treewide: replace hardcoded runfiles paths
We hardcoded some of the runfiles paths to find specific files. This replaces the hardcoded paths by a call to rlocationpath. This prevents running a target without the correct dependencies at build time instead of at runtime
Change-Id: I7ce56935ac80be6b28b824ccb0781ab401bd6521
Reviewed-on: https://review.monogon.dev/c/monogon/+/3301
Reviewed-by: Serge Bazanski <serge@monogon.tech>
Tested-by: Jenkins CI
diff --git a/metropolis/vm/smoketest/BUILD.bazel b/metropolis/vm/smoketest/BUILD.bazel
index 3c01a4a..7d075d8 100644
--- a/metropolis/vm/smoketest/BUILD.bazel
+++ b/metropolis/vm/smoketest/BUILD.bazel
@@ -4,8 +4,14 @@
go_library(
name = "smoketest_lib",
srcs = ["main.go"],
+ data = [
+ "@qemu//:qemu-x86_64-softmmu",
+ ],
importpath = "source.monogon.dev/metropolis/vm/smoketest",
visibility = ["//visibility:private"],
+ x_defs = {
+ "xQemuPath": "$(rlocationpath @qemu//:qemu-x86_64-softmmu )",
+ },
deps = ["@io_bazel_rules_go//go/runfiles:go_default_library"],
)
@@ -21,11 +27,6 @@
go_binary(
name = "smoketest",
- data = [
- ":initramfs",
- "//osbase/test/ktest:linux-testing",
- "@qemu//:qemu-x86_64-softmmu",
- ],
embed = [":smoketest_lib"],
pure = "on",
visibility = ["//visibility:private"],
diff --git a/metropolis/vm/smoketest/main.go b/metropolis/vm/smoketest/main.go
index 3f0b8ca..58f1a22 100644
--- a/metropolis/vm/smoketest/main.go
+++ b/metropolis/vm/smoketest/main.go
@@ -25,10 +25,30 @@
"net"
"os"
"os/exec"
+ "path/filepath"
"github.com/bazelbuild/rules_go/go/runfiles"
)
+var (
+ // These are filled by bazel at linking time with the canonical path of
+ // their corresponding file. Inside the init function we resolve it
+ // with the rules_go runfiles package to the real path.
+ xQemuPath string
+)
+
+func init() {
+ var err error
+ for _, path := range []*string{
+ &xQemuPath,
+ } {
+ *path, err = runfiles.Rlocation(*path)
+ if err != nil {
+ panic(err)
+ }
+ }
+}
+
func main() {
testSocket, err := net.Listen("unix", "@metropolis/vm/smoketest")
if err != nil {
@@ -49,17 +69,9 @@
}
}()
- qemuPath, err := runfiles.Rlocation("qemu/qemu-x86_64-softmmu")
- if err != nil {
- panic(err)
- }
-
// TODO(lorenz): This explicitly doesn't use our own qboot because it cannot be built in a musl configuration.
// This will be fixed once we have a proper multi-target toolchain.
- biosPath, err := runfiles.Rlocation("qemu/pc-bios/qboot.rom")
- if err != nil {
- panic(err)
- }
+ biosPath := filepath.Join(filepath.Dir(xQemuPath), "pc-bios/qboot.rom")
baseArgs := []string{"-nodefaults", "-no-user-config", "-nographic", "-no-reboot",
"-accel", "kvm", "-cpu", "host",
@@ -74,7 +86,7 @@
"-chardev", "socket,id=test,path=metropolis/vm/smoketest,abstract=on",
"-device", "virtserialport,chardev=test",
}
- qemuCmd := exec.Command(qemuPath, baseArgs...)
+ qemuCmd := exec.Command(xQemuPath, baseArgs...)
qemuCmd.Stdout = os.Stdout
qemuCmd.Stderr = os.Stderr
if err := qemuCmd.Run(); err != nil {