Skip to content

Commit

Permalink
cmd/go/internal/cache: disable builds if GOCACHE is not an absolute path
Browse files Browse the repository at this point in the history
If GOCACHE is set but is not an absolute path, we cannot build.
And GOCACHE=off also returns the error message "build cache is
disabled by GOCACHE=off".

Fixes #30447

Change-Id: I24f64bc886599ca0acd757acada4714aebe4d3ae
Reviewed-on: https://go-review.googlesource.com/c/164200
Run-TryBot: Baokun Lee <[email protected]>
Run-TryBot: Bryan C. Mills <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
Reviewed-by: Bryan C. Mills <[email protected]>
  • Loading branch information
oiooj authored and Bryan C. Mills committed Mar 1, 2019
1 parent db2b6e1 commit 13d24b6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/cmd/go/internal/cache/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ See golang.org to learn more about Go.
// the first time Default is called.
func initDefaultCache() {
dir := DefaultDir()
if dir == "off" || dir == "" {
if dir == "off" {
if defaultDirErr != nil {
base.Fatalf("build cache is required, but could not be located: %v", defaultDirErr)
}
Expand Down Expand Up @@ -74,7 +74,12 @@ func DefaultDir() string {

defaultDirOnce.Do(func() {
defaultDir = os.Getenv("GOCACHE")
if filepath.IsAbs(defaultDir) || defaultDir == "off" {
return
}
if defaultDir != "" {
defaultDir = "off"
defaultDirErr = fmt.Errorf("GOCACHE is not an absolute path")
return
}

Expand Down
5 changes: 5 additions & 0 deletions src/cmd/go/testdata/script/build_nocache.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ env HOME=
! go build -o triv triv.go
stderr 'build cache is required, but could not be located: GOCACHE is not defined and .*'

# If GOCACHE is set but is not an absolute path, and we cannot build.
env GOCACHE=test
! go build -o triv triv.go
stderr 'build cache is required, but could not be located: GOCACHE is not an absolute path'

# An explicit GOCACHE=off also disables builds.
env GOCACHE=off
! go build -o triv triv.go
Expand Down

0 comments on commit 13d24b6

Please sign in to comment.