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
diff --git a/tools/stamper.bzl b/tools/stamper.bzl new file mode 100644 index 0000000..ecbf75d --- /dev/null +++ b/tools/stamper.bzl
@@ -0,0 +1,20 @@ +# TODO(davido): Consider to move this general bazlets to Bazlets repository +load("@com_googlesource_gerrit_bazlets//tools:genrule2.bzl", "genrule2") + +def stamp(workspace, name): + # TODO(davido): Remove manual merge of manifest file when this feature + # request is implemented: https://github.com/bazelbuild/bazel/issues/2009 + genrule2( + name = "%s-stamped" % name, + stamp = 1, + srcs = [":%s" % name], + cmd = " && ".join([ + "GEN_VERSION=$$(cat bazel-out/stable-status.txt | grep -w STABLE_BUILD_%s_LABEL | cut -d ' ' -f 2)" % workspace.upper(), + "cd $$TMP", + "unzip -q $$ROOT/$<", + "echo \"Implementation-Version: $$GEN_VERSION\n$$(cat META-INF/MANIFEST.MF)\" > META-INF/MANIFEST.MF", + "zip -qr $$ROOT/$@ ."]), + outs = ["%s-stamped.jar" % name], + visibility = ["//visibility:public"], + ) +