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

Side by Side Diff: src/inspector/build/compile-scripts.py

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

Powered by Google App Engine
This is Rietveld 408576698