From 1104d17252fef2d76a8be45c8327001e43d4971a Mon Sep 17 00:00:00 2001 From: Alex Eagle Date: Wed, 17 Jan 2018 14:49:08 -0800 Subject: [PATCH] refactor(bazel): pass around tsconfig as a file, not a path (#21614) this unlocks the ability to replay ts compilations with different settings PR Close #21614 --- WORKSPACE | 11 +++++++---- integration/bazel/WORKSPACE | 11 +++++++---- packages/bazel/src/ng_module.bzl | 25 +++++++++++++------------ 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 62c4341dfd..5a3099e55b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -15,12 +15,15 @@ node_repositories(package_json = ["//:package.json"]) git_repository( name = "build_bazel_rules_typescript", - remote = "https://github.com/bazelbuild/rules_typescript.git", -# tag = "0.7.1+", - commit = "89d2c75066bea3d9c942f29dd1d2ea543c58d6d5" + # Use alexeagle's branch temporarily to allow a green build in the middle of + # the tsconfig refactoring. + # TODO(alexeagle): after the change lands in google3, push it to bazelbuild + # mirror and point this back to upstream. + remote = "https://github.com/alexeagle/rules_typescript.git", + commit = "5ccf967a393d94f53b5b1a97760eb1e18367faa3" ) -load("@build_bazel_rules_typescript//:setup.bzl", "ts_setup_workspace") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace") ts_setup_workspace() diff --git a/integration/bazel/WORKSPACE b/integration/bazel/WORKSPACE index 57fca31224..2c66d3b75f 100644 --- a/integration/bazel/WORKSPACE +++ b/integration/bazel/WORKSPACE @@ -13,12 +13,15 @@ node_repositories(package_json = ["//:package.json"]) git_repository( name = "build_bazel_rules_typescript", - remote = "https://github.com/bazelbuild/rules_typescript.git", -# tag = "0.6.0", - commit = "89d2c75066bea3d9c942f29dd1d2ea543c58d6d5" + # Use alexeagle's branch temporarily to allow a green build in the middle of + # the tsconfig refactoring. + # TODO(alexeagle): after the change lands in google3, push it to bazelbuild + # mirror and point this back to upstream. + remote = "https://github.com/alexeagle/rules_typescript.git", + commit = "5ccf967a393d94f53b5b1a97760eb1e18367faa3" ) -load("@build_bazel_rules_typescript//:setup.bzl", "ts_setup_workspace") +load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace") ts_setup_workspace() diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index 16655cc09f..71e74a3c0b 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -106,7 +106,7 @@ _EXTRA_NODE_OPTIONS_FLAGS = [ "--node_options=--expose-gc" ] -def ngc_compile_action(ctx, label, inputs, outputs, messages_out, config_file_path, +def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file, locale=None, i18n_args=[]): """Helper function to create the ngc action. @@ -119,7 +119,7 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, config_file_pa inputs: passed to the ngc action's inputs outputs: passed to the ngc action's outputs messages_out: produced xmb files - config_file_path: path to the tsconfig file + tsconfig_file: tsconfig file with settings used for the compilation locale: i18n locale, or None i18n_args: additional command-line arguments to ngc @@ -143,9 +143,9 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, config_file_pa # Two at-signs escapes the argument so it's passed through to ngc # rather than the contents getting expanded. if supports_workers == "1": - arguments += ["@@" + config_file_path] + arguments += ["@@" + tsconfig_file.path] else: - arguments += ["-p", config_file_path] + arguments += ["-p", tsconfig_file.path] arguments += i18n_args @@ -166,7 +166,7 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, config_file_pa outputs = messages_out, executable = ctx.executable._ng_xi18n, arguments = (_EXTRA_NODE_OPTIONS_FLAGS + - [config_file_path] + + [tsconfig_file.path] + # The base path is bin_dir because of the way the ngc # compiler host is configured. So we need to explictily # point to genfiles/ to redirect the output. @@ -177,14 +177,14 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, config_file_pa if not locale and not ctx.attr.no_i18n: return struct( label = label, - tsconfig = config_file_path, + tsconfig = tsconfig_file, inputs = inputs, outputs = outputs, ) return None -def _compile_action(ctx, inputs, outputs, messages_out, config_file_path): +def _compile_action(ctx, inputs, outputs, messages_out, tsconfig_file): # Give the Angular compiler all the user-listed assets file_inputs = list(ctx.files.assets) @@ -203,16 +203,17 @@ def _compile_action(ctx, inputs, outputs, messages_out, config_file_path): transitive = [inputs] + [dep.collect_summaries_aspect_result for dep in ctx.attr.deps if hasattr(dep, "collect_summaries_aspect_result")]) - return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, config_file_path) + return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file) -def _prodmode_compile_action(ctx, inputs, outputs, config_file_path): +def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file): outs = _expected_outs(ctx) - return _compile_action(ctx, inputs, outputs + outs.closure_js, outs.i18n_messages, config_file_path) + return _compile_action(ctx, inputs, outputs + outs.closure_js, outs.i18n_messages, tsconfig_file) -def _devmode_compile_action(ctx, inputs, outputs, config_file_path): +def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file): outs = _expected_outs(ctx) - _compile_action(ctx, inputs, outputs + outs.devmode_js + outs.declarations + outs.summaries, None, config_file_path) + compile_action_outputs = outputs + outs.devmode_js + outs.declarations + outs.summaries + _compile_action(ctx, inputs, compile_action_outputs, None, tsconfig_file) def _ts_expected_outs(ctx, label): # rules_typescript expects a function with two arguments, but our