34 |
34 |
35 # ============================================================================ |
35 # ============================================================================ |
36 # Globals |
36 # Globals |
37 # ============================================================================ |
37 # ============================================================================ |
38 VERBOSE = False |
38 VERBOSE = False |
39 EXCLUDE = ["hbplugins", "hbservers", "3rdparty", "internal", "tsrc", "debug", "release"] |
39 EXCLUDE = ["hbapps", "hbplugins", "hbservers", "hbtools", "3rdparty", |
|
40 "internal", "tsrc", "debug", "release", "bwins", "eabi"] |
40 COLLECTIONS = {"hbcore": "HbCore", |
41 COLLECTIONS = {"hbcore": "HbCore", |
41 "hbfeedback": "HbFeedback", |
42 "hbfeedback": "HbFeedback", |
42 "hbinput": "HbInput", |
43 "hbinput": "HbInput", |
43 "hbutils": "HbUtils", |
44 "hbutils": "HbUtils", |
44 "hbwidgets": "HbWidgets"} |
45 "hbwidgets": "HbWidgets"} |
85 file.write(content) |
86 file.write(content) |
86 file.close() |
87 file.close() |
87 except IOError, e: |
88 except IOError, e: |
88 print(e) |
89 print(e) |
89 |
90 |
90 def write_header(filepath, include): |
91 def include_directive(header): |
91 write_file(filepath, "#include \"%s\"\n" % include) |
92 return "#include \"%s\"\n" % header |
|
93 |
|
94 def write_header(header, include, path): |
|
95 filename = os.path.basename(header) |
|
96 filepath = os.path.join(path, filename) |
|
97 relpath = os.path.relpath(header, path).replace("\\", "/") |
|
98 skip = False |
|
99 if os.path.exists(filepath): |
|
100 directive = include_directive(include) |
|
101 oldsize = os.path.getsize(filepath) |
|
102 newsize = len(directive) |
|
103 if oldsize == newsize and directive == read_file(filepath): |
|
104 skip = True |
|
105 if not skip: |
|
106 if VERBOSE: |
|
107 print("INFO:\t ==> %s" % os.path.basename(filepath)) |
|
108 write_file(filepath, include_directive(include)) |
92 |
109 |
93 # ============================================================================ |
110 # ============================================================================ |
94 # Component |
111 # Component |
95 # ============================================================================ |
112 # ============================================================================ |
96 class Component: |
113 class Component: |
97 def __init__(self, name): |
114 def __init__(self, name): |
98 self.name = name |
115 self.name = name |
99 self.headers = list() |
116 self.headers = [] |
100 self.privates = list() |
117 self.privates = [] |
101 |
118 |
102 def read(self, path): |
119 def read(self, path): |
103 entries = os.listdir(path) |
120 entries = os.listdir(path) |
104 for entry in entries: |
121 for entry in entries: |
105 entrypath = os.path.join(path, entry) |
122 entrypath = os.path.join(path, entry) |
112 self.privates.append(entrypath) |
129 self.privates.append(entrypath) |
113 elif entry.endswith(".h"): |
130 elif entry.endswith(".h"): |
114 self.headers.append(entrypath) |
131 self.headers.append(entrypath) |
115 |
132 |
116 def write(self, path): |
133 def write(self, path): |
|
134 written = [] |
117 if len(self.headers) > 0: |
135 if len(self.headers) > 0: |
118 self._makedirs(path) |
136 self._makedirs(path) |
119 self._write(path, self.headers, True) |
137 written += self._write(path, self.headers, True) |
120 |
138 |
121 if len(self.privates) > 0: |
139 if len(self.privates) > 0: |
122 privpath = os.path.join(path, "private") |
140 privpath = os.path.join(path, "private") |
123 self._makedirs(privpath) |
141 self._makedirs(privpath) |
124 self._write(privpath, self.privates, False) |
142 written += self._write(privpath, self.privates, False) |
|
143 return written |
125 |
144 |
126 def _write(self, path, headers, convenience): |
145 def _write(self, path, headers, convenience): |
127 global VERBOSE |
146 written = [] |
128 if VERBOSE: |
|
129 print("INFO: Writing headers to '%s'" % path) |
|
130 for header in headers: |
147 for header in headers: |
131 filename = os.path.basename(header) |
148 write_header(header, header, path) |
132 filepath = os.path.join(path, filename) |
149 written.append(os.path.join(path, os.path.basename(header))) |
133 relpath = os.path.relpath(header, path) |
|
134 if VERBOSE: |
|
135 print("INFO:\t ==> %s" % os.path.basename(filepath)) |
|
136 write_header(filepath, relpath.replace("\\", "/")) |
|
137 if convenience: |
150 if convenience: |
138 classes = list() |
151 classes = [] |
139 content = read_file(header) |
152 content = read_file(header) |
140 for match in re.finditer("(?:class|namespace)\s+(?:HB_[^_]+_EXPORT\s+)?(Hb\w*)(\s*;)?", content): |
153 for match in re.finditer("(?:class|namespace)\s+(?:HB_[^_]+_EXPORT\s+)?(Hb\w*)(\s*;)?", content): |
141 if not match.group(2): |
154 if not match.group(2): |
142 classes.append(match.group(1)) |
155 classes.append(match.group(1)) |
143 for match in re.finditer("#pragma hb_header\((\w+)\)", content): |
156 for match in re.finditer("#pragma hb_header\((\w+)\)", content): |
144 classes.append(match.group(1)) |
157 classes.append(match.group(1)) |
145 for cls in classes: |
158 for cls in classes: |
146 filepath = os.path.join(path, cls) |
159 write_header(cls, os.path.basename(header), path) |
147 write_header(filepath, filename) |
160 written.append(os.path.join(path, cls)) |
|
161 return written |
148 |
162 |
149 def _makedirs(self, path): |
163 def _makedirs(self, path): |
150 global VERBOSE |
|
151 if not os.path.exists(path): |
164 if not os.path.exists(path): |
152 if VERBOSE: |
|
153 print("INFO: Creating include dir '%s'" % path) |
|
154 os.makedirs(path) |
165 os.makedirs(path) |
155 |
166 |
156 # ============================================================================ |
167 # ============================================================================ |
157 # Collection |
168 # Collection |
158 # ============================================================================ |
169 # ============================================================================ |
169 component = Component(entry) |
180 component = Component(entry) |
170 component.read(entrypath) |
181 component.read(entrypath) |
171 self.components.append(component) |
182 self.components.append(component) |
172 |
183 |
173 def write(self, path): |
184 def write(self, path): |
174 global COLLECTIONS |
185 global COLLECTIONS, VERBOSE |
|
186 path = os.path.join(os.path.abspath(path), self.name) |
|
187 if VERBOSE: |
|
188 print("INFO: Writing headers to '%s'..." % path) |
|
189 # there's no set in python 2.3 so use a list |
|
190 leftovers = [] |
|
191 for root, dirs, files in os.walk(path): |
|
192 for file in files: |
|
193 leftovers.append(os.path.abspath(os.path.join(root, file))) |
|
194 |
175 # include/hbcore |
195 # include/hbcore |
176 includes = list() |
196 includes = [] |
177 path = os.path.join(path, self.name) |
197 written = [] |
178 for component in self.components: |
198 for component in self.components: |
179 component.write(path) |
199 written += component.write(path) |
180 for header in component.headers: |
200 for header in component.headers: |
181 includes.append("#include \"%s\"\n" % os.path.basename(header)) |
201 includes.append("#include \"%s\"\n" % os.path.basename(header)) |
|
202 |
182 if self.name in COLLECTIONS: |
203 if self.name in COLLECTIONS: |
183 write_file(os.path.join(path, self.name + ".h"), "".join(includes)) |
204 collectionheader = os.path.join(path, self.name + ".h") |
184 write_header(os.path.join(path, COLLECTIONS[self.name]), self.name + ".h") |
205 write_file(collectionheader, "".join(includes)) |
|
206 written.append(collectionheader) |
|
207 if collectionheader in leftovers: |
|
208 leftovers.remove(collectionheader) |
|
209 convenienceheader = os.path.join(path, COLLECTIONS[self.name]) |
|
210 write_file(convenienceheader, include_directive(self.name + ".h")) |
|
211 written.append(convenienceheader) |
|
212 if convenienceheader in leftovers: |
|
213 leftovers.remove(convenienceheader) |
|
214 |
|
215 for filepath in written: |
|
216 filepath = os.path.abspath(filepath) |
|
217 if filepath in leftovers: |
|
218 leftovers.remove(filepath) |
|
219 |
|
220 if VERBOSE and len(leftovers) > 0: |
|
221 print("INFO: Removing obsolete headers from '%s'..." % path) |
|
222 for leftover in leftovers: |
|
223 if VERBOSE: |
|
224 print("INFO:\t ==> %s" % leftover) # os.path.basename(leftover)) |
|
225 os.remove(leftover) |
185 |
226 |
186 # ============================================================================ |
227 # ============================================================================ |
187 # Package |
228 # Package |
188 # ============================================================================ |
229 # ============================================================================ |
189 class Package: |
230 class Package: |
190 def __init__(self, name): |
231 def __init__(self, name): |
191 self.path = name |
232 self.name = name |
192 self.collections = list() |
233 self.collections = [] |
193 |
234 |
194 def read(self, path): |
235 def read(self, path): |
195 global EXCLUDE |
236 global EXCLUDE |
196 for entry in os.listdir(path): |
237 for entry in os.listdir(path): |
197 # hbcore, hbwidgets, hbutils... |
238 # hbcore, hbwidgets, hbutils... |
226 if not options.outputdir: |
267 if not options.outputdir: |
227 options.outputdir = os.getcwd() |
268 options.outputdir = os.getcwd() |
228 if not os.path.basename(os.path.normpath(options.outputdir)) == "include": |
269 if not os.path.basename(os.path.normpath(options.outputdir)) == "include": |
229 options.outputdir = os.path.join(options.outputdir, "include") |
270 options.outputdir = os.path.join(options.outputdir, "include") |
230 |
271 |
231 if os.path.exists(options.outputdir): |
|
232 if VERBOSE: |
|
233 print("INFO: Removing include dir '%s'" % options.outputdir) |
|
234 shutil.rmtree(options.outputdir, ignore_errors=True) |
|
235 |
|
236 package = Package("hb") |
272 package = Package("hb") |
237 package.read(options.inputdir) |
273 package.read(options.inputdir) |
238 package.write(options.outputdir) |
274 package.write(options.outputdir) |
239 |
275 |
240 if __name__ == "__main__": |
276 if __name__ == "__main__": |