blob: ff2657c6d8b21ba6897d6b244098ba6fccccbd94 [file] [log] [blame]
Joe Onorato88155422012-07-23 13:51:44 -07001#!/usr/bin/env python
2#
3# Copyright (C) 2012 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of the License at
8#
9# http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16
17import os
18import re
19import sys
20
21def break_lines(key, val):
22 # these don't get split
23 if key in ("PRODUCT_MODEL"):
24 return (key,val)
25 return (key, "\n".join(val.split()))
26
27def split_line(line):
28 words = line.split("=", 1)
29 if len(words) == 1:
30 return (words[0], "")
31 else:
32 return (words[0], words[1])
33
34def sort_lines(text):
35 lines = text.split()
36 lines.sort()
37 return "\n".join(lines)
38
39def parse_variables(lines):
40 return [split_line(line) for line in lines if line.strip()]
41
42def render_variables(variables):
43 variables = dict(variables)
44 del variables["FILE"]
45 variables = list(variables.iteritems())
46 variables.sort(lambda a, b: cmp(a[0], b[0]))
47 return ("<table id='variables'>"
48 + "\n".join([ "<tr><th>%(key)s</th><td>%(val)s</td></tr>" % { "key": key, "val": val }
49 for key,val in variables])
50 +"</table>")
51
52def linkify_inherit(variables, text, func_name):
53 groups = re.split("(\\$\\(call " + func_name + ",.*\\))", text)
54 result = ""
55 for i in range(0,len(groups)/2):
56 i = i * 2
57 result = result + groups[i]
58 s = groups[i+1]
59 href = s.split(",", 1)[1].strip()[:-1]
60 href = href.replace("$(SRC_TARGET_DIR)", "build/target")
61 href = ("../" * variables["FILE"].count("/")) + href + ".html"
62 result = result + "<a href=\"%s\">%s</a>" % (href,s)
63 result = result + groups[-1]
64 return result
65
66def render_original(variables, text):
67 text = linkify_inherit(variables, text, "inherit-product")
68 text = linkify_inherit(variables, text, "inherit-product-if-exists")
69 return text
70
71def read_file(fn):
72 f = file(fn)
73 text = f.read()
74 f.close()
75 return text
76
77def main(argv):
78 # read the variables
79 lines = sys.stdin.readlines()
80 variables = parse_variables(lines)
81
82 # format the variables
83 variables = [break_lines(key,val) for key,val in variables]
84
85 # now it's a dict
86 variables = dict(variables)
87
88 sorted_vars = (
89 "PRODUCT_COPY_FILES",
90 "PRODUCT_PACKAGES",
91 "PRODUCT_LOCALES",
Joe Onorato88155422012-07-23 13:51:44 -070092 "PRODUCT_PROPERTY_OVERRIDES",
93 )
94
95 for key in sorted_vars:
96 variables[key] = sort_lines(variables[key])
97
98 # the original file
99 original = read_file(variables["FILE"])
100
101 # formatting
102 values = dict(variables)
103 values.update({
104 "variables": render_variables(variables),
105 "original": render_original(variables, original),
106 })
107 print """<html>
108
109
110<head>
111 <title>%(FILE)s</title>
112 <style type="text/css">
113 body {
114 font-family: Helvetica, Arial, sans-serif;
115 padding-bottom: 20px;
116 }
117 #variables {
118 border-collapse: collapse;
119 }
120 #variables th, #variables td {
121 vertical-align: top;
122 text-align: left;
123 border-top: 1px solid #c5cdde;
124 border-bottom: 1px solid #c5cdde;
125 padding: 2px 10px 2px 10px;
126 }
127 #variables th {
128 font-size: 10pt;
129 background-color: #e2ecff
130 }
131 #variables td {
132 background-color: #ebf2ff;
133 white-space: pre;
134 font-size: 10pt;
135 }
136 #original {
137 background-color: #ebf2ff;
138 border-top: 1px solid #c5cdde;
139 border-bottom: 1px solid #c5cdde;
140 padding: 2px 10px 2px 10px;
141 white-space: pre;
142 font-size: 10pt;
143 }
144 </style>
145</head>
146<body>
147<h1>%(FILE)s</h1>
148<a href="#Original">Original</a>
149<a href="#Variables">Variables</a>
150<h2><a name="Original"></a>Original</h2>
151<div id="original">%(original)s</div>
152<h2><a name="Variables"></a>Variables</h2>
153%(variables)s
154</body>
155</html>
156""" % values
157
158if __name__ == "__main__":
159 main(sys.argv)