diff --git a/BUILD.gn b/BUILD.gn index 15d1d0adba..b7ce283768 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -2186,20 +2186,22 @@ group("devtools_all_files") { ] } -devtools_frontend_resources_deps = [ - ":aria_properties", - ":build_release_devtools", - ":copy_devtools_modules", - ":copy_embedder_scripts", - ":copy_emulated_devices_images", - ":copy_htaccess", - ":copy_inspector_images", - ":copy_lighthouse_locale_files", - ":copy_wasm_deps", - ":devtools_extension_api", - ":frontend_protocol_sources", - ":supported_css_properties", -] +devtools_typescript_deps = [ "front_end/common:common" ] + +devtools_frontend_resources_deps = devtools_typescript_deps + [ + ":aria_properties", + ":build_release_devtools", + ":copy_devtools_modules", + ":copy_embedder_scripts", + ":copy_emulated_devices_images", + ":copy_htaccess", + ":copy_inspector_images", + ":copy_lighthouse_locale_files", + ":copy_wasm_deps", + ":devtools_extension_api", + ":frontend_protocol_sources", + ":supported_css_properties", + ] if (debug_devtools) { devtools_frontend_resources_deps += [ diff --git a/build_overrides/BUILDCONFIG.gn b/build_overrides/BUILDCONFIG.gn index cee7a957fb..ac85c0f18f 100644 --- a/build_overrides/BUILDCONFIG.gn +++ b/build_overrides/BUILDCONFIG.gn @@ -40,6 +40,11 @@ declare_args() { # every toolchain can pass through the "global" value via toolchain_args(). host_toolchain = "" + # Needed to properly resolve the locations for the TypeScript build system + # when we are building for DevTools only. This arg will not be defined in + # Chromium itself. + use_devtools_typescript = true + # DON'T ADD MORE FLAGS HERE. Read the comment above. } diff --git a/front_end/common/BUILD.gn b/front_end/common/BUILD.gn new file mode 100644 index 0000000000..4c830dc2dc --- /dev/null +++ b/front_end/common/BUILD.gn @@ -0,0 +1,17 @@ +# Copyright 2019 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +import("../../third_party/typescript/typescript.gni") + +group("common") { + public_deps = [ + ":trie", + ] +} + +ts_library("trie") { + sources = [ + "Trie.js", + ] +} diff --git a/third_party/typescript/ts_library.py b/third_party/typescript/ts_library.py index 5b47faf93a..5c285c4aec 100644 --- a/third_party/typescript/ts_library.py +++ b/third_party/typescript/ts_library.py @@ -11,11 +11,21 @@ from os import path _CURRENT_DIR = path.join(path.dirname(__file__)) TSC_LOCATION = path.join(_CURRENT_DIR, '..', '..', 'node_modules', 'typescript', 'bin', 'tsc') -ROOT_TS_CONFIG_LOCATION = path.join(_CURRENT_DIR, 'tsconfig.json') +try: + old_sys_path = sys.path[:] + sys.path.append(path.join(_CURRENT_DIR, '..', '..', 'scripts')) + import devtools_paths +finally: + sys.path = old_sys_path +NODE_LOCATION = devtools_paths.node_path() + +ROOT_TS_CONFIG_LOCATION = path.join(_CURRENT_DIR, '..', '..', 'tsconfig.json') def runTsc(tsconfig_location): - process = subprocess.Popen([TSC_LOCATION, '-b', tsconfig_location], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + process = subprocess.Popen([NODE_LOCATION, TSC_LOCATION, '-b', tsconfig_location], + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) stdout, stderr = process.communicate() # TypeScript does not correctly write to stderr because of https://github.com/microsoft/TypeScript/issues/33849 return process.returncode, stdout + stderr @@ -24,7 +34,7 @@ def runTsc(tsconfig_location): def main(): parser = argparse.ArgumentParser() parser.add_argument('-s', '--sources', nargs='*', required=True, help='List of TypeScript source files') - parser.add_argument('-b', '--tsconfig_location', required=True) + parser.add_argument('-b', '--tsconfig_output_location', required=True) opts = parser.parse_args() with open(ROOT_TS_CONFIG_LOCATION) as root_tsconfig: try: @@ -33,7 +43,7 @@ def main(): print('Encountered error while loading root tsconfig:') print(e) return 1 - tsconfig_output_location = path.join(os.getcwd(), opts.tsconfig_location) + tsconfig_output_location = path.join(os.getcwd(), opts.tsconfig_output_location) tsconfig['files'] = [path.join(os.getcwd(), src) for src in opts.sources] tsconfig['compilerOptions']['outDir'] = path.dirname(tsconfig_output_location) with open(tsconfig_output_location, 'w') as generated_tsconfig: diff --git a/third_party/typescript/tsconfig.json b/third_party/typescript/tsconfig.json deleted file mode 100644 index 1d5057bedc..0000000000 --- a/third_party/typescript/tsconfig.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "compilerOptions": { - "target": "esnext", - "module": "esnext" - } -} \ No newline at end of file diff --git a/third_party/typescript/typescript.gni b/third_party/typescript/typescript.gni index 9f8f989f82..e2b5a4a5d5 100644 --- a/third_party/typescript/typescript.gni +++ b/third_party/typescript/typescript.gni @@ -2,7 +2,11 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -script_path = "//third_party/typescript" +if (defined(use_devtools_typescript) && use_devtools_typescript) { + devtools_location = "" +} else { + devtools_location = "third_party/devtools-frontend/src" +} # Defines a target that compiles .ts files using TypeScript. # A temporary tsconfig.json is generated which uses the @@ -17,17 +21,25 @@ script_path = "//third_party/typescript" # } template("ts_library") { action(target_name) { - script = "//third_party/typescript/ts_library.py" + script = "//$devtools_location/third_party/typescript/ts_library.py" - forward_variables_from(invoker, [ "sources", "visibility" ]) + forward_variables_from(invoker, + [ + "sources", + "visibility", + ]) + + inputs = [ + "//$devtools_location/tsconfig.json", + ] args = [ - "--tsconfig_location", - rebase_path(target_gen_dir, root_build_dir) + "/tsconfig.json", + "--tsconfig_output_location", + rebase_path(target_gen_dir, root_build_dir) + "/$target_name-tsconfig.json", ] args += [ "--sources" ] + rebase_path(sources, root_build_dir) - output_files = [ "$target_gen_dir/tsconfig.json" ] + output_files = [ "$target_gen_dir/$target_name-tsconfig.json" ] foreach(src, sources) { js_renamed_path = @@ -42,5 +54,5 @@ template("ts_library") { set_defaults("ts_library") { # Build output should be private and directories should export all relevant # components in a group - visibility = [":*"] + visibility = [ ":*" ] } diff --git a/tsconfig.json b/tsconfig.json index e963c4dc7d..91fa83559d 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -18,6 +18,5 @@ "forceConsistentCasingInFileNames": true, "noImplicitReturns": true, "noFallthroughCasesInSwitch": true - } } }