From ca06af40f4b731eda1f3f4cd5d9779505bf25a48 Mon Sep 17 00:00:00 2001 From: Martin Probst Date: Thu, 15 Feb 2018 22:43:15 +0100 Subject: [PATCH] build: allow passing node options to ngc. (#22245) PR Close #22245 --- WORKSPACE | 9 +++------ integration/bazel/WORKSPACE | 7 +++---- packages/bazel/src/ng_module.bzl | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/WORKSPACE b/WORKSPACE index 84ba511ddc..7bfda34ff7 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -16,13 +16,10 @@ load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_reposi check_bazel_version("0.9.0") node_repositories(package_json = ["//:package.json"]) -RULES_TYPESCRIPT_VERSION = "0.10.1" - -http_archive( +git_repository( name = "build_bazel_rules_typescript", - url = "https://github.com/bazelbuild/rules_typescript/archive/%s.zip" % RULES_TYPESCRIPT_VERSION, - strip_prefix = "rules_typescript-%s" % RULES_TYPESCRIPT_VERSION, - sha256 = "a2c81776a4a492ff9f878f9705639f5647bef345f7f3e1da09c9eeb8dec80485", + commit = "d3cc5cd72d89aee0e4c2553ae1b99c707ecbef4e", + remote = "https://github.com/bazelbuild/rules_typescript", ) load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace") diff --git a/integration/bazel/WORKSPACE b/integration/bazel/WORKSPACE index 7b17d4eab4..9d23735f92 100644 --- a/integration/bazel/WORKSPACE +++ b/integration/bazel/WORKSPACE @@ -10,11 +10,10 @@ http_archive( load("@build_bazel_rules_nodejs//:defs.bzl", "node_repositories") node_repositories(package_json = ["//:package.json"]) -http_archive( +git_repository( name = "build_bazel_rules_typescript", - url = "https://github.com/bazelbuild/rules_typescript/archive/0.10.1.zip", - strip_prefix = "rules_typescript-0.10.1", - sha256 = "a2c81776a4a492ff9f878f9705639f5647bef345f7f3e1da09c9eeb8dec80485", + commit = "d3cc5cd72d89aee0e4c2553ae1b99c707ecbef4e", + remote = "https://github.com/bazelbuild/rules_typescript", ) load("@build_bazel_rules_typescript//:defs.bzl", "ts_setup_workspace") diff --git a/packages/bazel/src/ng_module.bzl b/packages/bazel/src/ng_module.bzl index 5041dccc49..b36636c09f 100644 --- a/packages/bazel/src/ng_module.bzl +++ b/packages/bazel/src/ng_module.bzl @@ -121,7 +121,7 @@ _EXTRA_NODE_OPTIONS_FLAGS = [ ] def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file, - locale=None, i18n_args=[]): + node_opts, locale=None, i18n_args=[]): """Helper function to create the ngc action. This is exposed for google3 to wire up i18n replay rules, and is not intended @@ -134,6 +134,7 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file, outputs: passed to the ngc action's outputs messages_out: produced xmb files tsconfig_file: tsconfig file with settings used for the compilation + node_opts: list of strings, extra nodejs options. locale: i18n locale, or None i18n_args: additional command-line arguments to ngc @@ -152,7 +153,8 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file, else: supports_workers = str(int(ctx.attr._supports_workers)) - arguments = list(_EXTRA_NODE_OPTIONS_FLAGS) + arguments = (list(_EXTRA_NODE_OPTIONS_FLAGS) + + ["--node_options=%s" % opt for opt in node_opts]) # One at-sign makes this a params-file, enabling the worker strategy. # Two at-signs escapes the argument so it's passed through to ngc # rather than the contents getting expanded. @@ -199,7 +201,7 @@ def ngc_compile_action(ctx, label, inputs, outputs, messages_out, tsconfig_file, return None -def _compile_action(ctx, inputs, outputs, messages_out, tsconfig_file): +def _compile_action(ctx, inputs, outputs, messages_out, tsconfig_file, node_opts): # Give the Angular compiler all the user-listed assets file_inputs = list(ctx.files.assets) @@ -218,17 +220,17 @@ def _compile_action(ctx, inputs, outputs, messages_out, tsconfig_file): 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, tsconfig_file) + return ngc_compile_action(ctx, ctx.label, action_inputs, outputs, messages_out, tsconfig_file, node_opts) -def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file): +def _prodmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts): outs = _expected_outs(ctx) - return _compile_action(ctx, inputs, outputs + outs.closure_js, outs.i18n_messages, tsconfig_file) + return _compile_action(ctx, inputs, outputs + outs.closure_js, outs.i18n_messages, tsconfig_file, node_opts) -def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file): +def _devmode_compile_action(ctx, inputs, outputs, tsconfig_file, node_opts): outs = _expected_outs(ctx) compile_action_outputs = outputs + outs.devmode_js + outs.declarations + outs.summaries - _compile_action(ctx, inputs, compile_action_outputs, None, tsconfig_file) + _compile_action(ctx, inputs, compile_action_outputs, None, tsconfig_file, node_opts) def _ts_expected_outs(ctx, label): # rules_typescript expects a function with two arguments, but our