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

Unified Diff: src/inspector/build/compile-scripts.py

Issue 2354263003: [inspector] add presubmit.py to compile inspector-related scripts (Closed)
Patch Set: addressed comments Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: src/inspector/build/compile-scripts.py
diff --git a/src/inspector/build/compile-scripts.py b/src/inspector/build/compile-scripts.py
new file mode 100755
index 0000000000000000000000000000000000000000..c1c3f802f5b95918e78da8d5c65505b38cb559ab
--- /dev/null
+++ b/src/inspector/build/compile-scripts.py
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+#
+# Copyright 2016 the V8 project authors. All rights reserved.
Michael Achenbach 2016/09/28 09:54:05 nit: If this is not copied but a new file, please
kozy 2016/09/28 23:38:47 Done.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+import os
+import os.path as path
+import generate_protocol_externs
+import re
+import subprocess
+import sys
+
+if len(sys.argv) == 2 and sys.argv[1] == '--help':
+ print("Usage: %s" % path.basename(sys.argv[0]))
+ sys.exit(0)
+
+def popen(arguments):
Michael Achenbach 2016/09/28 09:54:05 nit: move method down to other methods and don't m
kozy 2016/09/28 23:38:47 Done.
+ return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+
+v8_inspector_path = path.dirname(path.dirname(path.abspath(__file__)))
+
+protocol_externs_file = path.join(v8_inspector_path, 'protocol_externs.js')
Michael Achenbach 2016/09/28 09:54:05 Is this robust to the file already existing? E.g.
kozy 2016/09/28 23:38:47 Yes, it is.
+injected_script_source_name = path.join(v8_inspector_path, 'injected-script-source.js')
+injected_script_externs_file = path.join(v8_inspector_path, 'injected_script_externs.js')
+debugger_script_source_name = path.join(v8_inspector_path, 'debugger-script.js')
+debugger_script_externs_file = path.join(v8_inspector_path, 'debugger_script_externs.js')
+
+generate_protocol_externs.generate_protocol_externs(protocol_externs_file, path.join(v8_inspector_path, 'js_protocol.json'))
+
+# Error reporting and checking.
+errors_found = False
+
+def error_excepthook(exctype, value, traceback):
+ print 'ERROR:'
+ sys.__excepthook__(exctype, value, traceback)
+sys.excepthook = error_excepthook
+
+error_warning_regex = re.compile(r'WARNING|ERROR')
+
+def hasErrors(output):
+ return re.search(error_warning_regex, output) != None
+
+# Find java.
+# Based on http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python.
+def which(program):
+ def is_exe(fpath):
+ return path.isfile(fpath) and os.access(fpath, os.X_OK)
+
+ fpath, fname = path.split(program)
+ if fpath:
+ if is_exe(program):
+ return program
+ else:
+ for part in os.environ["PATH"].split(os.pathsep):
+ part = part.strip('"')
+ exe_file = path.join(part, program)
+ if is_exe(exe_file):
+ return exe_file
+ return None
+
+def find_java():
+ required_major = 1
Michael Achenbach 2016/09/28 09:54:05 Maybe make these toplevel constants at the top of
kozy 2016/09/28 23:38:47 Done.
+ required_minor = 7
+ exec_command = None
+ has_server_jvm = True
+ java_path = which('java')
+ if not java_path:
+ java_path = which('java.exe')
+
+ if not java_path:
+ print 'NOTE: No Java executable found in $PATH.'
+ sys.exit(1)
+
+ is_ok = False
+ java_version_out, _ = popen([java_path, '-version']).communicate()
+ java_build_regex = re.compile(r'^\w+ version "(\d+)\.(\d+)')
+ # pylint: disable=E1103
+ match = re.search(java_build_regex, java_version_out)
+ if match:
+ major = int(match.group(1))
+ minor = int(match.group(2))
+ is_ok = major >= required_major and minor >= required_minor
+ if is_ok:
+ exec_command = [java_path, '-Xms1024m', '-server', '-XX:+TieredCompilation']
+ check_server_proc = popen(exec_command + ['-version'])
+ check_server_proc.communicate()
+ if check_server_proc.returncode != 0:
+ # Not all Java installs have server JVMs.
+ exec_command = exec_command.remove('-server')
+ has_server_jvm = False
+
+ if not is_ok:
+ print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (required_major, required_minor)
+ sys.exit(1)
+ print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)')
+ return exec_command
+
+java_exec = find_java()
+
+closure_compiler_jar = path.join(v8_inspector_path, 'build', 'closure-compiler', 'closure-compiler.jar')
Michael Achenbach 2016/09/28 09:54:05 nit: move constant up to other toplevel constants
kozy 2016/09/28 23:38:47 Done.
+
+common_closure_args = [
+ '--checks_only',
+ '--warning_level', 'VERBOSE'
+]
+
+print 'Compiling injected-script-source.js...'
+
+spawned_compiler_command = java_exec + [
+ '-jar',
+ closure_compiler_jar
+] + common_closure_args
+
+command = spawned_compiler_command + [
+ '--externs', injected_script_externs_file,
+ '--externs', protocol_externs_file,
+ '--js', injected_script_source_name
+]
+
+injectedScriptCompileProc = popen(command)
+
+print 'Compiling debugger-script.js...'
+
+command = spawned_compiler_command + [
+ '--externs', debugger_script_externs_file,
+ '--js', debugger_script_source_name,
+ '--new_type_inf'
+]
+
+debuggerScriptCompileProc = popen(command)
+
+print 'Validating injected-script-source.js...'
+injectedscript_check_script_path = path.join(v8_inspector_path, 'build', "check_injected_script_source.py")
+validateInjectedScriptProc = popen([sys.executable, injectedscript_check_script_path, injected_script_source_name])
+
+print
+
+(injectedScriptCompileOut, _) = injectedScriptCompileProc.communicate()
+print 'injected-script-source.js compilation output:%s' % os.linesep, injectedScriptCompileOut
Michael Achenbach 2016/09/28 09:54:05 Does this work? One %s but two parameters? Thought
kozy 2016/09/28 23:38:47 It print first formatted string and then second st
+errors_found |= hasErrors(injectedScriptCompileOut)
+
+(debuggerScriptCompilerOut, _) = debuggerScriptCompileProc.communicate()
+print 'debugger-script.js compilation output:%s' % os.linesep, debuggerScriptCompilerOut
+errors_found |= hasErrors(debuggerScriptCompilerOut)
+
+(validateInjectedScriptOut, _) = validateInjectedScriptProc.communicate()
+print 'Validate injected-script-source.js output:%s' % os.linesep, (validateInjectedScriptOut if validateInjectedScriptOut else '<empty>')
+errors_found |= hasErrors(validateInjectedScriptOut)
+
+if errors_found:
+ print 'ERRORS DETECTED'
+
+os.remove(protocol_externs_file)

Powered by Google App Engine
This is Rietveld 408576698