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

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

Issue 1144333005: Make compile_frontend.py work with default JVM 1.8 installation on Mac OS X (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: fixed execution on windows Created 5 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 46
47 if len(sys.argv) == 2 and sys.argv[1] == '--help': 47 if len(sys.argv) == 2 and sys.argv[1] == '--help':
48 print("Usage: %s [module_names]" % path.basename(sys.argv[0])) 48 print("Usage: %s [module_names]" % path.basename(sys.argv[0]))
49 print(" module_names list of modules for which the Closure compilation s hould run.") 49 print(" module_names list of modules for which the Closure compilation s hould run.")
50 print(" If absent, the entire frontend will be compiled.") 50 print(" If absent, the entire frontend will be compiled.")
51 sys.exit(0) 51 sys.exit(0)
52 52
53 is_cygwin = sys.platform == 'cygwin' 53 is_cygwin = sys.platform == 'cygwin'
54 54
55 55
56 def run_in_shell(command_line): 56 def popen(arguments):
57 return subprocess.Popen(command_line, stdout=subprocess.PIPE, stderr=subproc ess.STDOUT, shell=True) 57 return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess .STDOUT)
58
59 58
60 def to_platform_path(filepath): 59 def to_platform_path(filepath):
61 if not is_cygwin: 60 if not is_cygwin:
62 return filepath 61 return filepath
63 return re.sub(r'^/cygdrive/(\w)', '\\1:', filepath) 62 return re.sub(r'^/cygdrive/(\w)', '\\1:', filepath)
64 63
65 64
66 def to_platform_path_exact(filepath): 65 def to_platform_path_exact(filepath):
67 if not is_cygwin: 66 if not is_cygwin:
68 return filepath 67 return filepath
69 output, _ = run_in_shell('cygpath -w %s' % filepath).communicate() 68 output, _ = popen(['cygpath', '-w', filepath]).communicate()
70 # pylint: disable=E1103 69 # pylint: disable=E1103
71 return output.strip().replace('\\', '\\\\') 70 return output.strip().replace('\\', '\\\\')
72 71
73 scripts_path = path.dirname(path.abspath(__file__)) 72 scripts_path = path.dirname(path.abspath(__file__))
74 devtools_path = path.dirname(scripts_path) 73 devtools_path = path.dirname(scripts_path)
75 inspector_path = path.join(path.dirname(devtools_path), 'core', 'inspector') 74 inspector_path = path.join(path.dirname(devtools_path), 'core', 'inspector')
76 devtools_frontend_path = path.join(devtools_path, 'front_end') 75 devtools_frontend_path = path.join(devtools_path, 'front_end')
77 patched_es6_externs_file = to_platform_path(path.join(devtools_frontend_path, 'e s6.js')) 76 patched_es6_externs_file = to_platform_path(path.join(devtools_frontend_path, 'e s6.js'))
78 global_externs_file = to_platform_path(path.join(devtools_frontend_path, 'extern s.js')) 77 global_externs_file = to_platform_path(path.join(devtools_frontend_path, 'extern s.js'))
79 protocol_externs_file = path.join(devtools_frontend_path, 'protocol_externs.js') 78 protocol_externs_file = path.join(devtools_frontend_path, 'protocol_externs.js')
(...skipping 27 matching lines...) Expand all
107 fpath, fname = path.split(program) 106 fpath, fname = path.split(program)
108 if fpath: 107 if fpath:
109 if is_exe(program): 108 if is_exe(program):
110 return program 109 return program
111 else: 110 else:
112 for part in os.environ["PATH"].split(os.pathsep): 111 for part in os.environ["PATH"].split(os.pathsep):
113 part = part.strip('"') 112 part = part.strip('"')
114 exe_file = path.join(part, program) 113 exe_file = path.join(part, program)
115 if is_exe(exe_file): 114 if is_exe(exe_file):
116 return exe_file 115 return exe_file
117
118 return None 116 return None
119 117
120 118
121 def log_error(message): 119 def log_error(message):
122 print 'ERROR: ' + message 120 print 'ERROR: ' + message
123 121
124 def error_excepthook(exctype, value, traceback): 122 def error_excepthook(exctype, value, traceback):
125 print 'ERROR:' 123 print 'ERROR:'
126 sys.__excepthook__(exctype, value, traceback) 124 sys.__excepthook__(exctype, value, traceback)
127 sys.excepthook = error_excepthook 125 sys.excepthook = error_excepthook
128 126
129 application_descriptors = ['inspector.json', 'toolbox.json'] 127 application_descriptors = ['inspector.json', 'toolbox.json']
130 loader = modular_build.DescriptorLoader(devtools_frontend_path) 128 loader = modular_build.DescriptorLoader(devtools_frontend_path)
131 descriptors = loader.load_applications(application_descriptors) 129 descriptors = loader.load_applications(application_descriptors)
132 modules_by_name = descriptors.modules 130 modules_by_name = descriptors.modules
133 131
134 132
135 def hasErrors(output): 133 def hasErrors(output):
136 return re.search(error_warning_regex, output) != None 134 return re.search(error_warning_regex, output) != None
137 135
138 136
139 def verify_jsdoc_extra(additional_files): 137 def verify_jsdoc_extra(additional_files):
140 files = [to_platform_path(file) for file in descriptors.all_compiled_files() + additional_files] 138 files = [to_platform_path(file) for file in descriptors.all_compiled_files() + additional_files]
141 file_list = tempfile.NamedTemporaryFile(mode='wt', delete=False) 139 file_list = tempfile.NamedTemporaryFile(mode='wt', delete=False)
142 try: 140 try:
143 file_list.write('\n'.join(files)) 141 file_list.write('\n'.join(files))
144 finally: 142 finally:
145 file_list.close() 143 file_list.close()
146 return run_in_shell('%s -jar %s --files-list-name %s' % (java_exec, jsdoc_va lidator_jar, to_platform_path_exact(file_list.name))), file_list 144 return popen(java_exec + ['-jar', jsdoc_validator_jar, '--files-list-name', to_platform_path_exact(file_list.name)]), file_list
147 145
148 146
149 def verify_jsdoc(additional_files): 147 def verify_jsdoc(additional_files):
150 def file_list(): 148 def file_list():
151 return descriptors.all_compiled_files() + additional_files 149 return descriptors.all_compiled_files() + additional_files
152 150
153 errors_found = False 151 errors_found = False
154 for full_file_name in file_list(): 152 for full_file_name in file_list():
155 lineIndex = 0 153 lineIndex = 0
156 with open(full_file_name, 'r') as sourceFile: 154 with open(full_file_name, 'r') as sourceFile:
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 has_server_jvm = True 203 has_server_jvm = True
206 java_path = which('java') 204 java_path = which('java')
207 if not java_path: 205 if not java_path:
208 java_path = which('java.exe') 206 java_path = which('java.exe')
209 207
210 if not java_path: 208 if not java_path:
211 print 'NOTE: No Java executable found in $PATH.' 209 print 'NOTE: No Java executable found in $PATH.'
212 sys.exit(1) 210 sys.exit(1)
213 211
214 is_ok = False 212 is_ok = False
215 java_version_out, _ = run_in_shell('%s -version' % java_path).communicate() 213 java_version_out, _ = popen([java_path, '-version']).communicate()
216 # pylint: disable=E1103 214 # pylint: disable=E1103
217 match = re.search(java_build_regex, java_version_out) 215 match = re.search(java_build_regex, java_version_out)
218 if match: 216 if match:
219 major = int(match.group(1)) 217 major = int(match.group(1))
220 minor = int(match.group(2)) 218 minor = int(match.group(2))
221 is_ok = major >= required_major and minor >= required_minor 219 is_ok = major >= required_major and minor >= required_minor
222 if is_ok: 220 if is_ok:
223 exec_command = '%s -Xms1024m -server -XX:+TieredCompilation' % java_path 221 exec_command = [java_path, '-Xms1024m', '-server', '-XX:+TieredCompilati on']
224 check_server_proc = run_in_shell('%s -version' % exec_command) 222 check_server_proc = popen(exec_command + ['-version'])
225 check_server_proc.communicate() 223 check_server_proc.communicate()
226 if check_server_proc.returncode != 0: 224 if check_server_proc.returncode != 0:
227 # Not all Java installs have server JVMs. 225 # Not all Java installs have server JVMs.
228 exec_command = exec_command.replace('-server ', '') 226 exec_command = exec_command.remove('-server ')
229 has_server_jvm = False 227 has_server_jvm = False
230 228
231 if not is_ok: 229 if not is_ok:
232 print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (required_major, required_minor) 230 print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (required_major, required_minor)
233 sys.exit(1) 231 sys.exit(1)
234 print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)') 232 print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)')
235 return exec_command 233 return exec_command
236 234
237 java_exec = find_java() 235 java_exec = find_java()
238 236
239 closure_compiler_jar = to_platform_path(path.join(scripts_path, 'closure', 'comp iler.jar')) 237 closure_compiler_jar = to_platform_path(path.join(scripts_path, 'closure', 'comp iler.jar'))
240 closure_runner_jar = to_platform_path(path.join(scripts_path, 'compiler-runner', 'closure-runner.jar')) 238 closure_runner_jar = to_platform_path(path.join(scripts_path, 'compiler-runner', 'closure-runner.jar'))
241 jsdoc_validator_jar = to_platform_path(path.join(scripts_path, 'jsdoc-validator' , 'jsdoc-validator.jar')) 239 jsdoc_validator_jar = to_platform_path(path.join(scripts_path, 'jsdoc-validator' , 'jsdoc-validator.jar'))
242 240
243 modules_dir = tempfile.mkdtemp() 241 modules_dir = tempfile.mkdtemp()
244 common_closure_args = ' --summary_detail_level 3 --jscomp_error visibility --com pilation_level SIMPLE_OPTIMIZATIONS --warning_level VERBOSE --language_in=ES6_ST RICT --language_out=ES5_STRICT --accept_const_keyword --extra_annotation_name su ppressReceiverCheck --extra_annotation_name suppressGlobalPropertiesCheck --modu le_output_path_prefix %s' % to_platform_path_exact(modules_dir + path.sep) 242 common_closure_args = [
243 '--summary_detail_level', '3',
244 '--jscomp_error', 'visibility',
245 '--compilation_level', 'SIMPLE_OPTIMIZATIONS',
246 '--warning_level', 'VERBOSE',
247 '--language_in=ES6_STRICT',
248 '--language_out=ES5_STRICT',
249 '--accept_const_keyword',
250 '--extra_annotation_name', 'suppressReceiverCheck',
251 '--extra_annotation_name', 'suppressGlobalPropertiesCheck',
252 '--module_output_path_prefix', to_platform_path_exact(modules_dir + path.sep )
253 ]
245 254
246 worker_modules_by_name = {} 255 worker_modules_by_name = {}
247 dependents_by_module_name = {} 256 dependents_by_module_name = {}
248 257
249 for module_name in descriptors.application: 258 for module_name in descriptors.application:
250 module = descriptors.modules[module_name] 259 module = descriptors.modules[module_name]
251 if descriptors.application[module_name].get('type', None) == 'worker': 260 if descriptors.application[module_name].get('type', None) == 'worker':
252 worker_modules_by_name[module_name] = module 261 worker_modules_by_name[module_name] = module
253 for dep in module.get('dependencies', []): 262 for dep in module.get('dependencies', []):
254 list = dependents_by_module_name.get(dep) 263 list = dependents_by_module_name.get(dep)
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 return command 348 return command
340 349
341 print 'Compiling frontend...' 350 print 'Compiling frontend...'
342 351
343 compiler_args_file = tempfile.NamedTemporaryFile(mode='wt', delete=False) 352 compiler_args_file = tempfile.NamedTemporaryFile(mode='wt', delete=False)
344 try: 353 try:
345 platform_protocol_externs_file = to_platform_path(protocol_externs_file) 354 platform_protocol_externs_file = to_platform_path(protocol_externs_file)
346 runtime_js_path = to_platform_path(path.join(devtools_frontend_path, 'Runtim e.js')) 355 runtime_js_path = to_platform_path(path.join(devtools_frontend_path, 'Runtim e.js'))
347 checked_modules = modules_to_check() 356 checked_modules = modules_to_check()
348 for name in checked_modules: 357 for name in checked_modules:
349 closure_args = common_closure_args 358 closure_args = ' '.join(common_closure_args)
350 closure_args += ' --externs ' + to_platform_path(patched_es6_externs_fil e) 359 closure_args += ' --externs ' + to_platform_path(patched_es6_externs_fil e)
351 closure_args += ' --externs ' + to_platform_path(global_externs_file) 360 closure_args += ' --externs ' + to_platform_path(global_externs_file)
352 closure_args += ' --externs ' + platform_protocol_externs_file 361 closure_args += ' --externs ' + platform_protocol_externs_file
353 runtime_module = module_arg(runtime_module_name) + ':1 --js ' + runtime_ js_path 362 runtime_module = module_arg(runtime_module_name) + ':1 --js ' + runtime_ js_path
354 closure_args += runtime_module + dump_module(name, True, {}) 363 closure_args += runtime_module + dump_module(name, True, {})
355 compiler_args_file.write('%s %s%s' % (name, closure_args, os.linesep)) 364 compiler_args_file.write('%s %s%s' % (name, closure_args, os.linesep))
356 finally: 365 finally:
357 compiler_args_file.close() 366 compiler_args_file.close()
358 367
359 closure_runner_command = '%s -jar %s --compiler-args-file %s' % (java_exec, clos ure_runner_jar, to_platform_path_exact(compiler_args_file.name)) 368 modular_compiler_proc = popen(java_exec + ['-jar', closure_runner_jar, '--compil er-args-file', to_platform_path_exact(compiler_args_file.name)])
360 modular_compiler_proc = run_in_shell(closure_runner_command)
361 369
362 370
363 def unclosure_injected_script(sourceFileName, outFileName): 371 def unclosure_injected_script(sourceFileName, outFileName):
364 372
365 source = read_file(sourceFileName) 373 source = read_file(sourceFileName)
366 374
367 def replace_function(matchobj): 375 def replace_function(matchobj):
368 return re.sub(r'@param', 'param', matchobj.group(1) or '') + '\n//' + ma tchobj.group(2) 376 return re.sub(r'@param', 'param', matchobj.group(1) or '') + '\n//' + ma tchobj.group(2)
369 377
370 # Comment out the closure function and its jsdocs 378 # Comment out the closure function and its jsdocs
371 source = re.sub(r'(/\*\*(?:[\s\n]*\*\s*@param[^\n]+\n)+\s*\*/\s*)?\n(\(funct ion)', replace_function, source, count=1) 379 source = re.sub(r'(/\*\*(?:[\s\n]*\*\s*@param[^\n]+\n)+\s*\*/\s*)?\n(\(funct ion)', replace_function, source, count=1)
372 380
373 # Comment out its return statement 381 # Comment out its return statement
374 source = re.sub(r'\n(\s*return\s+[^;]+;\s*\n\}\)\s*)$', '\n/*\\1*/', source) 382 source = re.sub(r'\n(\s*return\s+[^;]+;\s*\n\}\)\s*)$', '\n/*\\1*/', source)
375 383
376 # Replace the "var Object" override with a "self.Object" one 384 # Replace the "var Object" override with a "self.Object" one
377 source = re.sub(r'\nvar Object =', '\nself.Object =', source, count=1) 385 source = re.sub(r'\nvar Object =', '\nself.Object =', source, count=1)
378 386
379 write_file(outFileName, source) 387 write_file(outFileName, source)
380 388
381 injectedScriptSourceTmpFile = to_platform_path(path.join(inspector_path, 'Inject edScriptSourceTmp.js')) 389 injectedScriptSourceTmpFile = to_platform_path(path.join(inspector_path, 'Inject edScriptSourceTmp.js'))
382 390
383 unclosure_injected_script(injected_script_source_name, injectedScriptSourceTmpFi le) 391 unclosure_injected_script(injected_script_source_name, injectedScriptSourceTmpFi le)
384 392
385 print 'Compiling InjectedScriptSource.js...' 393 print 'Compiling InjectedScriptSource.js...'
386 spawned_compiler_command = '%s -jar %s %s' % (java_exec, closure_compiler_jar, c ommon_closure_args)
387 394
388 command = spawned_compiler_command 395 spawned_compiler_command = java_exec + [
389 command += ' --externs ' + to_platform_path(injected_script_externs_file) 396 '-jar',
390 command += ' --externs ' + to_platform_path(protocol_externs_file) 397 closure_compiler_jar
391 command += ' --module ' + jsmodule_name_prefix + 'injected_script' + ':1' 398 ] + common_closure_args
392 command += ' --js ' + to_platform_path(injectedScriptSourceTmpFile)
393 399
394 injectedScriptCompileProc = run_in_shell(command) 400 command = spawned_compiler_command + [
401 '--externs', to_platform_path_exact(injected_script_externs_file),
402 '--externs', to_platform_path_exact(protocol_externs_file),
403 '--module', jsmodule_name_prefix + 'injected_script' + ':1',
404 '--js', to_platform_path(injectedScriptSourceTmpFile),
dgozman 2015/06/05 13:08:29 nit: extra comma
405 ]
406
407 injectedScriptCompileProc = popen(command)
395 408
396 print 'Compiling devtools.js...' 409 print 'Compiling devtools.js...'
397 spawned_compiler_command = '%s -jar %s %s' % (java_exec, closure_compiler_jar, c ommon_closure_args) 410
398 command = spawned_compiler_command 411 command = spawned_compiler_command + [
399 command += ' --externs ' + to_platform_path(global_externs_file) 412 '--externs', to_platform_path(global_externs_file),
400 command += ' --externs ' + to_platform_path(path.join(devtools_frontend_path, 'host', 'InspectorFrontendHostAPI.js')) 413 '--externs', to_platform_path(path.join(devtools_frontend_path, 'host', 'Ins pectorFrontendHostAPI.js')),
401 command += ' --module ' + jsmodule_name_prefix + 'devtools_js' + ':1' 414 '--module', jsmodule_name_prefix + 'devtools_js' + ':1',
402 command += ' --js ' + to_platform_path(path.join(devtools_frontend_path, 'devtools.js')) 415 '--js', to_platform_path(path.join(devtools_frontend_path, 'devtools.js'))
403 devtoolsJSCompileProc = run_in_shell(command) 416 ]
417 devtoolsJSCompileProc = popen(command)
404 418
405 print 'Verifying JSDoc comments...' 419 print 'Verifying JSDoc comments...'
406 additional_jsdoc_check_files = [injectedScriptSourceTmpFile] 420 additional_jsdoc_check_files = [injectedScriptSourceTmpFile]
407 errors_found |= verify_jsdoc(additional_jsdoc_check_files) 421 errors_found |= verify_jsdoc(additional_jsdoc_check_files)
408 jsdocValidatorProc, jsdocValidatorFileList = verify_jsdoc_extra(additional_jsdoc _check_files) 422 jsdocValidatorProc, jsdocValidatorFileList = verify_jsdoc_extra(additional_jsdoc _check_files)
409 423
410 print 'Validating InjectedScriptSource.js...' 424 print 'Validating InjectedScriptSource.js...'
411 injectedscript_check_script_path = path.join(scripts_path, "check_injected_scrip t_source.py") 425 injectedscript_check_script_path = path.join(scripts_path, "check_injected_scrip t_source.py")
412 check_injected_script_command = '%s %s' % (injectedscript_check_script_path, inj ected_script_source_name) 426 validateInjectedScriptProc = popen([sys.executable, injectedscript_check_script_ path, injected_script_source_name])
413 validateInjectedScriptProc = run_in_shell(check_injected_script_command)
414 427
415 print 428 print
416 429
417 (jsdocValidatorOut, _) = jsdocValidatorProc.communicate() 430 (jsdocValidatorOut, _) = jsdocValidatorProc.communicate()
418 if jsdocValidatorOut: 431 if jsdocValidatorOut:
419 print ('JSDoc validator output:%s%s' % (os.linesep, jsdocValidatorOut)) 432 print ('JSDoc validator output:%s%s' % (os.linesep, jsdocValidatorOut))
420 errors_found = True 433 errors_found = True
421 434
422 os.remove(jsdocValidatorFileList.name) 435 os.remove(jsdocValidatorFileList.name)
423 436
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 print 'Validate InjectedScriptSource.js output:%s' % os.linesep, (validateInject edScriptOut if validateInjectedScriptOut else '<empty>') 503 print 'Validate InjectedScriptSource.js output:%s' % os.linesep, (validateInject edScriptOut if validateInjectedScriptOut else '<empty>')
491 errors_found |= hasErrors(validateInjectedScriptOut) 504 errors_found |= hasErrors(validateInjectedScriptOut)
492 505
493 if errors_found: 506 if errors_found:
494 print 'ERRORS DETECTED' 507 print 'ERRORS DETECTED'
495 508
496 os.remove(injectedScriptSourceTmpFile) 509 os.remove(injectedScriptSourceTmpFile)
497 os.remove(compiler_args_file.name) 510 os.remove(compiler_args_file.name)
498 os.remove(protocol_externs_file) 511 os.remove(protocol_externs_file)
499 shutil.rmtree(modules_dir, True) 512 shutil.rmtree(modules_dir, True)
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698