File tree 4 files changed +27
-3
lines changed
4 files changed +27
-3
lines changed Original file line number Diff line number Diff line change @@ -370,7 +370,10 @@ func findGOROOT() string {
370
370
if env := Getenv ("GOROOT" ); env != "" {
371
371
return filepath .Clean (env )
372
372
}
373
- def := filepath .Clean (runtime .GOROOT ())
373
+ def := ""
374
+ if r := runtime .GOROOT (); r != "" {
375
+ def = filepath .Clean (r )
376
+ }
374
377
if runtime .Compiler == "gccgo" {
375
378
// gccgo has no real GOROOT, and it certainly doesn't
376
379
// depend on the executable's location.
Original file line number Diff line number Diff line change @@ -142,6 +142,10 @@ func main() {
142
142
}
143
143
}
144
144
145
+ if cfg .GOROOT == "" {
146
+ fmt .Fprintf (os .Stderr , "go: cannot find GOROOT directory: 'go' binary is trimmed and GOROOT is not set\n " )
147
+ os .Exit (2 )
148
+ }
145
149
if fi , err := os .Stat (cfg .GOROOT ); err != nil || ! fi .IsDir () {
146
150
fmt .Fprintf (os .Stderr , "go: cannot find GOROOT directory: %v\n " , cfg .GOROOT )
147
151
os .Exit (2 )
Original file line number Diff line number Diff line change @@ -22,6 +22,7 @@ import (
22
22
"path/filepath"
23
23
"regexp"
24
24
"runtime"
25
+ "runtime/debug"
25
26
"strconv"
26
27
"strings"
27
28
"sync"
@@ -373,6 +374,17 @@ Script:
373
374
ok = testenv .HasSymlink ()
374
375
case "case-sensitive" :
375
376
ok = isCaseSensitive (ts .t )
377
+ case "trimpath" :
378
+ if info , _ := debug .ReadBuildInfo (); info == nil {
379
+ ts .fatalf ("missing build info" )
380
+ } else {
381
+ for _ , s := range info .Settings {
382
+ if s .Key == "-trimpath" && s .Value == "true" {
383
+ ok = true
384
+ break
385
+ }
386
+ }
387
+ }
376
388
default :
377
389
if strings .HasPrefix (cond .tag , "exec:" ) {
378
390
prog := cond .tag [len ("exec:" ):]
Original file line number Diff line number Diff line change 8
8
# TODO(#51483): when runtime.GOROOT() returns the empty string,
9
9
# go/build should default to 'go env GOROOT' instead.
10
10
11
- [short] skip
12
-
13
11
env GOROOT=
14
12
env GOROOT_FINAL=
15
13
14
+ [trimpath] ! go env GOROOT
15
+ [trimpath] stderr '^go: cannot find GOROOT directory: ''go'' binary is trimmed and GOROOT is not set$'
16
+ [trimpath] stop
17
+
18
+
19
+ [short] skip
20
+
16
21
go run .
17
22
stdout '^GOROOT '$TESTGO_GOROOT'$'
18
23
stdout '^runtime '$TESTGO_GOROOT${/}src${/}runtime'$'
You can’t perform that action at this time.
0 commit comments