treewide: replace stampsrcs with embed
A rules_go maintainer suggested using embed instead of stampsrcs:
https://github.com/bazel-contrib/rules_go/issues/3507
For Kubernetes, this means we need to patch the version libraries.
Instead of creating a separate file for each variable, I put them all in
one file, which is parsed in an init function. This init function needs
to run before all other init functions, which access the variables.
Another benefit of this change is that versions are stamped in all
binaries which include Kubernetes client libraries, not just hyperkube.
Change-Id: Ib1157d3686fc35e0c4191d2fc8e165862a1973c7
Reviewed-on: https://review.monogon.dev/c/monogon/+/4208
Tested-by: Jenkins CI
Reviewed-by: Tim Windelschmidt <tim@monogon.tech>
diff --git a/build/BUILD.bazel b/build/BUILD.bazel
index 3708a0b..9cd94ec 100644
--- a/build/BUILD.bazel
+++ b/build/BUILD.bazel
@@ -1,18 +1,42 @@
-load("//build/filter_stamp:def.bzl", "filtered_stamp")
+load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
-# This is a filtered stable status file which contains only the variables which
-# do not change on every commit. Using this instead of the status file avoids
-# unnecessary rebuilds.
-filtered_stamp(
- name = "stabler_status",
- vars = [
- "KUBERNETES_gitMajor",
- "KUBERNETES_gitMinor",
- "KUBERNETES_gitVersion",
- "KUBERNETES_gitCommit",
- "KUBERNETES_gitTreeState",
- "KUBERNETES_buildDate",
- "MONOGON_copyright",
- ],
+# The copyright and Kubernetes stamp variables change less often than the status
+# file. Instead of stamping these into Go binaries through x_defs, we create a
+# file for each variable and stamp through go:embed. With this indirection, only
+# the expand_template actions are executed each time the status file changes,
+# instead of relinking the Go binaries, which would be more expensive.
+
+expand_template(
+ name = "copyright_line",
+ out = "copyright_line.txt",
+ stamp = 1,
+ stamp_substitutions = {"copyright": "{{STABLE_MONOGON_copyright}}"},
+ template = ["copyright"],
+ visibility = ["//visibility:public"],
+)
+
+kubernetes_vars = [
+ "gitMajor",
+ "gitMinor",
+ "gitVersion",
+ "gitCommit",
+ "gitTreeState",
+ "buildDate",
+]
+
+[
+ expand_template(
+ name = "kubernetes_%s" % var,
+ out = "kubernetes_%s.txt" % var,
+ stamp = 1,
+ stamp_substitutions = {"value": "{{STABLE_KUBERNETES_%s}}" % var},
+ template = ["value"],
+ )
+ for var in kubernetes_vars
+]
+
+filegroup(
+ name = "kubernetes_stamp",
+ srcs = ["kubernetes_%s.txt" % var for var in kubernetes_vars],
visibility = ["//visibility:public"],
)