Skip to content

Commit 719b2e9

Browse files
davidoDavid Ostrovsky
authored and
David Ostrovsky
committed
Stamp final artifacts
Merge Implementation-Version into the final artifacts. This has two advantages: for one, it can be later tracked down, from what release this artifact was consumed; for another, in case a release was produced without touching any source files but only bumping some dependencies, that are not shaded in the final artifacts and thus do not contribute to the SHA1 update of the final artifacts, the SHA1 would still change, because of the changed content of the META-INF/MANIFEST.MF file. For example building from this commit will produce the following manifest content: $ bazel build java/com/google/gitiles/blame/cache:cache-stamped bazel-genfiles/java/com/google/gitiles/blame/cache/cache-stamped.jar Unzipping the content of the cache-stamped.jar produces the following implementation version: $ cat META-INF/MANIFEST.MF | grep -i Impl Implementation-Version: v0.2-3-7-g9af1a70 Change-Id: Idb6e7c635ae254188e1ee6592e0e0502c7c338a6
1 parent bc53e1b commit 719b2e9

File tree

6 files changed

+54
-2
lines changed

6 files changed

+54
-2
lines changed

java/com/google/gitiles/BUILD

+7
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,10 @@ java_doc(
5151
title = "Gitiles API Documentation",
5252
visibility = ["//visibility:public"],
5353
)
54+
55+
load("//tools:stamper.bzl", "stamp")
56+
57+
stamp(
58+
name = "servlet",
59+
workspace = "gitiles",
60+
)

java/com/google/gitiles/blame/cache/BUILD

+7
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,10 @@ java_doc(
2121
title = "Blame Cache API Documentation",
2222
visibility = ["//visibility:public"],
2323
)
24+
25+
load("//tools:stamper.bzl", "stamp")
26+
27+
stamp(
28+
name = "cache",
29+
workspace = "gitiles",
30+
)

tools/bazel.rc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build --workspace_status_command=./tools/workspace-status.sh

tools/maven/BUILD

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ maven_package(
1212
},
1313
group = "com.google.gitiles",
1414
jar = {
15-
"blame-cache": "//java/com/google/gitiles/blame/cache",
16-
"gitiles-servlet": "//java/com/google/gitiles:servlet",
15+
"blame-cache": "//java/com/google/gitiles/blame/cache:cache-stamped",
16+
"gitiles-servlet": "//java/com/google/gitiles:servlet-stamped",
1717
},
1818
repository = "gerrit-maven-repository",
1919
url = "gs://gerrit-maven",

tools/stamper.bzl

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# TODO(davido): Consider to move this general bazlets to Bazlets repository
2+
load("@com_googlesource_gerrit_bazlets//tools:genrule2.bzl", "genrule2")
3+
4+
def stamp(workspace, name):
5+
# TODO(davido): Remove manual merge of manifest file when this feature
6+
# request is implemented: https://github.com/bazelbuild/bazel/issues/2009
7+
genrule2(
8+
name = "%s-stamped" % name,
9+
stamp = 1,
10+
srcs = [":%s" % name],
11+
cmd = " && ".join([
12+
"GEN_VERSION=$$(cat bazel-out/stable-status.txt | grep -w STABLE_BUILD_%s_LABEL | cut -d ' ' -f 2)" % workspace.upper(),
13+
"cd $$TMP",
14+
"unzip -q $$ROOT/$<",
15+
"echo \"Implementation-Version: $$GEN_VERSION\n$$(cat META-INF/MANIFEST.MF)\" > META-INF/MANIFEST.MF",
16+
"zip -qr $$ROOT/$@ ."]),
17+
outs = ["%s-stamped.jar" % name],
18+
visibility = ["//visibility:public"],
19+
)
20+

tools/workspace-status.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
3+
# This script will be run by bazel when the build process starts to
4+
# generate key-value information that represents the status of the
5+
# workspace. The output should be like
6+
#
7+
# KEY1 VALUE1
8+
# KEY2 VALUE2
9+
#
10+
# If the script exits with non-zero code, it's considered as a failure
11+
# and the output will be discarded.
12+
13+
function rev() {
14+
cd $1; git describe --always --match "v[0-9].*" --dirty
15+
}
16+
17+
echo STABLE_BUILD_GITILES_LABEL $(rev .)

0 commit comments

Comments
 (0)