treewide: remove direct access to external/
This prepares the repositoriy to be compatible with the flag
--nolegacy_external_runfiles. This reduces runfiles & sandbox creation
times.
Change-Id: I06720be4a3c873d68d8278dcb24271ed874f7134
Reviewed-on: https://review.monogon.dev/c/monogon/+/2747
Tested-by: Jenkins CI
Reviewed-by: Lorenz Brun <lorenz@monogon.tech>
diff --git a/build/toolbase/gotoolchain/BUILD.bazel b/build/toolbase/gotoolchain/BUILD.bazel
index 42dc877..1842398 100644
--- a/build/toolbase/gotoolchain/BUILD.bazel
+++ b/build/toolbase/gotoolchain/BUILD.bazel
@@ -6,7 +6,7 @@
importpath = "source.monogon.dev/build/toolbase/gotoolchain",
visibility = ["//visibility:public"],
deps = [
- "@io_bazel_rules_go//go/tools/bazel:go_default_library",
+ "@io_bazel_rules_go//go/runfiles:go_default_library",
],
)
diff --git a/build/toolbase/gotoolchain/toolchain.go.in b/build/toolbase/gotoolchain/toolchain.go.in
index 2989f21..4923e67 100644
--- a/build/toolbase/gotoolchain/toolchain.go.in
+++ b/build/toolbase/gotoolchain/toolchain.go.in
@@ -4,37 +4,24 @@
import (
"fmt"
- "os"
+ "path/filepath"
"strings"
- "github.com/bazelbuild/rules_go/go/tools/bazel"
+ "github.com/bazelbuild/rules_go/go/runfiles"
)
func mustRunfile(s string) string {
- // When running as a tool (in a genrule, or a test, etc.), bazel.Runfile
- // does not work. However, ${0}.runfiles/$runfile should be present. If so,
- // return early and return that. Otherwise, carry on with bazel.Runfile.
- //
- // TODO(q3k): dig deeper into this and unify with //metropolis/cli/pkg/datafile.
-
- // Ignore the error, worst case we get an empty string that will make a
- // garbage path that won't point to a file.
- ex, _ := os.Executable()
- rf := ex + ".runfiles"
- if _, err := os.Stat(rf); err == nil {
- parts := strings.Split(s, "/")
- parts[0] = rf
- rf = strings.Join(parts, "/")
- if _, err := os.Stat(rf); err == nil {
- return rf
- }
- }
-
- res, err := bazel.Runfile(s)
+ // TODO(tim): I couldn't find out why there is a prefix.
+ s = strings.TrimPrefix(s, "external/")
+ res, err := runfiles.Rlocation(s)
if err != nil {
panic(fmt.Sprintf("runfile %q not found: %v", s, err))
}
- return res
+ abs, err := filepath.Abs(res)
+ if err != nil {
+ panic(fmt.Sprintf("cant make runfile %q absolute: %v", s, err))
+ }
+ return abs
}
var (