bazel: generate the workspace version from the volatile status.

This generates a version file that looks correct, but doesn't rebuild
correctly.  Correct rebuilds will be provided by a version of
bazel containing

  a2897bff4c

Change-Id: I5101d7f2643d464cf32c8281a28ec6c3fc4fa2cf
This commit is contained in:
Han-Wen Nienhuys 2016-09-20 14:52:52 +02:00
parent 3ac816776c
commit 214171ddda
4 changed files with 23 additions and 9 deletions

View File

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

11
BUILD
View File

@ -1,11 +1,10 @@
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 = "grep STABLE_BUILD_GERRIT_LABEL < bazel-out/volatile-status.txt | cut -d ' ' -f 2 > $@",
outs = ['version.txt'],
visibility = ['//visibility:public'],
)

View File

@ -62,9 +62,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}"