1
0
mirror of https://github.com/golang/go synced 2024-11-08 18:46:16 -07:00

cmd/go: make sure CC and CXX are absolute

Add check in cmd/go/internal/work.BuildInit and
cmd/go/internal/envcmd.checkEnvWrite.

Fixes #38372

Change-Id: I196ea93a0469e4667ef785f7c1dc4574bdf7ff78
Reviewed-on: https://go-review.googlesource.com/c/go/+/228517
Run-TryBot: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Jay Conrod <jayconrod@google.com>
Trust: Jay Conrod <jayconrod@google.com>
Trust: Michael Matloob <matloob@golang.org>
This commit is contained in:
Obeyda Djeffal 2020-04-16 12:45:37 +01:00 committed by Jay Conrod
parent 8cd75f3da0
commit aa161e799d
3 changed files with 36 additions and 0 deletions

View File

@ -424,6 +424,11 @@ func checkEnvWrite(key, val string) error {
if !filepath.IsAbs(val) && val != "" { if !filepath.IsAbs(val) && val != "" {
return fmt.Errorf("GOPATH entry is relative; must be absolute path: %q", val) return fmt.Errorf("GOPATH entry is relative; must be absolute path: %q", val)
} }
// Make sure CC and CXX are absolute paths
case "CC", "CXX":
if !filepath.IsAbs(val) && val != "" && val != filepath.Base(val) {
return fmt.Errorf("%s entry is relative; must be absolute path: %q", key, val)
}
} }
if !utf8.ValidString(val) { if !utf8.ValidString(val) {

View File

@ -41,6 +41,13 @@ func BuildInit() {
cfg.BuildPkgdir = p cfg.BuildPkgdir = p
} }
// Make sure CC and CXX are absolute paths
for _, key := range []string{"CC", "CXX"} {
if path := cfg.Getenv(key); !filepath.IsAbs(path) && path != "" && path != filepath.Base(path) {
base.Fatalf("go %s: %s environment variable is relative; must be absolute path: %s\n", flag.Args()[0], key, path)
}
}
// For each experiment that has been enabled in the toolchain, define a // For each experiment that has been enabled in the toolchain, define a
// build tag with the same name but prefixed by "goexperiment." which can be // build tag with the same name but prefixed by "goexperiment." which can be
// used for compiling alternative files for the experiment. This allows // used for compiling alternative files for the experiment. This allows

View File

@ -123,6 +123,30 @@ go env -w GOTMPDIR=
go env GOTMPDIR go env GOTMPDIR
stdout ^$ stdout ^$
# go env -w rejects relative CC values
[!windows] go env -w CC=/usr/bin/clang
go env -w CC=clang
[!windows] ! go env -w CC=./clang
[!windows] ! go env -w CC=bin/clang
[!windows] stderr 'go env -w: CC entry is relative; must be absolute path'
[windows] go env -w CC=$WORK\bin\clang
[windows] ! go env -w CC=.\clang
[windows] ! go env -w CC=bin\clang
[windows] stderr 'go env -w: CC entry is relative; must be absolute path'
# go env -w rejects relative CXX values
[!windows] go env -w CC=/usr/bin/cpp
go env -w CXX=cpp
[!windows] ! go env -w CXX=./cpp
[!windows] ! go env -w CXX=bin/cpp
[!windows] stderr 'go env -w: CXX entry is relative; must be absolute path'
[windows] go env -w CXX=$WORK\bin\cpp
[windows] ! go env -w CXX=.\cpp
[windows] ! go env -w CXX=bin\cpp
[windows] stderr 'go env -w: CXX entry is relative; must be absolute path'
# go env -w/-u checks validity of GOOS/ARCH combinations # go env -w/-u checks validity of GOOS/ARCH combinations
env GOOS= env GOOS=
env GOARCH= env GOARCH=