Skip to content

Commit

Permalink
build: update to [email protected]
Browse files Browse the repository at this point in the history
Updating to latest rules_nodejs which properly handles stamping for
releases.  Previously rollup_bundle and npm_package were unable to
be cached remotely.
See bazel-contrib/rules_nodejs#1441 for changes.

With new requirements from changes in rules_nodejs, we now must add
--stamp to bazel builds we wish to include stamping.
  • Loading branch information
josephperrott committed Dec 11, 2019
1 parent 985d9d3 commit ff1dc91
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 15 deletions.
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
Expand Down
4 changes: 2 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions integration/bazel/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 12 additions & 5 deletions packages/bazel/src/ng_package/ng_package.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()]),
Expand All @@ -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)
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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:
```
Expand Down Expand Up @@ -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:
```
Expand Down Expand Up @@ -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,
Expand Down
18 changes: 12 additions & 6 deletions tools/ng_rollup_bundle/ng_rollup_bundle.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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,
),
Expand All @@ -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:
```
Expand Down Expand Up @@ -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:
```
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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]),
Expand All @@ -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)
Expand All @@ -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(
Expand Down

0 comments on commit ff1dc91

Please sign in to comment.