Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | # Copyright (c) 2012 Google Inc. All rights reserved. |
| 3 | # |
| 4 | # Redistribution and use in source and binary forms, with or without |
| 5 | # modification, are permitted provided that the following conditions are |
| 6 | # met: |
| 7 | # |
| 8 | # * Redistributions of source code must retain the above copyright |
| 9 | # notice, this list of conditions and the following disclaimer. |
| 10 | # * Redistributions in binary form must reproduce the above |
| 11 | # copyright notice, this list of conditions and the following disclaimer |
| 12 | # in the documentation and/or other materials provided with the |
| 13 | # distribution. |
| 14 | # * Neither the name of Google Inc. nor the names of its |
| 15 | # contributors may be used to endorse or promote products derived from |
| 16 | # this software without specific prior written permission. |
| 17 | # |
| 18 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 19 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 20 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 21 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 22 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 23 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 24 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 28 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | |
| 30 | import argparse |
| 31 | import os |
| 32 | import os.path as path |
| 33 | import re |
| 34 | import shutil |
| 35 | import subprocess |
| 36 | import sys |
| 37 | import tempfile |
| 38 | |
| 39 | from build import modular_build |
| 40 | from build import generate_protocol_externs |
| 41 | |
| 42 | import dependency_preprocessor |
| 43 | import utils |
| 44 | |
| 45 | try: |
| 46 | import simplejson as json |
| 47 | except ImportError: |
| 48 | import json |
| 49 | |
| 50 | is_cygwin = sys.platform == 'cygwin' |
| 51 | |
| 52 | |
| 53 | def popen(arguments): |
| 54 | return subprocess.Popen(arguments, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 55 | |
| 56 | |
| 57 | def to_platform_path(filepath): |
| 58 | if not is_cygwin: |
| 59 | return filepath |
| 60 | return re.sub(r'^/cygdrive/(\w)', '\\1:', filepath) |
| 61 | |
| 62 | |
| 63 | def to_platform_path_exact(filepath): |
| 64 | if not is_cygwin: |
| 65 | return filepath |
| 66 | output, _ = popen(['cygpath', '-w', filepath]).communicate() |
| 67 | # pylint: disable=E1103 |
| 68 | return output.strip().replace('\\', '\\\\') |
| 69 | |
| 70 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 71 | SCRIPTS_PATH = path.dirname(path.abspath(__file__)) |
| 72 | DEVTOOLS_PATH = path.dirname(SCRIPTS_PATH) |
| 73 | INSPECTOR_PATH = path.join(path.dirname(DEVTOOLS_PATH), 'core', 'inspector') |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 74 | # TODO(dgozman): move these checks to v8. |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 75 | V8_INCLUDE_PATH = path.normpath(path.join(path.dirname(DEVTOOLS_PATH), os.pardir, os.pardir, os.pardir, 'v8', 'include')) |
| 76 | DEVTOOLS_FRONTEND_PATH = path.join(DEVTOOLS_PATH, 'front_end') |
| 77 | GLOBAL_EXTERNS_FILE = to_platform_path(path.join(DEVTOOLS_FRONTEND_PATH, 'externs.js')) |
| 78 | DEFAULT_PROTOCOL_EXTERNS_FILE = path.join(DEVTOOLS_FRONTEND_PATH, 'protocol_externs.js') |
| 79 | RUNTIME_FILE = to_platform_path(path.join(DEVTOOLS_FRONTEND_PATH, 'Runtime.js')) |
Tim van der Lippe | 790b929 | 2019-09-19 15:14:16 +0000 | [diff] [blame] | 80 | ROOT_MODULE_FILE = to_platform_path(path.join(DEVTOOLS_FRONTEND_PATH, 'root.js')) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 81 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 82 | CLOSURE_COMPILER_JAR = to_platform_path(path.join(SCRIPTS_PATH, 'closure', 'compiler.jar')) |
| 83 | CLOSURE_RUNNER_JAR = to_platform_path(path.join(SCRIPTS_PATH, 'closure', 'closure_runner', 'closure_runner.jar')) |
| 84 | JSDOC_VALIDATOR_JAR = to_platform_path(path.join(SCRIPTS_PATH, 'jsdoc_validator', 'jsdoc_validator.jar')) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 85 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 86 | TYPE_CHECKED_JSDOC_TAGS_LIST = ['param', 'return', 'type', 'enum'] |
| 87 | TYPE_CHECKED_JSDOC_TAGS_OR = '|'.join(TYPE_CHECKED_JSDOC_TAGS_LIST) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 88 | |
| 89 | # 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). |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 90 | INVALID_TYPE_REGEX = re.compile(r'@(?:' + TYPE_CHECKED_JSDOC_TAGS_OR + |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 91 | r')\s*\{.*(?<![!?:._A-Za-z0-9])([A-Z][_A-Za-z0-9.]+[A-Za-z0-9])[^/]*\}') |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 92 | INVALID_TYPE_DESIGNATOR_REGEX = re.compile(r'@(?:' + TYPE_CHECKED_JSDOC_TAGS_OR + r')\s*.*(?<![{: ])([?!])=?\}') |
| 93 | INVALID_NON_OBJECT_TYPE_REGEX = re.compile(r'@(?:' + TYPE_CHECKED_JSDOC_TAGS_OR + r')\s*\{.*(![a-z]+)[^/]*\}') |
| 94 | ERROR_WARNING_REGEX = re.compile(r'WARNING|ERROR') |
| 95 | LOADED_CSS_REGEX = re.compile(r'(?:registerRequiredCSS|WebInspector\.View\.createStyleElement)\s*\(\s*"(.+)"\s*\)') |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 96 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 97 | JAVA_BUILD_REGEX = re.compile(r'\w+ version "(\d+)\.(\d+)') |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 98 | |
| 99 | |
| 100 | def log_error(message): |
| 101 | print 'ERROR: ' + message |
| 102 | |
| 103 | |
| 104 | def error_excepthook(exctype, value, traceback): |
| 105 | print 'ERROR:' |
| 106 | sys.__excepthook__(exctype, value, traceback) |
| 107 | |
| 108 | |
| 109 | sys.excepthook = error_excepthook |
| 110 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 111 | APPLICATION_DESCRIPTORS = [ |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 112 | 'inspector', |
| 113 | 'toolbox', |
| 114 | 'integration_test_runner', |
| 115 | 'formatter_worker', |
| 116 | 'heap_snapshot_worker', |
| 117 | ] |
| 118 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 119 | SKIPPED_NAMESPACES = { |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 120 | 'Console', # Closure uses Console as a namespace item so we cannot override it right now. |
| 121 | 'Gonzales', # third party module defined in front_end/externs.js |
| 122 | 'Terminal', # third party module defined in front_end/externs.js |
| 123 | } |
| 124 | |
| 125 | |
| 126 | def has_errors(output): |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 127 | return re.search(ERROR_WARNING_REGEX, output) is not None |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 128 | |
| 129 | |
| 130 | class JSDocChecker: |
| 131 | |
| 132 | def __init__(self, descriptors, java_exec): |
| 133 | self._error_found = False |
| 134 | self._all_files = descriptors.all_compiled_files() |
| 135 | self._java_exec = java_exec |
| 136 | |
| 137 | def check(self): |
| 138 | print 'Verifying JSDoc comments...' |
| 139 | self._verify_jsdoc() |
| 140 | self._run_jsdoc_validator() |
| 141 | return self._error_found |
| 142 | |
| 143 | def _run_jsdoc_validator(self): |
| 144 | files = [to_platform_path(f) for f in self._all_files] |
| 145 | file_list = tempfile.NamedTemporaryFile(mode='wt', delete=False) |
| 146 | try: |
| 147 | file_list.write('\n'.join(files)) |
| 148 | finally: |
| 149 | file_list.close() |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 150 | proc = popen(self._java_exec + ['-jar', JSDOC_VALIDATOR_JAR, '--files-list-name', to_platform_path_exact(file_list.name)]) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 151 | (out, _) = proc.communicate() |
| 152 | if out: |
| 153 | print('JSDoc validator output:%s%s' % (os.linesep, out)) |
| 154 | self._error_found = True |
| 155 | os.remove(file_list.name) |
| 156 | |
| 157 | def _verify_jsdoc(self): |
| 158 | for full_file_name in self._all_files: |
| 159 | line_index = 0 |
| 160 | with open(full_file_name, 'r') as sourceFile: |
| 161 | for line in sourceFile: |
| 162 | line_index += 1 |
| 163 | if line.rstrip(): |
| 164 | self._verify_jsdoc_line(full_file_name, line_index, line) |
| 165 | |
| 166 | def _verify_jsdoc_line(self, file_name, line_index, line): |
| 167 | |
| 168 | def print_error(message, error_position): |
| 169 | print '%s:%s: ERROR - %s%s%s%s%s%s' % (file_name, line_index, message, os.linesep, line, os.linesep, |
| 170 | ' ' * error_position + '^', os.linesep) |
| 171 | |
| 172 | known_css = {} |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 173 | match = re.search(INVALID_TYPE_REGEX, line) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 174 | if match: |
| 175 | print_error('Type "%s" nullability not marked explicitly with "?" (nullable) or "!" (non-nullable)' % match.group(1), |
| 176 | match.start(1)) |
| 177 | self._error_found = True |
| 178 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 179 | match = re.search(INVALID_NON_OBJECT_TYPE_REGEX, line) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 180 | if match: |
| 181 | print_error('Non-object type explicitly marked with "!" (non-nullable), which is the default and should be omitted', |
| 182 | match.start(1)) |
| 183 | self._error_found = True |
| 184 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 185 | match = re.search(INVALID_TYPE_DESIGNATOR_REGEX, line) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 186 | if match: |
| 187 | print_error('Type nullability indicator misplaced, should precede type', match.start(1)) |
| 188 | self._error_found = True |
| 189 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 190 | match = re.search(LOADED_CSS_REGEX, line) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 191 | if match: |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 192 | css_file = path.join(DEVTOOLS_FRONTEND_PATH, match.group(1)) |
| 193 | exists = known_css.get(css_file) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 194 | if exists is None: |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 195 | exists = path.isfile(css_file) |
| 196 | known_css[css_file] = exists |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 197 | if not exists: |
| 198 | print_error('Dynamically loaded CSS stylesheet is missing in the source tree', match.start(1)) |
| 199 | self._error_found = True |
| 200 | |
| 201 | |
| 202 | def find_java(): |
| 203 | required_major = 1 |
| 204 | required_minor = 7 |
| 205 | exec_command = None |
| 206 | has_server_jvm = True |
| 207 | java_path = utils.which('java') |
| 208 | |
| 209 | if not java_path: |
| 210 | print 'NOTE: No Java executable found in $PATH.' |
| 211 | sys.exit(1) |
| 212 | |
| 213 | is_ok = False |
| 214 | java_version_out, _ = popen([java_path, '-version']).communicate() |
| 215 | # pylint: disable=E1103 |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 216 | match = re.search(JAVA_BUILD_REGEX, java_version_out) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 217 | if match: |
| 218 | major = int(match.group(1)) |
| 219 | minor = int(match.group(2)) |
Alexei Filippov | 87e097d | 2018-11-06 19:18:29 +0000 | [diff] [blame] | 220 | is_ok = major > required_major or major == required_major and minor >= required_minor |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 221 | if is_ok: |
| 222 | exec_command = [java_path, '-Xms1024m', '-server', '-XX:+TieredCompilation'] |
| 223 | check_server_proc = popen(exec_command + ['-version']) |
| 224 | check_server_proc.communicate() |
| 225 | if check_server_proc.returncode != 0: |
| 226 | # Not all Java installs have server JVMs. |
| 227 | exec_command = exec_command.remove('-server') |
| 228 | has_server_jvm = False |
| 229 | |
| 230 | if not is_ok: |
| 231 | print 'NOTE: Java executable version %d.%d or above not found in $PATH.' % (required_major, required_minor) |
| 232 | sys.exit(1) |
| 233 | print 'Java executable: %s%s' % (java_path, '' if has_server_jvm else ' (no server JVM)') |
| 234 | return exec_command |
| 235 | |
| 236 | |
| 237 | common_closure_args = [ |
| 238 | '--summary_detail_level', |
| 239 | '3', |
| 240 | '--jscomp_error', |
| 241 | 'visibility', |
| 242 | '--jscomp_warning', |
| 243 | 'missingOverride', |
| 244 | '--compilation_level', |
| 245 | 'SIMPLE_OPTIMIZATIONS', |
| 246 | '--warning_level', |
| 247 | 'VERBOSE', |
Tim van der Lippe | 620071a | 2019-09-25 13:33:32 +0000 | [diff] [blame] | 248 | '--language_in=ECMASCRIPT_NEXT', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 249 | '--language_out=ES5_STRICT', |
| 250 | '--extra_annotation_name', |
| 251 | 'suppressReceiverCheck', |
| 252 | '--extra_annotation_name', |
| 253 | 'suppressGlobalPropertiesCheck', |
| 254 | '--checks-only', |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 255 | ] |
| 256 | |
| 257 | |
| 258 | def check_conditional_dependencies(modules_by_name): |
| 259 | errors_found = False |
| 260 | for name in modules_by_name: |
| 261 | if 'test_runner' in name: |
| 262 | continue |
| 263 | for dep_name in modules_by_name[name].get('dependencies', []): |
| 264 | dependency = modules_by_name[dep_name] |
| 265 | if dependency.get('experiment') or dependency.get('condition'): |
| 266 | log_error('Module "%s" may not depend on the conditional module "%s"' % (name, dep_name)) |
| 267 | errors_found = True |
| 268 | return errors_found |
| 269 | |
| 270 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 271 | def prepare_closure_frontend_compile(temp_devtools_path, descriptors, namespace_externs_path, protocol_externs_file): |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 272 | temp_frontend_path = path.join(temp_devtools_path, 'front_end') |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 273 | checker = dependency_preprocessor.DependencyPreprocessor(descriptors, temp_frontend_path, DEVTOOLS_FRONTEND_PATH) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 274 | checker.enforce_dependencies() |
| 275 | |
| 276 | command = common_closure_args + [ |
| 277 | '--externs', |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 278 | to_platform_path(GLOBAL_EXTERNS_FILE), |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 279 | '--externs', |
| 280 | namespace_externs_path, |
| 281 | '--js', |
Brandon Goddard | 52dd33a | 2019-09-25 16:58:21 +0000 | [diff] [blame] | 282 | ROOT_MODULE_FILE, |
Paul Lewis | 0cd45e3 | 2019-09-25 22:19:27 +0000 | [diff] [blame] | 283 | '--js', |
| 284 | RUNTIME_FILE, |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 285 | ] |
| 286 | |
| 287 | all_files = descriptors.all_compiled_files() |
| 288 | args = [] |
| 289 | for file in all_files: |
| 290 | args.extend(['--js', file]) |
| 291 | if "InspectorBackend.js" in file: |
| 292 | args.extend(['--js', protocol_externs_file]) |
| 293 | command += args |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 294 | command = [arg.replace(DEVTOOLS_FRONTEND_PATH, temp_frontend_path) for arg in command] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 295 | compiler_args_file = tempfile.NamedTemporaryFile(mode='wt', delete=False) |
| 296 | try: |
| 297 | compiler_args_file.write('devtools_frontend %s' % (' '.join(command))) |
| 298 | finally: |
| 299 | compiler_args_file.close() |
| 300 | return compiler_args_file.name |
| 301 | |
| 302 | |
| 303 | def generate_namespace_externs(modules_by_name): |
| 304 | special_case_namespaces_path = path.join(path.dirname(path.abspath(__file__)), 'special_case_namespaces.json') |
| 305 | with open(special_case_namespaces_path) as json_file: |
| 306 | special_case_namespaces = json.load(json_file) |
| 307 | |
| 308 | def map_module_to_namespace(module): |
| 309 | return special_case_namespaces.get(module, to_camel_case(module)) |
| 310 | |
| 311 | def to_camel_case(snake_string): |
| 312 | components = snake_string.split('_') |
| 313 | return ''.join(x.title() for x in components) |
| 314 | |
| 315 | all_namespaces = [map_module_to_namespace(module) for module in modules_by_name] |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 316 | namespaces = [namespace for namespace in all_namespaces if namespace not in SKIPPED_NAMESPACES] |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 317 | namespaces.sort() |
| 318 | namespace_externs_file = tempfile.NamedTemporaryFile(mode='wt', delete=False) |
| 319 | try: |
| 320 | for namespace in namespaces: |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 321 | namespace_externs_file.write('var %s = {};\n' % namespace) |
| 322 | finally: |
| 323 | namespace_externs_file.close() |
| 324 | namespace_externs_path = to_platform_path(namespace_externs_file.name) |
| 325 | return namespace_externs_path |
| 326 | |
| 327 | |
| 328 | def main(): |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 329 | protocol_externs_file = DEFAULT_PROTOCOL_EXTERNS_FILE |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 330 | errors_found = False |
| 331 | parser = argparse.ArgumentParser() |
| 332 | parser.add_argument('--protocol-externs-file') |
| 333 | args, _ = parser.parse_known_args() |
| 334 | if args.protocol_externs_file: |
| 335 | protocol_externs_file = args.protocol_externs_file |
| 336 | else: |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 337 | generate_protocol_externs.generate_protocol_externs(protocol_externs_file, path.join( |
| 338 | INSPECTOR_PATH, 'browser_protocol.pdl'), path.join(V8_INCLUDE_PATH, 'js_protocol.pdl')) |
| 339 | loader = modular_build.DescriptorLoader(DEVTOOLS_FRONTEND_PATH) |
| 340 | descriptors = loader.load_applications(APPLICATION_DESCRIPTORS) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 341 | modules_by_name = descriptors.modules |
| 342 | |
| 343 | java_exec = find_java() |
| 344 | errors_found |= check_conditional_dependencies(modules_by_name) |
| 345 | |
| 346 | print 'Compiling frontend...' |
| 347 | temp_devtools_path = tempfile.mkdtemp() |
| 348 | namespace_externs_path = generate_namespace_externs(modules_by_name) |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 349 | compiler_args_file_path = prepare_closure_frontend_compile(temp_devtools_path, descriptors, namespace_externs_path, |
| 350 | protocol_externs_file) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 351 | frontend_compile_proc = popen( |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 352 | java_exec + ['-jar', CLOSURE_RUNNER_JAR, '--compiler-args-file', |
| 353 | to_platform_path_exact(compiler_args_file_path)]) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 354 | |
| 355 | print 'Compiling devtools_compatibility.js...' |
| 356 | |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 357 | closure_compiler_command = java_exec + ['-jar', CLOSURE_COMPILER_JAR] + common_closure_args |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 358 | |
| 359 | devtools_js_compile_command = closure_compiler_command + [ |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 360 | '--externs', |
Tim van der Lippe | 7b19016 | 2019-09-27 15:10:44 +0000 | [diff] [blame^] | 361 | to_platform_path(GLOBAL_EXTERNS_FILE), '--jscomp_off=externsValidation', '--js', |
Yang Guo | 5ebd8a7 | 2019-06-26 08:04:01 +0000 | [diff] [blame] | 362 | to_platform_path(path.join(DEVTOOLS_FRONTEND_PATH, 'devtools_compatibility.js')) |
Blink Reformat | 4c46d09 | 2018-04-07 15:32:37 +0000 | [diff] [blame] | 363 | ] |
| 364 | devtools_js_compile_proc = popen(devtools_js_compile_command) |
| 365 | |
| 366 | errors_found |= JSDocChecker(descriptors, java_exec).check() |
| 367 | |
| 368 | (devtools_js_compile_out, _) = devtools_js_compile_proc.communicate() |
| 369 | print 'devtools_compatibility.js compilation output:%s' % os.linesep, devtools_js_compile_out |
| 370 | errors_found |= has_errors(devtools_js_compile_out) |
| 371 | |
| 372 | (frontend_compile_out, _) = frontend_compile_proc.communicate() |
| 373 | print 'devtools frontend compilation output:' |
| 374 | for line in frontend_compile_out.splitlines(): |
| 375 | if "@@ START_MODULE" in line or "@@ END_MODULE" in line: |
| 376 | continue |
| 377 | print line |
| 378 | errors_found |= has_errors(frontend_compile_out) |
| 379 | |
| 380 | os.remove(protocol_externs_file) |
| 381 | os.remove(namespace_externs_path) |
| 382 | os.remove(compiler_args_file_path) |
| 383 | shutil.rmtree(temp_devtools_path, True) |
| 384 | |
| 385 | if errors_found: |
| 386 | print 'ERRORS DETECTED' |
| 387 | sys.exit(1) |
| 388 | print 'DONE - compiled without errors' |
| 389 | |
| 390 | |
| 391 | if __name__ == "__main__": |
| 392 | main() |