OLD | NEW |
---|---|
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 Google Inc. All rights reserved. | 2 # Copyright (c) 2012 Google Inc. All rights reserved. |
3 # | 3 # |
4 # Redistribution and use in source and binary forms, with or without | 4 # Redistribution and use in source and binary forms, with or without |
5 # modification, are permitted provided that the following conditions are | 5 # modification, are permitted provided that the following conditions are |
6 # met: | 6 # met: |
7 # | 7 # |
8 # * Redistributions of source code must retain the above copyright | 8 # * Redistributions of source code must retain the above copyright |
9 # notice, this list of conditions and the following disclaimer. | 9 # notice, this list of conditions and the following disclaimer. |
10 # * Redistributions in binary form must reproduce the above | 10 # * Redistributions in binary form must reproduce the above |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
85 "source_frame/SourceFrame.js", | 85 "source_frame/SourceFrame.js", |
86 ] | 86 ] |
87 | 87 |
88 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"] | 88 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"] |
89 | 89 |
90 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list) | 90 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list) |
91 | 91 |
92 # Basic regex for invalid JsDoc types: an object type name ([A-Z][A-Za-z0-9.]+[A -Za-z0-9]) not preceded by '!', '?', ':' (this, new), or '.' (object property). | 92 # Basic regex for invalid JsDoc types: an object type name ([A-Z][A-Za-z0-9.]+[A -Za-z0-9]) not preceded by '!', '?', ':' (this, new), or '.' (object property). |
93 invalid_type_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*\{. *(?<![!?:.A-Za-z0-9])([A-Z][A-Za-z0-9.]+[A-Za-z0-9])[^/]*\}") | 93 invalid_type_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*\{. *(?<![!?:.A-Za-z0-9])([A-Z][A-Za-z0-9.]+[A-Za-z0-9])[^/]*\}") |
94 | 94 |
95 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*.*([?!])=?\}") | 95 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*.*(?<![{: ])([?!])=?\}") |
aandrey
2014/06/17 11:38:34
hard to review
| |
96 | 96 |
97 importscript_regex = re.compile(r"importScript\(\s*[\"']") | 97 importscript_regex = re.compile(r"importScript\(\s*[\"']") |
98 error_warning_regex = re.compile(r"(?:WARNING|ERROR)") | 98 error_warning_regex = re.compile(r"(?:WARNING|ERROR)") |
99 | 99 |
100 errors_found = False | 100 errors_found = False |
101 | 101 |
102 | 102 |
103 def hasErrors(output): | 103 def hasErrors(output): |
104 return re.search(error_warning_regex, output) != None | 104 return re.search(error_warning_regex, output) != None |
105 | 105 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
182 print "Verifying 'importScript' function usage..." | 182 print "Verifying 'importScript' function usage..." |
183 errors_found |= verify_importScript_usage() | 183 errors_found |= verify_importScript_usage() |
184 | 184 |
185 print "Verifying JSDoc comments..." | 185 print "Verifying JSDoc comments..." |
186 errors_found |= verify_jsdoc() | 186 errors_found |= verify_jsdoc() |
187 jsdocValidatorProc = verify_jsdoc_extra() | 187 jsdocValidatorProc = verify_jsdoc_extra() |
188 | 188 |
189 modules_dir = tempfile.mkdtemp() | 189 modules_dir = tempfile.mkdtemp() |
190 common_closure_args = " --summary_detail_level 3 --compilation_level SIMPLE_OPTI MIZATIONS --warning_level VERBOSE --language_in ECMASCRIPT5 --accept_const_keywo rd --module_output_path_prefix %s/" % modules_dir | 190 common_closure_args = " --summary_detail_level 3 --compilation_level SIMPLE_OPTI MIZATIONS --warning_level VERBOSE --language_in ECMASCRIPT5 --accept_const_keywo rd --module_output_path_prefix %s/" % modules_dir |
191 | 191 |
192 compiler_args_file = tempfile.NamedTemporaryFile(mode='wt', delete=False) | |
193 closure_runner_command = "%s -jar %s --compiler-args-file %s" % (java_exec, clos ure_runner_jar, compiler_args_file.name) | |
194 | |
195 spawned_compiler_command = "%s -jar %s %s \\\n" % (java_exec, closure_compiler_j ar, common_closure_args) | 192 spawned_compiler_command = "%s -jar %s %s \\\n" % (java_exec, closure_compiler_j ar, common_closure_args) |
196 | 193 |
197 modules_by_name = {} | 194 modules_by_name = {} |
198 standalone_modules_by_name = {} | 195 standalone_modules_by_name = {} |
199 dependents_by_module_name = {} | 196 dependents_by_module_name = {} |
200 | 197 |
201 for module in modules: | 198 for module in modules: |
202 name = module["name"] | 199 name = module["name"] |
203 modules_by_name[name] = module | 200 modules_by_name[name] = module |
204 if "standalone" in module: | 201 if "standalone" in module: |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 else: | 257 else: |
261 command += "," | 258 command += "," |
262 firstDependency = False | 259 firstDependency = False |
263 command += jsmodule_name_prefix + dependency | 260 command += jsmodule_name_prefix + dependency |
264 for script in module["sources"]: | 261 for script in module["sources"]: |
265 command += " --js " + path.join(devtools_frontend_path, script) | 262 command += " --js " + path.join(devtools_frontend_path, script) |
266 return command | 263 return command |
267 | 264 |
268 print "Compiling frontend..." | 265 print "Compiling frontend..." |
269 | 266 |
267 compiler_args_file = tempfile.NamedTemporaryFile(mode='wt', delete=False) | |
268 closure_runner_command = "%s -jar %s --compiler-args-file %s" % (java_exec, clos ure_runner_jar, compiler_args_file.name) | |
269 | |
270 for module in modules: | 270 for module in modules: |
271 closure_args = common_closure_args | 271 closure_args = common_closure_args |
272 closure_args += " --externs " + global_externs_file | 272 closure_args += " --externs " + global_externs_file |
273 closure_args += " --externs " + protocol_externs_file | 273 closure_args += " --externs " + protocol_externs_file |
274 closure_args += dump_module(module["name"], True, {}) | 274 closure_args += dump_module(module["name"], True, {}) |
275 compiler_args_file.write("%s %s\n" % (module["name"], closure_args)) | 275 compiler_args_file.write("%s %s\n" % (module["name"], closure_args)) |
276 | 276 |
277 compiler_args_file.close() | 277 compiler_args_file.close() |
278 modular_compiler_proc = subprocess.Popen(closure_runner_command, stdout=subproce ss.PIPE, stderr=subprocess.STDOUT, shell=True) | 278 modular_compiler_proc = subprocess.Popen(closure_runner_command, stdout=subproce ss.PIPE, stderr=subprocess.STDOUT, shell=True) |
279 | 279 |
280 | 280 |
281 def unclosure_injected_script(sourceFileName, outFileName): | 281 def unclosure_injected_script(sourceFileName, outFileName, has_object_override=F alse): |
282 sourceFile = open(sourceFileName, "r") | 282 with open(sourceFileName, "r") as sourceFile: |
283 source = sourceFile.read() | 283 source = sourceFile.read() |
284 sourceFile.close() | |
285 | 284 |
286 def replace_function(matchobj): | 285 def replace_function(matchobj): |
287 return re.sub(r"@param", "param", matchobj.group(1) or "") + "\n//" + ma tchobj.group(2) | 286 return re.sub(r"@param", "param", matchobj.group(1) or "") + "\n//" + ma tchobj.group(2) |
288 | 287 |
289 # Comment out the closure function and its jsdocs | 288 # Comment out the closure function and its jsdocs |
290 source = re.sub(r"(/\*\*(?:[\s\n]*\*\s*@param[^\n]+\n)+\s*\*/\s*)?\n(\(funct ion)", replace_function, source, count=1) | 289 source = re.sub(r"(/\*\*(?:[\s\n]*\*\s*@param[^\n]+\n)+\s*\*/\s*)?\n(\(funct ion)", replace_function, source, count=1) |
291 | 290 |
292 # Comment out its return statement | 291 # Comment out its return statement |
293 source = re.sub(r"\n(\s*return\s+[^;]+;\s*\n\}\)\s*)$", "\n/*\\1*/", source) | 292 source = re.sub(r"\n(\s*return\s+[^;]+;\s*\n\}\)\s*)$", "\n/*\\1*/", source) |
294 | 293 |
295 outFileName = open(outFileName, "w") | 294 # Replace the "var Object" override with a "self.Object" one |
296 outFileName.write(source) | 295 if has_object_override: |
aandrey
2014/06/17 11:38:33
just remove the flag?
apavlov
2014/06/17 11:54:04
Done.
| |
297 outFileName.close() | 296 source = re.sub(r"\nvar Object =", "\nself.Object =", source, count=1) |
297 | |
298 with open(outFileName, "w") as outFileName: | |
299 outFileName.write(source) | |
298 | 300 |
299 injectedScriptSourceTmpFile = path.join(inspector_path, "InjectedScriptSourceTmp .js") | 301 injectedScriptSourceTmpFile = path.join(inspector_path, "InjectedScriptSourceTmp .js") |
300 injectedScriptCanvasModuleSourceTmpFile = path.join(inspector_path, "InjectedScr iptCanvasModuleSourceTmp.js") | 302 injectedScriptCanvasModuleSourceTmpFile = path.join(inspector_path, "InjectedScr iptCanvasModuleSourceTmp.js") |
301 | 303 |
302 unclosure_injected_script(injected_script_source_name, injectedScriptSourceTmpFi le) | 304 unclosure_injected_script(injected_script_source_name, injectedScriptSourceTmpFi le, True) |
303 unclosure_injected_script(canvas_injected_script_source_name, injectedScriptCanv asModuleSourceTmpFile) | 305 unclosure_injected_script(canvas_injected_script_source_name, injectedScriptCanv asModuleSourceTmpFile) |
304 | 306 |
305 print "Compiling InjectedScriptSource.js and InjectedScriptCanvasModuleSource.js ..." | 307 print "Compiling InjectedScriptSource.js and InjectedScriptCanvasModuleSource.js ..." |
306 command = spawned_compiler_command | 308 command = spawned_compiler_command |
307 command += " --externs " + path.join(inspector_path, "InjectedScriptExterns.j s") + " \\\n" | 309 command += " --externs " + path.join(inspector_path, "InjectedScriptExterns.j s") + " \\\n" |
308 command += " --externs " + protocol_externs_file + " \\\n" | 310 command += " --externs " + protocol_externs_file + " \\\n" |
309 command += " --module " + jsmodule_name_prefix + "injected_script" + ":1" + " \\\n" | 311 command += " --module " + jsmodule_name_prefix + "injected_script" + ":1" + " \\\n" |
310 command += " --js " + injectedScriptSourceTmpFile + " \\\n" | 312 command += " --js " + injectedScriptSourceTmpFile + " \\\n" |
311 command += " --module " + jsmodule_name_prefix + "injected_canvas_script" + " :1:" + jsmodule_name_prefix + "injected_script" + " \\\n" | 313 command += " --module " + jsmodule_name_prefix + "injected_canvas_script" + " :1:" + jsmodule_name_prefix + "injected_script" + " \\\n" |
312 command += " --js " + injectedScriptCanvasModuleSourceTmpFile + " \\\n" | 314 command += " --js " + injectedScriptCanvasModuleSourceTmpFile + " \\\n" |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
393 errors_found |= hasErrors(validateInjectedScriptOut) | 395 errors_found |= hasErrors(validateInjectedScriptOut) |
394 | 396 |
395 if errors_found: | 397 if errors_found: |
396 print "ERRORS DETECTED" | 398 print "ERRORS DETECTED" |
397 | 399 |
398 os.remove(injectedScriptSourceTmpFile) | 400 os.remove(injectedScriptSourceTmpFile) |
399 os.remove(injectedScriptCanvasModuleSourceTmpFile) | 401 os.remove(injectedScriptCanvasModuleSourceTmpFile) |
400 os.remove(compiler_args_file.name) | 402 os.remove(compiler_args_file.name) |
401 os.remove(protocol_externs_file) | 403 os.remove(protocol_externs_file) |
402 shutil.rmtree(modules_dir, True) | 404 shutil.rmtree(modules_dir, True) |
OLD | NEW |