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

Side by Side 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, 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
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 #
3 # 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.
4 # Use of this source code is governed by a BSD-style license that can be
5 # found in the LICENSE file.
6
7 import os
8 import os.path as path
9 import generate_protocol_externs
10 import re
11 import subprocess
12 import sys
13
14 if len(sys.argv) == 2 and sys.argv[1] == '--help':
15 print("Usage: %s" % path.basename(sys.argv[0]))
16 sys.exit(0)
17
18 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.
19 return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess .STDOUT)
20
21 v8_inspector_path = path.dirname(path.dirname(path.abspath(__file__)))
22
23 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.
24 injected_script_source_name = path.join(v8_inspector_path, 'injected-script-sour ce.js')
25 injected_script_externs_file = path.join(v8_inspector_path, 'injected_script_ext erns.js')
26 debugger_script_source_name = path.join(v8_inspector_path, 'debugger-script.js')
27 debugger_script_externs_file = path.join(v8_inspector_path, 'debugger_script_ext erns.js')
28
29 generate_protocol_externs.generate_protocol_externs(protocol_externs_file, path. join(v8_inspector_path, 'js_protocol.json'))
30
31 # Error reporting and checking.
32 errors_found = False
33
34 def error_excepthook(exctype, value, traceback):
35 print 'ERROR:'
36 sys.__excepthook__(exctype, value, traceback)
37 sys.excepthook = error_excepthook
38
39 error_warning_regex = re.compile(r'WARNING|ERROR')
40
41 def hasErrors(output):
42 return re.search(error_warning_regex, output) != None
43
44 # Find java.
45 # Based on http://stackoverflow.com/questions/377017/test-if-executable-exists-i n-python.
46 def which(program):
47 def is_exe(fpath):
48 return path.isfile(fpath) and os.access(fpath, os.X_OK)
49
50 fpath, fname = path.split(program)
51 if fpath:
52 if is_exe(program):
53 return program
54 else:
55 for part in os.environ["PATH"].split(os.pathsep):
56 part = part.strip('"')
57 exe_file = path.join(part, program)
58 if is_exe(exe_file):
59 return exe_file
60 return None
61
62 def find_java():
63 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.
64 required_minor = 7
65 exec_command = None
66 has_server_jvm = True
67 java_path = which('java')
68 if not java_path:
69 java_path = which('java.exe')
70
71 if not java_path:
72 print 'NOTE: No Java executable found in $PATH.'
73 sys.exit(1)
74
75 is_ok = False
76 java_version_out, _ = popen([java_path, '-version']).communicate()
77 java_build_regex = re.compile(r'^\w+ version "(\d+)\.(\d+)')
78 # pylint: disable=E1103
79 match = re.search(java_build_regex, java_version_out)
80 if match:
81 major = int(match.group(1))
82 minor = int(match.group(2))
83 is_ok = major >= required_major and minor >= required_minor
84 if is_ok:
85 exec_command = [java_path, '-Xms1024m', '-server', '-XX:+TieredCompilati on']
86 check_server_proc = popen(exec_command + ['-version'])
87 check_server_proc.communicate()
88 if check_server_proc.returncode != 0:
89 # Not all Java installs have server JVMs.
90 exec_command = exec_command.remove('-server')
91 has_server_jvm = False
92
93 if not is_ok:
94 print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (required_major, required_minor)
95 sys.exit(1)
96 print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)')
97 return exec_command
98
99 java_exec = find_java()
100
101 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.
102
103 common_closure_args = [
104 '--checks_only',
105 '--warning_level', 'VERBOSE'
106 ]
107
108 print 'Compiling injected-script-source.js...'
109
110 spawned_compiler_command = java_exec + [
111 '-jar',
112 closure_compiler_jar
113 ] + common_closure_args
114
115 command = spawned_compiler_command + [
116 '--externs', injected_script_externs_file,
117 '--externs', protocol_externs_file,
118 '--js', injected_script_source_name
119 ]
120
121 injectedScriptCompileProc = popen(command)
122
123 print 'Compiling debugger-script.js...'
124
125 command = spawned_compiler_command + [
126 '--externs', debugger_script_externs_file,
127 '--js', debugger_script_source_name,
128 '--new_type_inf'
129 ]
130
131 debuggerScriptCompileProc = popen(command)
132
133 print 'Validating injected-script-source.js...'
134 injectedscript_check_script_path = path.join(v8_inspector_path, 'build', "check_ injected_script_source.py")
135 validateInjectedScriptProc = popen([sys.executable, injectedscript_check_script_ path, injected_script_source_name])
136
137 print
138
139 (injectedScriptCompileOut, _) = injectedScriptCompileProc.communicate()
140 print 'injected-script-source.js compilation output:%s' % os.linesep, injectedSc riptCompileOut
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
141 errors_found |= hasErrors(injectedScriptCompileOut)
142
143 (debuggerScriptCompilerOut, _) = debuggerScriptCompileProc.communicate()
144 print 'debugger-script.js compilation output:%s' % os.linesep, debuggerScriptCom pilerOut
145 errors_found |= hasErrors(debuggerScriptCompilerOut)
146
147 (validateInjectedScriptOut, _) = validateInjectedScriptProc.communicate()
148 print 'Validate injected-script-source.js output:%s' % os.linesep, (validateInje ctedScriptOut if validateInjectedScriptOut else '<empty>')
149 errors_found |= hasErrors(validateInjectedScriptOut)
150
151 if errors_found:
152 print 'ERRORS DETECTED'
153
154 os.remove(protocol_externs_file)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698