treewide: clean up test static binary targets

This removes some intermediate targets only used for transitions by
consolidating them into a single one.

Change-Id: I46dcbcb731038edd2b67259de1811018f5ba43da
Reviewed-on: https://review.monogon.dev/c/monogon/+/3753
Reviewed-by: Leopold Schabel <leo@monogon.tech>
Tested-by: Jenkins CI
Vouch-Run-CI: Tim Windelschmidt <tim@monogon.tech>
diff --git a/cloud/agent/takeover/BUILD.bazel b/cloud/agent/takeover/BUILD.bazel
index 63747a9..2b28464 100644
--- a/cloud/agent/takeover/BUILD.bazel
+++ b/cloud/agent/takeover/BUILD.bazel
@@ -1,3 +1,4 @@
+load("@aspect_bazel_lib//lib:transitions.bzl", "platform_transition_binary")
 load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
 load("//build/static_binary_tarball:def.bzl", "static_binary_tarball")
 load("//osbase/build:def.bzl", "node_initramfs")
@@ -26,6 +27,27 @@
     ],
 )
 
+go_binary(
+    name = "takeover_bin",
+    embed = [":takeover_lib"],
+    visibility = ["//visibility:private"],
+)
+
+# Used by e2e tests, forces a static build
+platform_transition_binary(
+    name = "takeover",
+    binary = ":takeover_bin",
+    target_platform = "//build/platforms:linux_amd64_static",
+    visibility = ["//visibility:public"],
+)
+
+# Used by container_images, forces a static build
+static_binary_tarball(
+    name = "takeover_layer",
+    executable = ":takeover_bin",
+    visibility = ["//visibility:public"],
+)
+
 node_initramfs(
     name = "initramfs",
     files = {
@@ -39,16 +61,3 @@
     ],
     visibility = ["//cloud/agent:__subpackages__"],
 )
-
-go_binary(
-    name = "takeover",
-    embed = [":takeover_lib"],
-    visibility = ["//visibility:public"],
-)
-
-# Used by container_images, forces a static build of the test_agent.
-static_binary_tarball(
-    name = "takeover_layer",
-    executable = ":takeover",
-    visibility = ["//visibility:public"],
-)
diff --git a/cloud/agent/takeover/e2e/BUILD.bazel b/cloud/agent/takeover/e2e/BUILD.bazel
index 7259fc5..3ca92ee 100644
--- a/cloud/agent/takeover/e2e/BUILD.bazel
+++ b/cloud/agent/takeover/e2e/BUILD.bazel
@@ -4,6 +4,7 @@
     name = "e2e_test",
     srcs = ["main_test.go"],
     data = [
+        # We use the layer instead of the binary to not add a transition target
         "//cloud/agent/takeover",
         "//third_party/edk2:OVMF_CODE.fd",
         "//third_party/edk2:OVMF_VARS.fd",
@@ -13,7 +14,8 @@
         "xCloudImagePath": "$(rlocationpath @debian_11_cloudimage//file )",
         "xOvmfVarsPath": "$(rlocationpath //third_party/edk2:OVMF_VARS.fd )",
         "xOvmfCodePath": "$(rlocationpath //third_party/edk2:OVMF_CODE.fd )",
-        "xTakeoverPath": "$(rlocationpath //cloud/agent/takeover )",
+        # TODO(tim): Hardcoded because of https://github.com/monogon-dev/monogon/issues/316
+        "xTakeoverPath": "_main/cloud/agent/takeover/takeover_bin_/takeover_bin",
     },
     deps = [
         "//cloud/agent/api",
diff --git a/cloud/agent/takeover/e2e/main_test.go b/cloud/agent/takeover/e2e/main_test.go
index 0521cc9..b141e63 100644
--- a/cloud/agent/takeover/e2e/main_test.go
+++ b/cloud/agent/takeover/e2e/main_test.go
@@ -174,6 +174,7 @@
 		t.Fatal(err)
 	}
 	defer takeoverSrcFile.Close()
+
 	if _, err := io.Copy(takeoverFile, takeoverSrcFile); err != nil {
 		t.Fatal(err)
 	}