github.com/gagliardetto/golang-go@v0.0.0-20201020153340-53909ea70814/cmd/go/testdata/script/gcflags_patterns.txt (about) 1 env GO111MODULE=off 2 3 [!gc] skip 'using -gcflags and -ldflags' 4 [short] skip 5 6 # -gcflags=-e applies to named packages, not dependencies 7 go build -n -v -gcflags=-e z1 z2 8 stderr 'compile.* -e.* -p z1' 9 stderr 'compile.* -e.* -p z2' 10 stderr 'compile.* -p y' 11 ! stderr 'compile.* -e.* -p [^z]' 12 13 # -gcflags can specify package=flags, and can be repeated; last match wins 14 go build -n -v -gcflags=-e -gcflags=z1=-N z1 z2 15 stderr 'compile.* -N.* -p z1' 16 ! stderr 'compile.* -e.* -p z1' 17 ! stderr 'compile.* -N.* -p z2' 18 stderr 'compile.* -e.* -p z2' 19 stderr 'compile.* -p y' 20 ! stderr 'compile.* -e.* -p [^z]' 21 ! stderr 'compile.* -N.* -p [^z]' 22 23 # -gcflags can have arbitrary spaces around the flags 24 go build -n -v -gcflags=' z1 = -e ' z1 25 stderr 'compile.* -e.* -p z1' 26 27 # -gcflags='all=-e' should apply to all packages, even with go test 28 go test -c -n -gcflags='all=-e' z1 29 stderr 'compile.* -e.* -p z3 ' 30 31 # this particular -gcflags argument made the compiler crash 32 ! go build -gcflags=-d=ssa/ z1 33 stderr 'PhaseOptions usage' 34 35 # -ldflags for implicit test package applies to test binary 36 go test -c -n -gcflags=-N -ldflags=-X=x.y=z z1 37 stderr 'compile.* -N .*z_test.go' 38 stderr 'link.* -X=x.y=z' 39 40 # -ldflags for explicit test package applies to test binary 41 go test -c -n -gcflags=z1=-N -ldflags=z1=-X=x.y=z z1 42 stderr 'compile.* -N .*z_test.go' 43 stderr 'link.* -X=x.y=z' 44 45 # -ldflags applies to link of command 46 go build -n -ldflags=-X=math.pi=3 my/cmd/prog 47 stderr 'link.* -X=math.pi=3' 48 49 # -ldflags applies to link of command even with strange directory name 50 go build -n -ldflags=-X=math.pi=3 my/cmd/prog/ 51 stderr 'link.* -X=math.pi=3' 52 53 # -ldflags applies to current directory 54 cd my/cmd/prog 55 go build -n -ldflags=-X=math.pi=3 56 stderr 'link.* -X=math.pi=3' 57 58 # -ldflags applies to current directory even if GOPATH is funny 59 [windows] cd $WORK/GoPath/src/my/cmd/prog 60 [darwin] cd $WORK/GoPath/src/my/cmd/prog 61 go build -n -ldflags=-X=math.pi=3 62 stderr 'link.* -X=math.pi=3' 63 64 -- z1/z.go -- 65 package z1 66 import _ "y" 67 import _ "z2" 68 69 -- z1/z_test.go -- 70 package z1_test 71 import "testing" 72 import _ "z3" 73 func Test(t *testing.T) {} 74 75 -- z2/z.go -- 76 package z2 77 78 -- z3/z.go -- 79 package z3 80 81 -- y/y.go -- 82 package y 83 84 -- my/cmd/prog/prog.go -- 85 package main 86 func main() {}