| 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 18 matching lines...) Expand all Loading... |
| 29 | 29 |
| 30 import os | 30 import os |
| 31 import os.path as path | 31 import os.path as path |
| 32 import generate_protocol_externs | 32 import generate_protocol_externs |
| 33 import re | 33 import re |
| 34 import shutil | 34 import shutil |
| 35 import subprocess | 35 import subprocess |
| 36 import sys | 36 import sys |
| 37 import tempfile | 37 import tempfile |
| 38 try: | 38 try: |
| 39 import json |
| 40 except ImportError: |
| 39 import simplejson as json | 41 import simplejson as json |
| 40 except ImportError: | |
| 41 import json | |
| 42 | 42 |
| 43 scripts_path = path.dirname(path.abspath(__file__)) | 43 scripts_path = path.dirname(path.abspath(__file__)) |
| 44 devtools_path = path.dirname(scripts_path) | 44 devtools_path = path.dirname(scripts_path) |
| 45 inspector_path = path.join(path.dirname(devtools_path), "core", "inspector") | 45 inspector_path = path.join(path.dirname(devtools_path), "core", "inspector") |
| 46 devtools_frontend_path = path.join(devtools_path, "front_end") | 46 devtools_frontend_path = path.join(devtools_path, "front_end") |
| 47 global_externs_file = path.join(devtools_frontend_path, "externs.js") | 47 global_externs_file = path.join(devtools_frontend_path, "externs.js") |
| 48 protocol_externs_file = path.join(devtools_frontend_path, "protocol_externs.js") | 48 protocol_externs_file = path.join(devtools_frontend_path, "protocol_externs.js") |
| 49 webgl_rendering_context_idl_path = path.join(path.dirname(devtools_path), "core"
, "html", "canvas", "WebGLRenderingContextBase.idl") | 49 webgl_rendering_context_idl_path = path.join(path.dirname(devtools_path), "core"
, "html", "canvas", "WebGLRenderingContextBase.idl") |
| 50 injected_script_source_name = path.join(inspector_path, "InjectedScriptSource.js
") | 50 injected_script_source_name = path.join(inspector_path, "InjectedScriptSource.js
") |
| 51 canvas_injected_script_source_name = path.join(inspector_path, "InjectedScriptCa
nvasModuleSource.js") | 51 canvas_injected_script_source_name = path.join(inspector_path, "InjectedScriptCa
nvasModuleSource.js") |
| 52 closure_compiler_jar = path.join(scripts_path, "closure", "compiler.jar") | 52 closure_compiler_jar = path.join(scripts_path, "closure", "compiler.jar") |
| 53 closure_runner_jar = path.join(scripts_path, "compiler-runner", "closure-runner.
jar") | 53 closure_runner_jar = path.join(scripts_path, "compiler-runner", "closure-runner.
jar") |
| 54 jsdoc_validator_jar = path.join(scripts_path, "jsdoc-validator", "jsdoc-validato
r.jar") | 54 jsdoc_validator_jar = path.join(scripts_path, "jsdoc-validator", "jsdoc-validato
r.jar") |
| 55 java_exec = "java -Xms1024m -server -XX:+TieredCompilation" | 55 java_exec = "java -Xms1024m -server -XX:+TieredCompilation" |
| 56 | 56 |
| 57 generate_protocol_externs.generate_protocol_externs(protocol_externs_file, path.
join(devtools_path, "protocol.json")) | 57 generate_protocol_externs.generate_protocol_externs(protocol_externs_file, path.
join(devtools_path, "protocol.json")) |
| 58 | 58 |
| 59 jsmodule_name_prefix = "jsmodule_" | 59 jsmodule_name_prefix = "jsmodule_" |
| 60 frontend_modules_name = "frontend_modules.json" | 60 js_modules_name = "frontend_modules.json" |
| 61 runtime_module_name = "_runtime" | 61 runtime_module_name = "_runtime" |
| 62 module_initializer_name = "_module.js" | |
| 63 | 62 |
| 64 | 63 |
| 65 def error_excepthook(exctype, value, traceback): | 64 def error_excepthook(exctype, value, traceback): |
| 66 print "ERROR:" | 65 print "ERROR:" |
| 67 sys.__excepthook__(exctype, value, traceback) | 66 sys.__excepthook__(exctype, value, traceback) |
| 68 sys.excepthook = error_excepthook | 67 sys.excepthook = error_excepthook |
| 69 | 68 |
| 70 try: | 69 try: |
| 71 with open(path.join(scripts_path, frontend_modules_name), "rt") as js_module
s_file: | 70 with open(path.join(scripts_path, js_modules_name), "rt") as js_modules_file
: |
| 72 modules = json.loads(js_modules_file.read()) | 71 modules = json.loads(js_modules_file.read()) |
| 73 except: | 72 except: |
| 74 log_error("Failed to read %s" % frontend_modules_name) | 73 print "ERROR: Failed to read %s" % js_modules_name |
| 75 raise | 74 raise |
| 76 | 75 |
| 76 # `importScript` function must not be used in any files |
| 77 # except module headers. Refer to devtools.gyp file for |
| 78 # the module header list. |
| 79 allowed_import_statements_files = [ |
| 80 "console/ConsolePanel.js", |
| 81 "elements/ElementsPanel.js", |
| 82 "resources/ResourcesPanel.js", |
| 83 "network/NetworkPanel.js", |
| 84 "settings/SettingsScreen.js", |
| 85 "sources/SourcesPanel.js", |
| 86 "timeline/TimelinePanel.js", |
| 87 "profiler/ProfilesPanel.js", |
| 88 "audits/AuditsPanel.js", |
| 89 "layers/LayersPanel.js", |
| 90 "extensions/ExtensionServer.js", |
| 91 "source_frame/SourceFrame.js", |
| 92 "documentation/DocumentationView.js", |
| 93 ] |
| 94 |
| 77 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"] | 95 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"] |
| 78 | 96 |
| 79 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list) | 97 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list) |
| 80 | 98 |
| 81 # 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). | 99 # 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). |
| 82 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])[^/]*\}") | 100 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])[^/]*\}") |
| 83 | 101 |
| 84 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or
+ r")\s*.*(?<![{: ])([?!])=?\}") | 102 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or
+ r")\s*.*(?<![{: ])([?!])=?\}") |
| 85 | 103 |
| 86 importscript_regex = re.compile(r"importScript\(\s*[\"']") | 104 importscript_regex = re.compile(r"importScript\(\s*[\"']") |
| 87 error_warning_regex = re.compile(r"(?:WARNING|ERROR)") | 105 error_warning_regex = re.compile(r"(?:WARNING|ERROR)") |
| 88 | 106 |
| 89 errors_found = False | 107 errors_found = False |
| 90 | 108 |
| 91 | 109 |
| 92 def run_in_shell(command_line): | 110 def run_in_shell(command_line): |
| 93 return subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subproc
ess.STDOUT, shell=True) | 111 return subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subproc
ess.STDOUT, shell=True) |
| 94 | 112 |
| 95 | 113 |
| 96 def hasErrors(output): | 114 def hasErrors(output): |
| 97 return re.search(error_warning_regex, output) != None | 115 return re.search(error_warning_regex, output) != None |
| 98 | 116 |
| 99 | 117 |
| 100 def log_error(message): | |
| 101 print "ERROR: " + message | |
| 102 | |
| 103 def verify_importScript_usage(): | 118 def verify_importScript_usage(): |
| 104 errors_found = False | 119 errors_found = False |
| 105 for module in modules: | 120 for module in modules: |
| 106 for file_name in module["sources"]: | 121 for file_name in module['sources']: |
| 107 if path.basename(file_name) == module_initializer_name: | 122 if file_name in allowed_import_statements_files: |
| 108 log_error("Module initializer (%s) may not be listed among modul
e's scripts; found in '%s'" % (module_initializer_name, module["name"])) | |
| 109 errors_found = True | |
| 110 continue | 123 continue |
| 111 try: | 124 try: |
| 112 with open(path.join(devtools_frontend_path, file_name), "r") as
sourceFile: | 125 with open(path.join(devtools_frontend_path, file_name), "r") as
sourceFile: |
| 113 source = sourceFile.read() | 126 source = sourceFile.read() |
| 114 if re.search(importscript_regex, source): | 127 if re.search(importscript_regex, source): |
| 115 log_error("importScript() call only allowed in module in
itializers (%s); found in %s" % (module_initializer_name, file_name)) | 128 print "ERROR: importScript function call is allowed in m
odule header files only (found in %s)" % file_name |
| 116 errors_found = True | 129 errors_found = True |
| 117 except: | 130 except: |
| 118 log_error("Failed to access %s" % file_name) | 131 print "ERROR: Failed to access %s" % file_name |
| 119 raise | 132 raise |
| 120 return errors_found | 133 return errors_found |
| 121 | 134 |
| 122 | 135 |
| 123 def dump_all_checked_files(): | 136 def dump_all_checked_files(): |
| 124 files = {} | 137 files = {} |
| 125 for module in modules: | 138 for module in modules: |
| 126 for source in module["sources"]: | 139 for source in module["sources"]: |
| 127 files[path.join(devtools_frontend_path, source)] = True | 140 files[path.join(devtools_frontend_path, source)] = True |
| 128 return files.keys() | 141 return files.keys() |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 if not list: | 219 if not list: |
| 207 list = [] | 220 list = [] |
| 208 dependents_by_module_name[dep] = list | 221 dependents_by_module_name[dep] = list |
| 209 list.append(name) | 222 list.append(name) |
| 210 | 223 |
| 211 | 224 |
| 212 def verify_standalone_modules(): | 225 def verify_standalone_modules(): |
| 213 for module in modules: | 226 for module in modules: |
| 214 for dependency in module["dependencies"]: | 227 for dependency in module["dependencies"]: |
| 215 if dependency in standalone_modules_by_name: | 228 if dependency in standalone_modules_by_name: |
| 216 log_error("Standalone module '%s' may not be present among the d
ependencies of '%s'" % (dependency, module["name"])) | 229 print "ERROR: Standalone module %s may not be present among the
dependencies of %s" % (dependency, module["name"]) |
| 217 errors_found = True | 230 errors_found = True |
| 218 | 231 |
| 219 verify_standalone_modules() | 232 verify_standalone_modules() |
| 220 | 233 |
| 221 | 234 |
| 222 def check_duplicate_files(): | 235 def check_duplicate_files(): |
| 223 | 236 |
| 224 def check_module(module, seen_files, seen_modules): | 237 def check_module(module, seen_files, seen_modules): |
| 225 name = module["name"] | 238 name = module["name"] |
| 226 seen_modules[name] = True | 239 seen_modules[name] = True |
| 227 for dep_name in module["dependencies"]: | 240 for dep_name in module["dependencies"]: |
| 228 if not dep_name in seen_modules: | 241 if not dep_name in seen_modules: |
| 229 check_module(modules_by_name[dep_name], seen_files, seen_modules
) | 242 check_module(modules_by_name[dep_name], seen_files, seen_modules
) |
| 230 for source in module["sources"]: | 243 for source in module["sources"]: |
| 231 referencing_module = seen_files.get(source) | 244 referencing_module = seen_files.get(source) |
| 232 if referencing_module: | 245 if referencing_module: |
| 233 log_error("Duplicate use of %s in '%s' (previously seen in '%s')
" % (source, name, referencing_module)) | 246 print "ERROR: Duplicate use of %s in '%s' (previously seen in '%
s')" % (source, name, referencing_module) |
| 234 seen_files[source] = name | 247 seen_files[source] = name |
| 235 | 248 |
| 236 for module_name in standalone_modules_by_name: | 249 for module_name in standalone_modules_by_name: |
| 237 check_module(standalone_modules_by_name[module_name], {}, {}) | 250 check_module(standalone_modules_by_name[module_name], {}, {}) |
| 238 | 251 |
| 239 print "Checking duplicate files across modules..." | 252 print "Checking duplicate files across modules..." |
| 240 check_duplicate_files() | 253 check_duplicate_files() |
| 241 | 254 |
| 242 | 255 |
| 243 def module_arg(module_name): | 256 def module_arg(module_name): |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 errors_found |= hasErrors(validateInjectedScriptOut) | 418 errors_found |= hasErrors(validateInjectedScriptOut) |
| 406 | 419 |
| 407 if errors_found: | 420 if errors_found: |
| 408 print "ERRORS DETECTED" | 421 print "ERRORS DETECTED" |
| 409 | 422 |
| 410 os.remove(injectedScriptSourceTmpFile) | 423 os.remove(injectedScriptSourceTmpFile) |
| 411 os.remove(injectedScriptCanvasModuleSourceTmpFile) | 424 os.remove(injectedScriptCanvasModuleSourceTmpFile) |
| 412 os.remove(compiler_args_file.name) | 425 os.remove(compiler_args_file.name) |
| 413 os.remove(protocol_externs_file) | 426 os.remove(protocol_externs_file) |
| 414 shutil.rmtree(modules_dir, True) | 427 shutil.rmtree(modules_dir, True) |
| OLD | NEW |