From ff1dc91fc43530a9f5785151066e200aeee1ec21 Mon Sep 17 00:00:00 2001 From: Joey Perrott Date: Wed, 11 Dec 2019 08:29:53 -0800 Subject: [PATCH] build: update to rules_nodejs@0.42.3 Updating to latest rules_nodejs which properly handles stamping for releases. Previously rollup_bundle and npm_package were unable to be cached remotely. See https://github.com/bazelbuild/rules_nodejs/pull/1441 for changes. With new requirements from changes in rules_nodejs, we now must add --stamp to bazel builds we wish to include stamping. --- .bazelrc | 1 + WORKSPACE | 4 ++-- integration/bazel/WORKSPACE | 4 ++-- packages/bazel/src/ng_package/ng_package.bzl | 17 ++++++++++++----- tools/ng_rollup_bundle/ng_rollup_bundle.bzl | 18 ++++++++++++------ 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/.bazelrc b/.bazelrc index 49d20925c2f646..3a5ce1e387e19e 100644 --- a/.bazelrc +++ b/.bazelrc @@ -43,6 +43,7 @@ test --incompatible_strict_action_env # This command assumes node on the path and is a workaround for # https://github.com/bazelbuild/bazel/issues/4802 build:release --workspace_status_command="node ./tools/bazel_stamp_vars.js" +build:release --stamp ############################### # Output # diff --git a/WORKSPACE b/WORKSPACE index 8f975b902759a8..563ada9b7bdd1b 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -8,8 +8,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Fetch rules_nodejs so we can install our npm dependencies http_archive( name = "build_bazel_rules_nodejs", - sha256 = "16fc00ab0d1e538e88f084272316c0693a2e9007d64f45529b82f6230aedb073", - urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.2/rules_nodejs-0.42.2.tar.gz"], + sha256 = "a54b2511d6dae42c1f7cdaeb08144ee2808193a088004fc3b464a04583d5aa2e", + urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.3/rules_nodejs-0.42.3.tar.gz"], ) # Check the bazel version and download npm dependencies diff --git a/integration/bazel/WORKSPACE b/integration/bazel/WORKSPACE index 8b14713d386abe..0ae9835e0c458e 100644 --- a/integration/bazel/WORKSPACE +++ b/integration/bazel/WORKSPACE @@ -8,8 +8,8 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") # Fetch rules_nodejs so we can install our npm dependencies http_archive( name = "build_bazel_rules_nodejs", - sha256 = "16fc00ab0d1e538e88f084272316c0693a2e9007d64f45529b82f6230aedb073", - urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.2/rules_nodejs-0.42.2.tar.gz"], + sha256 = "a54b2511d6dae42c1f7cdaeb08144ee2808193a088004fc3b464a04583d5aa2e", + urls = ["https://github.com/bazelbuild/rules_nodejs/releases/download/0.42.3/rules_nodejs-0.42.3.tar.gz"], ) # Fetch sass rules for compiling sass files diff --git a/packages/bazel/src/ng_package/ng_package.bzl b/packages/bazel/src/ng_package/ng_package.bzl index 88aaa759dc3d93..4fdaa68a579d8d 100644 --- a/packages/bazel/src/ng_package/ng_package.bzl +++ b/packages/bazel/src/ng_package/ng_package.bzl @@ -13,7 +13,7 @@ It packages your library following the Angular Package Format, see the specification of this format at https://goo.gl/jB3GVv """ -load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo", "JSNamedModuleInfo", "NpmPackageInfo", "node_modules_aspect") +load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo", "JSNamedModuleInfo", "NodeContextInfo", "NpmPackageInfo", "node_modules_aspect") load( "@build_bazel_rules_nodejs//internal/npm_package:npm_package.bzl", "NPM_PACKAGE_ATTRS", @@ -209,6 +209,7 @@ def _write_rollup_config(ctx, root_dir, filename = "_%s.rollup.conf.js", include The rollup config file. See https://rollupjs.org/guide/en#configuration-files """ config = ctx.actions.declare_file(filename % ctx.label.name) + stamp = ctx.attr._node_context_data[NodeContextInfo].stamp mappings = dict() all_deps = ctx.attr.deps + ctx.attr.srcs @@ -237,7 +238,7 @@ def _write_rollup_config(ctx, root_dir, filename = "_%s.rollup.conf.js", include "TMPL_module_mappings": str(mappings), "TMPL_node_modules_root": _compute_node_modules_root(ctx), "TMPL_root_dir": root_dir, - "TMPL_stamp_data": "\"%s\"" % ctx.version_file.path if ctx.version_file else "undefined", + "TMPL_stamp_data": "\"%s\"" % ctx.version_file.path if stamp else "undefined", "TMPL_workspace_name": ctx.workspace_name, "TMPL_external": ", ".join(["'%s'" % e for e in external]), "TMPL_globals": ", ".join(["'%s': '%s'" % g for g in globals.items()]), @@ -248,6 +249,7 @@ def _write_rollup_config(ctx, root_dir, filename = "_%s.rollup.conf.js", include def _run_rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, format, module_name = ""): map_output = ctx.actions.declare_file(js_output.basename + ".map", sibling = js_output) + stamp = ctx.attr._node_context_data[NodeContextInfo].stamp args = ctx.actions.args() args.add("--input", entry_point) @@ -286,7 +288,7 @@ def _run_rollup(ctx, bundle_name, rollup_config, entry_point, inputs, js_output, other_inputs = [rollup_config] if ctx.file.license_banner: other_inputs.append(ctx.file.license_banner) - if ctx.version_file: + if stamp: other_inputs.append(ctx.version_file) ctx.actions.run( progress_message = "ng_package: Rollup %s %s" % (bundle_name, ctx.label), @@ -640,7 +642,7 @@ _NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **{ "entry_point": attr.label( doc = """The starting point of the application, passed as the `--input` flag to rollup. - If the entry JavaScript file belongs to the same package (as the BUILD file), + If the entry JavaScript file belongs to the same package (as the BUILD file), you can simply reference it by its relative name to the package directory: ``` @@ -668,7 +670,7 @@ _NG_PACKAGE_ATTRS = dict(NPM_PACKAGE_ATTRS, **{ The rule will use the corresponding `.js` output of the ts_library rule as the entry point. - If the entry point target is a rule, it should produce a single JavaScript entry file that will be passed to the nodejs_binary rule. + If the entry point target is a rule, it should produce a single JavaScript entry file that will be passed to the nodejs_binary rule. For example: ``` @@ -747,6 +749,11 @@ If `config_file` isn't supplied, Bazel will use a default config file. default = Label(_DEFAULT_ROLLUP_CONFIG_TMPL), allow_single_file = True, ), + "_node_context_data": attr.label( + default = "@build_bazel_rules_nodejs//internal:node_context_data", + providers = [NodeContextInfo], + doc = "Internal use only", + ), }) # Angular wants these named after the entry_point, diff --git a/tools/ng_rollup_bundle/ng_rollup_bundle.bzl b/tools/ng_rollup_bundle/ng_rollup_bundle.bzl index 93f468dd7f7d9d..5512394f1da7b0 100644 --- a/tools/ng_rollup_bundle/ng_rollup_bundle.bzl +++ b/tools/ng_rollup_bundle/ng_rollup_bundle.bzl @@ -15,7 +15,7 @@ """ load("@build_bazel_rules_nodejs//:index.bzl", "npm_package_bin") -load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo", "NpmPackageInfo", "node_modules_aspect") +load("@build_bazel_rules_nodejs//:providers.bzl", "JSEcmaScriptModuleInfo", "NodeContextInfo", "NpmPackageInfo", "node_modules_aspect") load("//packages/bazel/src:esm5.bzl", "esm5_outputs_aspect", "esm5_root_dir", "flatten_esm5") load("@npm_bazel_terser//:index.bzl", "terser_minified") @@ -66,7 +66,6 @@ _NG_ROLLUP_BUNDLE_DEPS_ASPECTS = [esm5_outputs_aspect, ng_rollup_module_mappings _NG_ROLLUP_BUNDLE_ATTRS = { "build_optimizer": attr.bool( doc = """Use build optimizer plugin - Only used if sources are esm5 which depends on value of esm5_sources.""", default = True, ), @@ -82,7 +81,7 @@ _NG_ROLLUP_BUNDLE_ATTRS = { "entry_point": attr.label( doc = """The starting point of the application, passed as the `--input` flag to rollup. - If the entry JavaScript file belongs to the same package (as the BUILD file), + If the entry JavaScript file belongs to the same package (as the BUILD file), you can simply reference it by its relative name to the package directory: ``` @@ -110,7 +109,7 @@ _NG_ROLLUP_BUNDLE_ATTRS = { The rule will use the corresponding `.js` output of the ts_library rule as the entry point. - If the entry point target is a rule, it should produce a single JavaScript entry file that will be passed to the nodejs_binary rule. + If the entry point target is a rule, it should produce a single JavaScript entry file that will be passed to the nodejs_binary rule. For example: ``` @@ -181,6 +180,11 @@ _NG_ROLLUP_BUNDLE_ATTRS = { default = Label("//tools/ng_rollup_bundle:rollup.config.js"), allow_single_file = True, ), + "_node_context_data": attr.label( + default = "@build_bazel_rules_nodejs//internal:node_context_data", + providers = [NodeContextInfo], + doc = "Internal use only", + ), } def _compute_node_modules_root(ctx): @@ -244,6 +248,7 @@ def _write_rollup_config(ctx, root_dir, build_optimizer, filename = "_%s.rollup. The rollup config file. See https://rollupjs.org/guide/en#configuration-files """ config = ctx.actions.declare_file(filename % ctx.label.name) + stamp = ctx.attr._node_context_data[NodeContextInfo].stamp mappings = dict() all_deps = ctx.attr.deps + ctx.attr.srcs @@ -270,7 +275,7 @@ def _write_rollup_config(ctx, root_dir, build_optimizer, filename = "_%s.rollup. "TMPL_module_mappings": str(mappings), "TMPL_node_modules_root": _compute_node_modules_root(ctx), "TMPL_root_dir": root_dir, - "TMPL_stamp_data": "\"%s\"" % ctx.version_file.path if ctx.version_file else "undefined", + "TMPL_stamp_data": "\"%s\"" % ctx.version_file.path if stamp else "undefined", "TMPL_workspace_name": ctx.workspace_name, "TMPL_external": ", ".join(["'%s'" % e for e in external]), "TMPL_globals": ", ".join(["'%s': '%s'" % g for g in globals]), @@ -288,6 +293,7 @@ def _filter_js_inputs(all_inputs): ] def _run_rollup(ctx, entry_point_path, sources, config): + stamp = ctx.attr._node_context_data[NodeContextInfo].stamp args = ctx.actions.args() args.add("--config", config.path) args.add("--input", entry_point_path) @@ -314,7 +320,7 @@ def _run_rollup(ctx, entry_point_path, sources, config): if ctx.file.license_banner: direct_inputs.append(ctx.file.license_banner) - if ctx.version_file: + if stamp: direct_inputs.append(ctx.version_file) ctx.actions.run(