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/test/launch/swtpm.go b/metropolis/test/launch/swtpm.go
index fa5cb78..5691c86 100644
--- a/metropolis/test/launch/swtpm.go
+++ b/metropolis/test/launch/swtpm.go
@@ -10,8 +10,6 @@
"sort"
"strings"
- "github.com/bazelbuild/rules_go/go/runfiles"
-
"source.monogon.dev/osbase/test/launch"
)
@@ -111,29 +109,6 @@
launch.Log("Skipping manufacturing TPM for %s, already exists", path)
return nil
}
-
- // Find all tools.
- swtpm, err := runfiles.Rlocation("swtpm/swtpm")
- if err != nil {
- return fmt.Errorf("could not find swtpm: %w", err)
- }
- swtpmSetup, err := runfiles.Rlocation("swtpm/swtpm_setup")
- if err != nil {
- return fmt.Errorf("could not find swtpm_setup: %w", err)
- }
- swtpmLocalca, err := runfiles.Rlocation("swtpm/swtpm_localca")
- if err != nil {
- return fmt.Errorf("could not find swtpm_localca: %w", err)
- }
- swtpmCert, err := runfiles.Rlocation("_main/metropolis/test/swtpm/swtpm_cert/swtpm_cert_/swtpm_cert")
- if err != nil {
- return fmt.Errorf("could not find swtpm_cert: %w", err)
- }
- certtool, err := runfiles.Rlocation("_main/metropolis/test/swtpm/certtool/certtool_/certtool")
- if err != nil {
- return fmt.Errorf("could not find certtool: %w", err)
- }
-
// Prepare swtpm-localca.options.
options := []string{
"--platform-manufacturer " + platform.Manufacturer,
@@ -141,14 +116,14 @@
"--platform-model " + platform.Model,
"",
}
- err = os.WriteFile(f.localCAOptionsPath(), []byte(strings.Join(options, "\n")), 0600)
+ err := os.WriteFile(f.localCAOptionsPath(), []byte(strings.Join(options, "\n")), 0600)
if err != nil {
return fmt.Errorf("could not write local options: %w", err)
}
// Prepare swptm.conf.
err = writeSWTPMConfig(f.swtpmConfPath(), map[string]string{
- "create_certs_tool": swtpmLocalca,
+ "create_certs_tool": xSwtpmLocalCAPath,
"create_certs_tool_config": f.localCAConfPath(),
"create_certs_tool_options": f.localCAOptionsPath(),
})
@@ -159,8 +134,8 @@
if err := os.MkdirAll(path, 0700); err != nil {
return fmt.Errorf("could not make output path: %w", err)
}
- cmd := exec.CommandContext(ctx, swtpmSetup,
- "--tpm", fmt.Sprintf("%s socket", swtpm),
+ cmd := exec.CommandContext(ctx, xSwtpmSetupPath,
+ "--tpm", fmt.Sprintf("%s socket", xSwtpmPath),
"--tpmstate", path,
"--create-ek-cert",
"--create-platform-cert",
@@ -169,7 +144,7 @@
"--display",
"--pcr-banks", "sha1,sha256,sha384,sha512",
"--config", f.swtpmConfPath())
- cmd.Env = append(cmd.Env, fmt.Sprintf("PATH=%s:%s", filepath.Dir(swtpmCert), filepath.Dir(certtool)))
+ cmd.Env = append(cmd.Env, fmt.Sprintf("PATH=%s:%s", filepath.Dir(xSwtpmCertPath), filepath.Dir(xCerttoolPath)))
cmd.Env = append(cmd.Env, "MONOGON_LIBTPMS_ACKNOWLEDGE_UNSAFE=yes")
if out, err := cmd.CombinedOutput(); err != nil {
log.Printf("Manufacturing TPM for %s failed: swtm_setup: %s", path, out)