• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
7import os
8import os.path as path
9import generate_protocol_externs
10import re
11import subprocess
12import sys
13
14if len(sys.argv) == 2 and sys.argv[1] == '--help':
15  print("Usage: %s" % path.basename(sys.argv[0]))
16  sys.exit(0)
17
18java_required_major = 1
19java_required_minor = 7
20
21v8_inspector_path = path.dirname(path.dirname(path.abspath(__file__)))
22
23protocol_externs_file = path.join(v8_inspector_path, 'protocol_externs.js')
24injected_script_source_name = path.join(v8_inspector_path,
25  'injected-script-source.js')
26injected_script_externs_file = path.join(v8_inspector_path,
27  'injected_script_externs.js')
28debugger_script_source_name = path.join(v8_inspector_path,
29  'debugger-script.js')
30debugger_script_externs_file = path.join(v8_inspector_path,
31  'debugger_script_externs.js')
32
33generate_protocol_externs.generate_protocol_externs(protocol_externs_file,
34  path.join(v8_inspector_path, 'js_protocol.json'))
35
36error_warning_regex = re.compile(r'WARNING|ERROR')
37
38closure_compiler_jar = path.join(v8_inspector_path, 'build',
39  'closure-compiler', 'closure-compiler.jar')
40
41common_closure_args = [
42  '--checks_only',
43  '--warning_level', 'VERBOSE'
44]
45
46# Error reporting and checking.
47errors_found = False
48
49def popen(arguments):
50  return subprocess.Popen(arguments, stdout=subprocess.PIPE,
51    stderr=subprocess.STDOUT)
52
53def error_excepthook(exctype, value, traceback):
54  print 'ERROR:'
55  sys.__excepthook__(exctype, value, traceback)
56sys.excepthook = error_excepthook
57
58def has_errors(output):
59  return re.search(error_warning_regex, output) != None
60
61# Find java. Based on
62# http://stackoverflow.com/questions/377017/test-if-executable-exists-in-python.
63def which(program):
64  def is_exe(fpath):
65    return path.isfile(fpath) and os.access(fpath, os.X_OK)
66
67  fpath, fname = path.split(program)
68  if fpath:
69    if is_exe(program):
70      return program
71  else:
72    for part in os.environ['PATH'].split(os.pathsep):
73      part = part.strip('"')
74      exe_file = path.join(part, program)
75      if is_exe(exe_file):
76        return exe_file
77  return None
78
79def find_java():
80  exec_command = None
81  has_server_jvm = True
82  java_path = which('java')
83  if not java_path:
84    java_path = which('java.exe')
85
86  if not java_path:
87    print 'NOTE: No Java executable found in $PATH.'
88    sys.exit(0)
89
90  is_ok = False
91  java_version_out, _ = popen([java_path, '-version']).communicate()
92  java_build_regex = re.compile(r'^\w+ version "(\d+)\.(\d+)')
93  # pylint: disable=E1103
94  match = re.search(java_build_regex, java_version_out)
95  if match:
96    major = int(match.group(1))
97    minor = int(match.group(2))
98    is_ok = major >= java_required_major and minor >= java_required_minor
99  if is_ok:
100    exec_command = [java_path, '-Xms1024m', '-server',
101      '-XX:+TieredCompilation']
102    check_server_proc = popen(exec_command + ['-version'])
103    check_server_proc.communicate()
104    if check_server_proc.returncode != 0:
105      # Not all Java installs have server JVMs.
106      exec_command = exec_command.remove('-server')
107      has_server_jvm = False
108
109  if not is_ok:
110    print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (java_required_major, java_required_minor)
111    sys.exit(0)
112  print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)')
113  return exec_command
114
115java_exec = find_java()
116
117spawned_compiler_command = java_exec + [
118  '-jar',
119  closure_compiler_jar
120] + common_closure_args
121
122print 'Compiling injected-script-source.js...'
123
124command = spawned_compiler_command + [
125  '--externs', injected_script_externs_file,
126  '--externs', protocol_externs_file,
127  '--js', injected_script_source_name
128]
129
130injected_script_compile_proc = popen(command)
131
132print 'Compiling debugger-script.js...'
133
134command = spawned_compiler_command + [
135  '--externs', debugger_script_externs_file,
136  '--js', debugger_script_source_name,
137  '--new_type_inf'
138]
139
140debugger_script_compile_proc = popen(command)
141
142print 'Validating injected-script-source.js...'
143injectedscript_check_script_path = path.join(v8_inspector_path, 'build',
144  'check_injected_script_source.py')
145validate_injected_script_proc = popen([sys.executable,
146  injectedscript_check_script_path, injected_script_source_name])
147
148print
149
150(injected_script_compile_out, _) = injected_script_compile_proc.communicate()
151print 'injected-script-source.js compilation output:%s' % os.linesep
152print injected_script_compile_out
153errors_found |= has_errors(injected_script_compile_out)
154
155(debugger_script_compiler_out, _) = debugger_script_compile_proc.communicate()
156print 'debugger-script.js compilation output:%s' % os.linesep
157print debugger_script_compiler_out
158errors_found |= has_errors(debugger_script_compiler_out)
159
160(validate_injected_script_out, _) = validate_injected_script_proc.communicate()
161print 'Validate injected-script-source.js output:%s' % os.linesep
162print validate_injected_script_out if validate_injected_script_out else '<empty>'
163errors_found |= has_errors(validate_injected_script_out)
164
165os.remove(protocol_externs_file)
166
167if errors_found:
168  print 'ERRORS DETECTED'
169  sys.exit(1)
170