bazel: generate the workspace version from the volatile status.

To work across bazel 0.3.1 and 0.3.2, we should grep both volatile and
stable status files for the magic version string.

Change-Id: I48361374a8d9cda1e7a5b5db4e147bc49b4452a3
This commit is contained in:
Han-Wen Nienhuys 2016-10-24 13:03:32 +02:00
parent 65b71d28e6
commit dc255120cf
4 changed files with 24 additions and 9 deletions

View File

@ -1 +1 @@
build --strategy=Javac=worker
build --workspace_status_command=./tools/workspace-status.sh --strategy=Javac=worker

12
BUILD
View File

@ -1,11 +1,11 @@
load('//tools/bzl:genrule2.bzl', 'genrule2')
load('//tools/bzl:pkg_war.bzl', 'pkg_war')
genrule2(
name = 'version',
srcs = ['VERSION'],
cmd = "grep GERRIT_VERSION $< | cut -d \"'\" -f 2 >$@",
out = 'version.txt',
genrule(
name = 'gen_version',
stamp = 1,
cmd = ("cat bazel-out/volatile-status.txt bazel-out/stable-status.txt | " +
"grep STABLE_BUILD_GERRIT_LABEL | cut -d ' ' -f 2 > $@"),
outs = ['version.txt'],
visibility = ['//visibility:public'],
)

View File

@ -63,9 +63,9 @@ genrule2(
cmd = ' && '.join([
'cd $$TMP',
'mkdir -p com/google/gerrit/common',
'cat $$ROOT/$(location //:version) >com/google/gerrit/common/Version',
'cat $$ROOT/$(location //:version.txt) >com/google/gerrit/common/Version',
'zip -9Dqr $$ROOT/$@ .',
]),
tools = ['//:version'],
tools = ['//:version.txt'],
out = 'gen_version.jar',
)

15
tools/workspace-status.sh Executable file
View File

@ -0,0 +1,15 @@
#!/bin/sh
# This script will be run by bazel when the build process starts to
# generate key-value information that represents the status of the
# workspace. The output should be like
#
# KEY1 VALUE1
# KEY2 VALUE2
#
# If the script exits with non-zero code, it's considered as a failure
# and the output will be discarded.
git_rev=$(git describe --always --match "v[0-9].*" --dirty)
echo "STABLE_BUILD_GERRIT_LABEL ${git_rev}"