Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: fix bazel stamping #22965

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions WORKSPACE
Expand Up @@ -2,9 +2,9 @@ workspace(name = "angular")

http_archive(
name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/25bb70fb67bddcc257b869f434ccc0fd130ec3bd.zip",
strip_prefix = "rules_nodejs-25bb70fb67bddcc257b869f434ccc0fd130ec3bd",
sha256 = "11c0d73bdcb4b2608abbe5967be5a910bdaebf848eb13e4e7f8413bbdeb940b8",
url = "https://github.com/bazelbuild/rules_nodejs/archive/0.6.0.zip",
strip_prefix = "rules_nodejs-0.6.0",
sha256 = "e8a2bb5ca51fbafb244bc507bcebcae33a63d969f47413b319a8dcce032845bf",
)

load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")
Expand Down
3 changes: 2 additions & 1 deletion docs/BAZEL.md
Expand Up @@ -145,7 +145,8 @@ In our repo, here is how it's configured:

1) In `tools/bazel_stamp_vars.sh` we run the `git` commands to generate our versioning info.
1) In `tools/bazel.rc` we register this script as the value for the `workspace_status_command` flag. Bazel will run the script when it needs to stamp a binary.
1) In `tools/BUILD.bazel` we have a target `stamp_data` with the special `stamp=1` attribute, which requests that Bazel run the `workspace_status_command`. The result is written to a text file that can be used as an input to other rules.

Note that Bazel has a `--stamp` argument to `bazel build`, but this has no effect since our stamping takes place in Skylark rules. See https://github.com/bazelbuild/bazel/issues/1054

## Remote cache

Expand Down
4 changes: 2 additions & 2 deletions packages/bazel/src/ng_package/ng_package.bzl
Expand Up @@ -57,8 +57,8 @@ def _rollup(ctx, rollup_config, entry_point, inputs, js_output, format = "es"):
other_inputs = [ctx.executable._rollup, rollup_config]
if ctx.file.license_banner:
other_inputs.append(ctx.file.license_banner)
if ctx.file.stamp_data:
other_inputs.append(ctx.file.stamp_data)
if ctx.version_file:
other_inputs.append(ctx.version_file)
ctx.actions.run(
progress_message = "Angular Packaging: rolling up %s" % ctx.label.name,
mnemonic = "AngularPackageRollup",
Expand Down
10 changes: 0 additions & 10 deletions tools/BUILD.bazel
@@ -1,11 +1 @@
exports_files(["tsconfig.json"])

# Executes the workspace_status_command and provides the result.
# See the section on stamping in docs/BAZEL.md
genrule(
name = "stamp_data",
outs = ["stamp_data.txt"],
cmd = "cat bazel-out/volatile-status.txt > $@",
stamp = True,
visibility = ["//:__subpackages__"],
)
1 change: 0 additions & 1 deletion tools/bazel_stamp_vars.sh
@@ -1,6 +1,5 @@
#!/usr/bin/env bash
# Generates the data used by the stamping feature in bazel.
# A genrule with stamp=1 can read the resulting file from bazel-out/volatile-status.txt
# See the section on stamping in docs/BAZEL.md

set -u -e -E -o pipefail
Expand Down
6 changes: 1 addition & 5 deletions tools/defaults.bzl
Expand Up @@ -45,26 +45,22 @@ def ng_module(name, tsconfig = None, entry_point = None, **kwargs):
entry_point = "public_api.ts"
_ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, **kwargs)

def ng_package(name, readme_md = None, license_banner = None, stamp_data = None, **kwargs):
def ng_package(name, readme_md = None, license_banner = None, **kwargs):
if not readme_md:
readme_md = "//packages:README.md"
if not license_banner:
license_banner = "//packages:license-banner.txt"
if not stamp_data:
stamp_data = "//tools:stamp_data"

_ng_package(
name = name,
readme_md = readme_md,
license_banner = license_banner,
stamp_data = stamp_data,
replacements = PKG_GROUP_REPLACEMENTS,
**kwargs)

def npm_package(name, replacements = {}, **kwargs):
_npm_package(
name = name,
stamp_data = "//tools:stamp_data",
replacements = dict(replacements, **PKG_GROUP_REPLACEMENTS),
**kwargs)

Expand Down