Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(497)

Side by Side Diff: Source/devtools/scripts/compile_frontend.py

Issue 459833002: Revert of Revert of DevTools: Introduce module initializers (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 simplejson as json
40 except ImportError:
39 import json 41 import json
40 except ImportError:
41 import simplejson as 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 js_modules_name = "frontend_modules.json" 60 frontend_modules_name = "frontend_modules.json"
61 runtime_module_name = "_runtime" 61 runtime_module_name = "_runtime"
62 module_initializer_name = "_module.js"
62 63
63 64
64 def error_excepthook(exctype, value, traceback): 65 def error_excepthook(exctype, value, traceback):
65 print "ERROR:" 66 print "ERROR:"
66 sys.__excepthook__(exctype, value, traceback) 67 sys.__excepthook__(exctype, value, traceback)
67 sys.excepthook = error_excepthook 68 sys.excepthook = error_excepthook
68 69
69 try: 70 try:
70 with open(path.join(scripts_path, js_modules_name), "rt") as js_modules_file : 71 with open(path.join(scripts_path, frontend_modules_name), "rt") as js_module s_file:
71 modules = json.loads(js_modules_file.read()) 72 modules = json.loads(js_modules_file.read())
72 except: 73 except:
73 print "ERROR: Failed to read %s" % js_modules_name 74 log_error("Failed to read %s" % frontend_modules_name)
74 raise 75 raise
75 76
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
95 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"] 77 type_checked_jsdoc_tags_list = ["param", "return", "type", "enum"]
96 78
97 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list) 79 type_checked_jsdoc_tags_or = "|".join(type_checked_jsdoc_tags_list)
98 80
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). 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).
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])[^/]*\}") 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])[^/]*\}")
101 83
102 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*.*(?<![{: ])([?!])=?\}") 84 invalid_type_designator_regex = re.compile(r"@(?:" + type_checked_jsdoc_tags_or + r")\s*.*(?<![{: ])([?!])=?\}")
103 85
104 importscript_regex = re.compile(r"importScript\(\s*[\"']") 86 importscript_regex = re.compile(r"importScript\(\s*[\"']")
105 error_warning_regex = re.compile(r"(?:WARNING|ERROR)") 87 error_warning_regex = re.compile(r"(?:WARNING|ERROR)")
106 88
107 errors_found = False 89 errors_found = False
108 90
109 91
110 def run_in_shell(command_line): 92 def run_in_shell(command_line):
111 return subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subproc ess.STDOUT, shell=True) 93 return subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subproc ess.STDOUT, shell=True)
112 94
113 95
114 def hasErrors(output): 96 def hasErrors(output):
115 return re.search(error_warning_regex, output) != None 97 return re.search(error_warning_regex, output) != None
116 98
117 99
100 def log_error(message):
101 print "ERROR: " + message
102
118 def verify_importScript_usage(): 103 def verify_importScript_usage():
119 errors_found = False 104 errors_found = False
120 for module in modules: 105 for module in modules:
121 for file_name in module['sources']: 106 for file_name in module["sources"]:
122 if file_name in allowed_import_statements_files: 107 if path.basename(file_name) == module_initializer_name:
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
123 continue 110 continue
124 try: 111 try:
125 with open(path.join(devtools_frontend_path, file_name), "r") as sourceFile: 112 with open(path.join(devtools_frontend_path, file_name), "r") as sourceFile:
126 source = sourceFile.read() 113 source = sourceFile.read()
127 if re.search(importscript_regex, source): 114 if re.search(importscript_regex, source):
128 print "ERROR: importScript function call is allowed in m odule header files only (found in %s)" % file_name 115 log_error("importScript() call only allowed in module in itializers (%s); found in %s" % (module_initializer_name, file_name))
129 errors_found = True 116 errors_found = True
130 except: 117 except:
131 print "ERROR: Failed to access %s" % file_name 118 log_error("Failed to access %s" % file_name)
132 raise 119 raise
133 return errors_found 120 return errors_found
134 121
135 122
136 def dump_all_checked_files(): 123 def dump_all_checked_files():
137 files = {} 124 files = {}
138 for module in modules: 125 for module in modules:
139 for source in module["sources"]: 126 for source in module["sources"]:
140 files[path.join(devtools_frontend_path, source)] = True 127 files[path.join(devtools_frontend_path, source)] = True
141 return files.keys() 128 return files.keys()
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 if not list: 206 if not list:
220 list = [] 207 list = []
221 dependents_by_module_name[dep] = list 208 dependents_by_module_name[dep] = list
222 list.append(name) 209 list.append(name)
223 210
224 211
225 def verify_standalone_modules(): 212 def verify_standalone_modules():
226 for module in modules: 213 for module in modules:
227 for dependency in module["dependencies"]: 214 for dependency in module["dependencies"]:
228 if dependency in standalone_modules_by_name: 215 if dependency in standalone_modules_by_name:
229 print "ERROR: Standalone module %s may not be present among the dependencies of %s" % (dependency, module["name"]) 216 log_error("Standalone module '%s' may not be present among the d ependencies of '%s'" % (dependency, module["name"]))
230 errors_found = True 217 errors_found = True
231 218
232 verify_standalone_modules() 219 verify_standalone_modules()
233 220
234 221
235 def check_duplicate_files(): 222 def check_duplicate_files():
236 223
237 def check_module(module, seen_files, seen_modules): 224 def check_module(module, seen_files, seen_modules):
238 name = module["name"] 225 name = module["name"]
239 seen_modules[name] = True 226 seen_modules[name] = True
240 for dep_name in module["dependencies"]: 227 for dep_name in module["dependencies"]:
241 if not dep_name in seen_modules: 228 if not dep_name in seen_modules:
242 check_module(modules_by_name[dep_name], seen_files, seen_modules ) 229 check_module(modules_by_name[dep_name], seen_files, seen_modules )
243 for source in module["sources"]: 230 for source in module["sources"]:
244 referencing_module = seen_files.get(source) 231 referencing_module = seen_files.get(source)
245 if referencing_module: 232 if referencing_module:
246 print "ERROR: Duplicate use of %s in '%s' (previously seen in '% s')" % (source, name, referencing_module) 233 log_error("Duplicate use of %s in '%s' (previously seen in '%s') " % (source, name, referencing_module))
247 seen_files[source] = name 234 seen_files[source] = name
248 235
249 for module_name in standalone_modules_by_name: 236 for module_name in standalone_modules_by_name:
250 check_module(standalone_modules_by_name[module_name], {}, {}) 237 check_module(standalone_modules_by_name[module_name], {}, {})
251 238
252 print "Checking duplicate files across modules..." 239 print "Checking duplicate files across modules..."
253 check_duplicate_files() 240 check_duplicate_files()
254 241
255 242
256 def module_arg(module_name): 243 def module_arg(module_name):
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 errors_found |= hasErrors(validateInjectedScriptOut) 405 errors_found |= hasErrors(validateInjectedScriptOut)
419 406
420 if errors_found: 407 if errors_found:
421 print "ERRORS DETECTED" 408 print "ERRORS DETECTED"
422 409
423 os.remove(injectedScriptSourceTmpFile) 410 os.remove(injectedScriptSourceTmpFile)
424 os.remove(injectedScriptCanvasModuleSourceTmpFile) 411 os.remove(injectedScriptCanvasModuleSourceTmpFile)
425 os.remove(compiler_args_file.name) 412 os.remove(compiler_args_file.name)
426 os.remove(protocol_externs_file) 413 os.remove(protocol_externs_file)
427 shutil.rmtree(modules_dir, True) 414 shutil.rmtree(modules_dir, True)
OLDNEW
« no previous file with comments | « Source/devtools/front_end/timeline/module.json ('k') | Source/devtools/scripts/concatenate_module_descriptors.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698