From a1e6eeeb44d954a9a6413ea2d956a97d13c31f68 Mon Sep 17 00:00:00 2001 From: Dan Willemsen Date: Fri, 2 Mar 2018 14:54:17 -0800 Subject: [PATCH] Try to make GOROOT relative in Go 1.10 In Go 1.10, runtime.GOROOT() will attempt to find the current location of the go binaries, instead of using the GOROOT_FINAL that was baked into the binaries. This means that GOROOT() will usually return an absolute path. We avoid putting absolute paths into the ninja file, since any change to the paths would then cause all of the actions including it to rebuild. Since we've got a decent number of build tools in Android using Go now, this causes us to rebuild a decent portion of the tree. Instead of passing the GOROOT around manually in a side channel, just let the Go 1.10 detection do its thing, and always try to turn the result into a relative path. --- bootstrap/config.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/bootstrap/config.go b/bootstrap/config.go index 3aa97a5..5785ea7 100644 --- a/bootstrap/config.go +++ b/bootstrap/config.go @@ -15,7 +15,10 @@ package bootstrap import ( + "os" + "path/filepath" "runtime" + "strings" "github.com/google/blueprint" ) @@ -39,7 +42,16 @@ var ( return NinjaBuildDir }) goRoot = bootstrapVariable("goRoot", func() string { - return runtime.GOROOT() + goroot := runtime.GOROOT() + // Prefer to omit absolute paths from the ninja file + if cwd, err := os.Getwd(); err == nil { + if relpath, err := filepath.Rel(cwd, goroot); err == nil { + if !strings.HasPrefix(relpath, "../") { + goroot = relpath + } + } + } + return goroot }) compileCmd = bootstrapVariable("compileCmd", func() string { return "$goRoot/pkg/tool/" + runtime.GOOS + "_" + runtime.GOARCH + "/compile" -- GitLab