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

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

Issue 2374153004: [DevTools] Fix compile_frontend.py script (Closed)
Patch Set: Created 4 years, 2 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 | « third_party/WebKit/Source/devtools/scripts/check_injected_script_source.py ('k') | 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 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
69 return output.strip().replace('\\', '\\\\') 69 return output.strip().replace('\\', '\\\\')
70 70
71 scripts_path = path.dirname(path.abspath(__file__)) 71 scripts_path = path.dirname(path.abspath(__file__))
72 devtools_path = path.dirname(scripts_path) 72 devtools_path = path.dirname(scripts_path)
73 inspector_path = path.join(path.dirname(devtools_path), 'core', 'inspector') 73 inspector_path = path.join(path.dirname(devtools_path), 'core', 'inspector')
74 # TODO(dgozman): move these checks to v8. 74 # TODO(dgozman): move these checks to v8.
75 v8_inspector_path = path.normpath(path.join(path.dirname(devtools_path), os.pard ir, os.pardir, os.pardir, 'v8', 'src', 'inspector')) 75 v8_inspector_path = path.normpath(path.join(path.dirname(devtools_path), os.pard ir, os.pardir, os.pardir, 'v8', 'src', 'inspector'))
76 devtools_frontend_path = path.join(devtools_path, 'front_end') 76 devtools_frontend_path = path.join(devtools_path, 'front_end')
77 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'))
78 protocol_externs_file = path.join(devtools_frontend_path, 'protocol_externs.js') 78 protocol_externs_file = path.join(devtools_frontend_path, 'protocol_externs.js')
79 injected_script_source_name = path.join(v8_inspector_path, 'injected-script-sour ce.js')
80 injected_script_externs_file = path.join(v8_inspector_path, 'injected_script_ext erns.js')
81 debugger_script_source_name = path.join(v8_inspector_path, 'debugger-script.js')
82 debugger_script_externs_file = path.join(v8_inspector_path, 'debugger_script_ext erns.js')
83 79
84 jsmodule_name_prefix = 'jsmodule_' 80 jsmodule_name_prefix = 'jsmodule_'
85 runtime_module_name = '_runtime' 81 runtime_module_name = '_runtime'
86 82
87 type_checked_jsdoc_tags_list = ['param', 'return', 'type', 'enum'] 83 type_checked_jsdoc_tags_list = ['param', 'return', 'type', 'enum']
88 type_checked_jsdoc_tags_or = '|'.join(type_checked_jsdoc_tags_list) 84 type_checked_jsdoc_tags_or = '|'.join(type_checked_jsdoc_tags_list)
89 85
90 # 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). 86 # 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).
91 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])[^/]*\}') 87 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])[^/]*\}')
92 invalid_type_designator_regex = re.compile(r'@(?:' + type_checked_jsdoc_tags_or + r')\s*.*(?<![{: ])([?!])=?\}') 88 invalid_type_designator_regex = re.compile(r'@(?:' + type_checked_jsdoc_tags_or + r')\s*.*(?<![{: ])([?!])=?\}')
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
129 application_descriptors = ['inspector.json', 'toolbox.json', 'formatter_worker.j son', 'heap_snapshot_worker.json', 'temp_storage_shared_worker.json'] 125 application_descriptors = ['inspector.json', 'toolbox.json', 'formatter_worker.j son', 'heap_snapshot_worker.json', 'temp_storage_shared_worker.json']
130 loader = modular_build.DescriptorLoader(devtools_frontend_path) 126 loader = modular_build.DescriptorLoader(devtools_frontend_path)
131 descriptors = loader.load_applications(application_descriptors) 127 descriptors = loader.load_applications(application_descriptors)
132 modules_by_name = descriptors.modules 128 modules_by_name = descriptors.modules
133 129
134 130
135 def hasErrors(output): 131 def hasErrors(output):
136 return re.search(error_warning_regex, output) != None 132 return re.search(error_warning_regex, output) != None
137 133
138 134
139 def verify_jsdoc_extra(additional_files): 135 def verify_jsdoc_extra():
140 files = [to_platform_path(file) for file in descriptors.all_compiled_files() + additional_files] 136 files = [to_platform_path(compiled_file) for compiled_file in descriptors.al l_compiled_files()]
141 file_list = tempfile.NamedTemporaryFile(mode='wt', delete=False) 137 file_list = tempfile.NamedTemporaryFile(mode='wt', delete=False)
142 try: 138 try:
143 file_list.write('\n'.join(files)) 139 file_list.write('\n'.join(files))
144 finally: 140 finally:
145 file_list.close() 141 file_list.close()
146 return popen(java_exec + ['-jar', jsdoc_validator_jar, '--files-list-name', to_platform_path_exact(file_list.name)]), file_list 142 return popen(java_exec + ['-jar', jsdoc_validator_jar, '--files-list-name', to_platform_path_exact(file_list.name)]), file_list
147 143
148 144
149 def verify_jsdoc(additional_files): 145 def verify_jsdoc():
150 def file_list(): 146 def file_list():
151 return descriptors.all_compiled_files() + additional_files 147 return descriptors.all_compiled_files()
152 148
153 errors_found = False 149 errors_found = False
154 for full_file_name in file_list(): 150 for full_file_name in file_list():
155 lineIndex = 0 151 lineIndex = 0
156 with open(full_file_name, 'r') as sourceFile: 152 with open(full_file_name, 'r') as sourceFile:
157 for line in sourceFile: 153 for line in sourceFile:
158 line = line.rstrip() 154 line = line.rstrip()
159 lineIndex += 1 155 lineIndex += 1
160 if not line: 156 if not line:
161 continue 157 continue
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after
360 closure_args += ' --externs ' + to_platform_path(global_externs_file) 356 closure_args += ' --externs ' + to_platform_path(global_externs_file)
361 closure_args += ' --externs ' + platform_protocol_externs_file 357 closure_args += ' --externs ' + platform_protocol_externs_file
362 runtime_module = module_arg(runtime_module_name) + ':1 --js ' + runtime_ js_path 358 runtime_module = module_arg(runtime_module_name) + ':1 --js ' + runtime_ js_path
363 closure_args += runtime_module + dump_module(name, True, {}) 359 closure_args += runtime_module + dump_module(name, True, {})
364 compiler_args_file.write('%s %s%s' % (name, closure_args, os.linesep)) 360 compiler_args_file.write('%s %s%s' % (name, closure_args, os.linesep))
365 finally: 361 finally:
366 compiler_args_file.close() 362 compiler_args_file.close()
367 363
368 modular_compiler_proc = popen(java_exec + ['-jar', closure_runner_jar, '--compil er-args-file', to_platform_path_exact(compiler_args_file.name)]) 364 modular_compiler_proc = popen(java_exec + ['-jar', closure_runner_jar, '--compil er-args-file', to_platform_path_exact(compiler_args_file.name)])
369 365
370 def unclosure_injected_script(sourceFileName, outFileName):
371
372 source = read_file(sourceFileName)
373
374 def replace_function(matchobj):
375 return re.sub(r'@param', 'param', matchobj.group(1) or '') + '\n//' + ma tchobj.group(2)
376
377 # Comment out the closure function and its jsdocs
378 source = re.sub(r'(/\*\*(?:[\s\n]*\*\s*@param[^\n]+\n)+\s*\*/\s*)?\n(\(funct ion)', replace_function, source, count=1)
379
380 # Comment out its return statement
381 source = re.sub(r'\n(\s*return\s+[^;]+;\s*\n\}\)\s*)$', '\n/*\\1*/', source)
382
383 # Replace the "var Object" override with a "self.Object" one
384 source = re.sub(r'\nvar Object =', '\nself.Object =', source, count=1)
385
386 write_file(outFileName, source)
387
388 injectedScriptSourceTmpFile = to_platform_path(path.join(inspector_path, 'Inject edScriptSourceTmp.js'))
389
390 unclosure_injected_script(injected_script_source_name, injectedScriptSourceTmpFi le)
391
392 print 'Compiling InjectedScriptSource.js...'
393
394 spawned_compiler_command = java_exec + [ 366 spawned_compiler_command = java_exec + [
395 '-jar', 367 '-jar',
396 closure_compiler_jar 368 closure_compiler_jar
397 ] + common_closure_args 369 ] + common_closure_args
398 370
399 command = spawned_compiler_command + [
400 '--externs', to_platform_path_exact(injected_script_externs_file),
401 '--externs', to_platform_path_exact(protocol_externs_file),
402 '--module', jsmodule_name_prefix + 'injected_script' + ':1',
403 '--js', to_platform_path(injectedScriptSourceTmpFile)
404 ]
405
406 injectedScriptCompileProc = popen(command)
407
408 print 'Compiling DebuggerScript.js...'
409
410 command = spawned_compiler_command + [
411 '--externs', to_platform_path_exact(debugger_script_externs_file),
412 '--module', jsmodule_name_prefix + 'debugger_script' + ':1',
413 '--js', to_platform_path(debugger_script_source_name)
414 ]
415
416 debuggerScriptCompileProc = popen(command)
417
418 print 'Compiling devtools.js...' 371 print 'Compiling devtools.js...'
419 372
420 command = spawned_compiler_command + [ 373 command = spawned_compiler_command + [
421 '--externs', to_platform_path(global_externs_file), 374 '--externs', to_platform_path(global_externs_file),
422 '--externs', to_platform_path(path.join(devtools_frontend_path, 'host', 'Ins pectorFrontendHostAPI.js')), 375 '--externs', to_platform_path(path.join(devtools_frontend_path, 'host', 'Ins pectorFrontendHostAPI.js')),
423 '--jscomp_off=externsValidation', 376 '--jscomp_off=externsValidation',
424 '--module', jsmodule_name_prefix + 'devtools_js' + ':1', 377 '--module', jsmodule_name_prefix + 'devtools_js' + ':1',
425 '--js', to_platform_path(path.join(devtools_frontend_path, 'devtools.js')) 378 '--js', to_platform_path(path.join(devtools_frontend_path, 'devtools.js'))
426 ] 379 ]
427 devtoolsJSCompileProc = popen(command) 380 devtoolsJSCompileProc = popen(command)
428 381
429 print 'Verifying JSDoc comments...' 382 print 'Verifying JSDoc comments...'
430 additional_jsdoc_check_files = [injectedScriptSourceTmpFile] 383 errors_found |= verify_jsdoc()
431 errors_found |= verify_jsdoc(additional_jsdoc_check_files) 384 (jsdocValidatorProc, jsdocValidatorFileList) = verify_jsdoc_extra()
432 jsdocValidatorProc, jsdocValidatorFileList = verify_jsdoc_extra(additional_jsdoc _check_files)
433
434 print 'Validating InjectedScriptSource.js...'
435 injectedscript_check_script_path = path.join(scripts_path, "check_injected_scrip t_source.py")
436 validateInjectedScriptProc = popen([sys.executable, injectedscript_check_script_ path, injected_script_source_name])
437 385
438 print 386 print
439 387
440 (jsdocValidatorOut, _) = jsdocValidatorProc.communicate() 388 (jsdocValidatorOut, _) = jsdocValidatorProc.communicate()
441 if jsdocValidatorOut: 389 if jsdocValidatorOut:
442 print ('JSDoc validator output:%s%s' % (os.linesep, jsdocValidatorOut)) 390 print ('JSDoc validator output:%s%s' % (os.linesep, jsdocValidatorOut))
443 errors_found = True 391 errors_found = True
444 392
445 os.remove(jsdocValidatorFileList.name) 393 os.remove(jsdocValidatorFileList.name)
446 394
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
494 print 'Module %s compile failed: %s errors%s' % (module_name, module _error_count, os.linesep) 442 print 'Module %s compile failed: %s errors%s' % (module_name, module _error_count, os.linesep)
495 print os.linesep.join(module_output) 443 print os.linesep.join(module_output)
496 444
497 if not has_module_output: 445 if not has_module_output:
498 print moduleCompileOut 446 print moduleCompileOut
499 447
500 if error_count: 448 if error_count:
501 print 'Total Closure errors: %d%s' % (error_count, os.linesep) 449 print 'Total Closure errors: %d%s' % (error_count, os.linesep)
502 errors_found = True 450 errors_found = True
503 451
504 (injectedScriptCompileOut, _) = injectedScriptCompileProc.communicate()
505 print 'InjectedScriptSource.js compilation output:%s' % os.linesep, injectedScri ptCompileOut
506 errors_found |= hasErrors(injectedScriptCompileOut)
507
508 (debuggerScriptCompilerOut, _) = debuggerScriptCompileProc.communicate()
509 print 'DebuggerScript.js compilation output:%s' % os.linesep, debuggerScriptComp ilerOut
510 errors_found |= hasErrors(debuggerScriptCompilerOut)
511
512 (devtoolsJSCompileOut, _) = devtoolsJSCompileProc.communicate() 452 (devtoolsJSCompileOut, _) = devtoolsJSCompileProc.communicate()
513 print 'devtools.js compilation output:%s' % os.linesep, devtoolsJSCompileOut 453 print 'devtools.js compilation output:%s' % os.linesep, devtoolsJSCompileOut
514 errors_found |= hasErrors(devtoolsJSCompileOut) 454 errors_found |= hasErrors(devtoolsJSCompileOut)
515 455
516 (validateInjectedScriptOut, _) = validateInjectedScriptProc.communicate()
517 print 'Validate InjectedScriptSource.js output:%s' % os.linesep, (validateInject edScriptOut if validateInjectedScriptOut else '<empty>')
518 errors_found |= hasErrors(validateInjectedScriptOut)
519
520 if errors_found: 456 if errors_found:
521 print 'ERRORS DETECTED' 457 print 'ERRORS DETECTED'
522 458
523 os.remove(injectedScriptSourceTmpFile)
524 os.remove(compiler_args_file.name) 459 os.remove(compiler_args_file.name)
525 os.remove(protocol_externs_file) 460 os.remove(protocol_externs_file)
526 shutil.rmtree(modules_dir, True) 461 shutil.rmtree(modules_dir, True)
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/devtools/scripts/check_injected_script_source.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698