build: fix bazel stamping (#22965)

As pointed out in https://github.com/bazelbuild/rules_nodejs/issues/156
our mechanism would never pick up changes to the version info.

PR Close #22965
This commit is contained in:
Alex Eagle 2018-03-23 11:34:18 -07:00 committed by Alex Rickabaugh
parent e1ea7ed019
commit 0b348c8ffe
6 changed files with 8 additions and 22 deletions

View File

@ -2,9 +2,9 @@ workspace(name = "angular")
http_archive( http_archive(
name = "build_bazel_rules_nodejs", name = "build_bazel_rules_nodejs",
url = "https://github.com/bazelbuild/rules_nodejs/archive/25bb70fb67bddcc257b869f434ccc0fd130ec3bd.zip", url = "https://github.com/bazelbuild/rules_nodejs/archive/0.6.0.zip",
strip_prefix = "rules_nodejs-25bb70fb67bddcc257b869f434ccc0fd130ec3bd", strip_prefix = "rules_nodejs-0.6.0",
sha256 = "11c0d73bdcb4b2608abbe5967be5a910bdaebf848eb13e4e7f8413bbdeb940b8", sha256 = "e8a2bb5ca51fbafb244bc507bcebcae33a63d969f47413b319a8dcce032845bf",
) )
load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install") load("@build_bazel_rules_nodejs//:defs.bzl", "check_bazel_version", "node_repositories", "yarn_install")

View File

@ -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_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/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 ## Remote cache

View File

@ -57,8 +57,8 @@ def _rollup(ctx, rollup_config, entry_point, inputs, js_output, format = "es"):
other_inputs = [ctx.executable._rollup, rollup_config] other_inputs = [ctx.executable._rollup, rollup_config]
if ctx.file.license_banner: if ctx.file.license_banner:
other_inputs.append(ctx.file.license_banner) other_inputs.append(ctx.file.license_banner)
if ctx.file.stamp_data: if ctx.version_file:
other_inputs.append(ctx.file.stamp_data) other_inputs.append(ctx.version_file)
ctx.actions.run( ctx.actions.run(
progress_message = "Angular Packaging: rolling up %s" % ctx.label.name, progress_message = "Angular Packaging: rolling up %s" % ctx.label.name,
mnemonic = "AngularPackageRollup", mnemonic = "AngularPackageRollup",

View File

@ -1,11 +1 @@
exports_files(["tsconfig.json"]) 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__"],
)

View File

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Generates the data used by the stamping feature in bazel. # 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 # See the section on stamping in docs/BAZEL.md
set -u -e -E -o pipefail set -u -e -E -o pipefail

View File

@ -45,26 +45,22 @@ def ng_module(name, tsconfig = None, entry_point = None, **kwargs):
entry_point = "public_api.ts" entry_point = "public_api.ts"
_ng_module(name = name, flat_module_out_file = name, tsconfig = tsconfig, entry_point = entry_point, **kwargs) _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: if not readme_md:
readme_md = "//packages:README.md" readme_md = "//packages:README.md"
if not license_banner: if not license_banner:
license_banner = "//packages:license-banner.txt" license_banner = "//packages:license-banner.txt"
if not stamp_data:
stamp_data = "//tools:stamp_data"
_ng_package( _ng_package(
name = name, name = name,
readme_md = readme_md, readme_md = readme_md,
license_banner = license_banner, license_banner = license_banner,
stamp_data = stamp_data,
replacements = PKG_GROUP_REPLACEMENTS, replacements = PKG_GROUP_REPLACEMENTS,
**kwargs) **kwargs)
def npm_package(name, replacements = {}, **kwargs): def npm_package(name, replacements = {}, **kwargs):
_npm_package( _npm_package(
name = name, name = name,
stamp_data = "//tools:stamp_data",
replacements = dict(replacements, **PKG_GROUP_REPLACEMENTS), replacements = dict(replacements, **PKG_GROUP_REPLACEMENTS),
**kwargs) **kwargs)