From 93f5ed019a89ea041a98cb485378851c9ce939c1 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 12 Aug 2021 12:22:40 -0700 Subject: [PATCH] depaware: use go toolchain that depaware was compiled with Fixes tailscale/corp#2376 Signed-off-by: Josh Bleecher Snyder --- depaware/depaware.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/depaware/depaware.go b/depaware/depaware.go index 6c0e2fe..4914e1c 100644 --- a/depaware/depaware.go +++ b/depaware/depaware.go @@ -18,6 +18,7 @@ import ( "log" "os" "path/filepath" + "runtime" "sort" "strings" "unicode" @@ -39,6 +40,7 @@ func Main() { if *check && *update { log.Fatalf("-check and -update can't be used together") } + setGoBinaryPath() ipaths, err := pkgPaths(flag.Args()...) if err != nil { @@ -305,3 +307,11 @@ func parsePreferredWhy(r io.Reader) map[string]string { } return m } + +// setGoBinaryPath makes the go binary executed by go/packages +// match the go binary that depaware was compiled with. +func setGoBinaryPath() { + binDir := filepath.Join(runtime.GOROOT(), "bin") + pathEnv := fmt.Sprintf("%s%c%s", binDir, os.PathListSeparator, os.Getenv("PATH")) + os.Setenv("PATH", pathEnv) +}