|
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 |
| 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' |
19 | 18 |
|
20 | 19 | # A binary from an external module built with -trimpath should not contain
|
21 | 20 | # the current workspace or GOROOT.
|
22 | 21 | cd $WORK
|
23 |
| -env GO111MODULE=on |
24 | 22 | go get -trimpath rsc.io/fortune
|
25 |
| -! grep -q $GOROOT_REGEXP $GOPATH/bin/fortune$GOEXE |
26 |
| -! grep -q $WORK_REGEXP $GOPATH/bin/fortune$GOEXE |
| 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 |
| -cd $GOPATH/src/a |
31 |
| -go build -trimpath -o $WORK/a-GOPATH.exe . |
32 |
| -cd $WORK/_alt/src/a |
33 |
| -go build -trimpath -o $WORK/a-alt.exe . |
34 |
| -cmp -q $WORK/a-GOPATH.exe $WORK/a-alt.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 |
35 | 36 |
|
36 | 37 | [!exec:gccgo] stop
|
37 | 38 |
|
38 |
| -# Binaries built using gccgo should also be identical to each other. |
| 39 | +# A binary built with gccgo without -trimpath should contain the current |
| 40 | +# GOPATH and GOROOT. |
39 | 41 | env GO111MODULE=off # The current released gccgo does not support builds in module mode.
|
40 | 42 | cd $GOPATH/src/a
|
41 |
| -go build -compiler=gccgo -trimpath -o $WORK/gccgo-GOPATH.exe . |
| 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' |
42 | 47 |
|
43 |
| -env old_gopath=$GOPATH |
44 |
| -env GOPATH=$WORK/_alt |
45 |
| -cd $WORK/_alt/src/a |
46 |
| -go build -compiler=gccgo -trimpath -o $WORK/gccgo-alt.exe . |
47 |
| -cd $WORK |
48 |
| -! grep -q $GOROOT_REGEXP gccgo-GOPATH.exe |
49 |
| -! grep -q $WORK_REGEXP gccgo-GOPATH.exe |
50 |
| -cmp -q gccgo-GOPATH.exe gccgo-alt.exe |
| 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' |
| 53 | + |
| 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 |
51 | 60 |
|
52 |
| --- $GOPATH/src/a/hello.go -- |
| 61 | +-- $GOPATH/src/a/paths.go -- |
53 | 62 | package main
|
54 |
| -func main() { println("hello") } |
| 63 | + |
| 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 | +} |
55 | 92 | -- $GOPATH/src/a/go.mod --
|
56 | 93 | module example.com/a
|
57 |
| --- $WORK/_alt/src/a/hello.go -- |
58 |
| -package main |
59 |
| -func main() { println("hello") } |
60 |
| --- $WORK/_alt/src/a/go.mod -- |
61 |
| -module example.com/a |
|
0 commit comments