|
1 | 1 | [short] skip
|
2 |
| - |
3 |
| -env -r GOROOT_REGEXP=$GOROOT |
4 |
| -env -r WORK_REGEXP='$WORK' # don't expand $WORK; grep replaces $WORK in text before matching. |
5 |
| -env GOROOT GOROOT_REGEXP WORK WORK_REGEXP |
| 2 | +env GO111MODULE=on |
6 | 3 |
|
7 | 4 | # A binary built without -trimpath should contain the current workspace
|
8 | 5 | # and GOROOT for debugging and stack traces.
|
9 | 6 | cd a
|
10 |
| -go build -o hello.exe hello.go |
11 |
| -grep -q $WORK_REGEXP hello.exe |
12 |
| -grep -q $GOROOT_REGEXP hello.exe |
| 7 | +go build -o $WORK/paths-a.exe paths.go |
| 8 | +exec $WORK/paths-a.exe $WORK/paths-a.exe |
| 9 | +stdout 'binary contains GOPATH: true' |
| 10 | +stdout 'binary contains GOROOT: true' |
13 | 11 |
|
14 | 12 | # A binary built with -trimpath should not contain the current workspace
|
15 | 13 | # or GOROOT.
|
16 |
| -go build -trimpath -o hello.exe hello.go |
17 |
| -! grep -q $GOROOT_REGEXP hello.exe |
18 |
| -! grep -q $WORK_REGEXP hello.exe |
19 |
| -cd .. |
| 14 | +go build -trimpath -o $WORK/paths-a.exe paths.go |
| 15 | +exec $WORK/paths-a.exe $WORK/paths-a.exe |
| 16 | +stdout 'binary contains GOPATH: false' |
| 17 | +stdout 'binary contains GOROOT: false' |
20 | 18 |
|
21 | 19 | # A binary from an external module built with -trimpath should not contain
|
22 | 20 | # the current workspace or GOROOT.
|
23 |
| -env GO111MODULE=on |
24 |
| -go build -trimpath -o fortune.exe rsc.io/fortune |
25 |
| -! grep -q $GOROOT_REGEXP fortune.exe |
26 |
| -! grep -q $WORK_REGEXP fortune.exe |
| 21 | +cd $WORK |
| 22 | +go get -trimpath rsc.io/fortune |
| 23 | +exec $WORK/paths-a.exe $GOPATH/bin/fortune$GOEXE |
| 24 | +stdout 'binary contains GOPATH: false' |
| 25 | +stdout 'binary contains GOROOT: false' |
27 | 26 |
|
28 | 27 | # Two binaries built from identical packages in different directories
|
29 | 28 | # should be identical.
|
30 |
| -mkdir b |
31 |
| -cp a/go.mod a/hello.go b |
32 |
| -cd a |
33 |
| -go build -trimpath -o ../a.exe . |
34 |
| -cd ../b |
35 |
| -go build -trimpath -o ../b.exe . |
36 |
| -cd .. |
37 |
| -cmp -q a.exe b.exe |
| 29 | +# TODO(golang.org/issue/35435): at the moment, they are not. |
| 30 | +#mkdir $GOPATH/src/b |
| 31 | +#cp $GOPATH/src/a/go.mod $GOPATH/src/b/go.mod |
| 32 | +#cp $GOPATH/src/a/paths.go $GOPATH/src/b/paths.go |
| 33 | +#cd $GOPATH/src/b |
| 34 | +#go build -trimpath -o $WORK/paths-b.exe . |
| 35 | +#cmp -q $WORK/paths-a.exe $WORK/paths-b.exe |
| 36 | + |
| 37 | +[!exec:gccgo] stop |
| 38 | + |
| 39 | +# A binary built with gccgo without -trimpath should contain the current |
| 40 | +# GOPATH and GOROOT. |
| 41 | +env GO111MODULE=off # The current released gccgo does not support builds in module mode. |
| 42 | +cd $GOPATH/src/a |
| 43 | +go build -compiler=gccgo -o $WORK/gccgo-paths-a.exe . |
| 44 | +exec $WORK/gccgo-paths-a.exe $WORK/gccgo-paths-b.exe |
| 45 | +stdout 'binary contains GOPATH: true' |
| 46 | +stdout 'binary contains GOROOT: true' |
| 47 | + |
| 48 | +# A binary built with gccgo with -trimpath should not contain GOPATH or GOROOT. |
| 49 | +go build -compiler=gccgo -trimpath -o $WORK/gccgo-paths-a.exe . |
| 50 | +exec $WORK/gccgo-paths-a.exe $WORK/gccgo-paths-b.exe |
| 51 | +stdout 'binary contains GOPATH: false' |
| 52 | +stdout 'binary contains GOROOT: false' |
38 | 53 |
|
39 |
| --- a/hello.go -- |
| 54 | +# Two binaries built from identical packages in different directories |
| 55 | +# should be identical. |
| 56 | +# TODO(golang.org/issue/35435): at the moment, they are not. |
| 57 | +#cd ../b |
| 58 | +#go build -compiler=gccgo -trimpath -o $WORK/gccgo-paths-b.exe . |
| 59 | +#cmp -q $WORK/gccgo-paths-a.exe $WORK/gccgo-paths-b.exe |
| 60 | + |
| 61 | +-- $GOPATH/src/a/paths.go -- |
40 | 62 | package main
|
41 |
| -func main() { println("hello") } |
42 | 63 |
|
43 |
| --- a/go.mod -- |
44 |
| -module m |
| 64 | +import ( |
| 65 | + "bytes" |
| 66 | + "fmt" |
| 67 | + "io/ioutil" |
| 68 | + "log" |
| 69 | + "os" |
| 70 | + "path/filepath" |
| 71 | +) |
| 72 | + |
| 73 | +func main() { |
| 74 | + exe := os.Args[1] |
| 75 | + data, err := ioutil.ReadFile(exe) |
| 76 | + if err != nil { |
| 77 | + log.Fatal(err) |
| 78 | + } |
| 79 | + |
| 80 | + gopath := []byte(filepath.ToSlash(os.Getenv("GOPATH"))) |
| 81 | + if len(gopath) == 0 { |
| 82 | + log.Fatal("GOPATH not set") |
| 83 | + } |
| 84 | + fmt.Printf("binary contains GOPATH: %v\n", bytes.Contains(data, gopath)) |
| 85 | + |
| 86 | + goroot := []byte(filepath.ToSlash(os.Getenv("GOROOT"))) |
| 87 | + if len(goroot) == 0 { |
| 88 | + log.Fatal("GOROOT not set") |
| 89 | + } |
| 90 | + fmt.Printf("binary contains GOROOT: %v\n", bytes.Contains(data, goroot)) |
| 91 | +} |
| 92 | +-- $GOPATH/src/a/go.mod -- |
| 93 | +module example.com/a |
0 commit comments