aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/testdata/script/gcflags_patterns.txt
blob: e9521c2fb27a11142c2474883b873e7077ee95e0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
env GO111MODULE=off

[!gc] skip 'using -gcflags and -ldflags'
[short] skip

env GOCACHE=$WORK/gocache  # Looking for compile commands, so need a clean cache.

# -gcflags=-e applies to named packages, not dependencies
go build -n -v -gcflags=-e z1 z2
stderr 'compile.* -p z1.* -e'
stderr 'compile.* -p z2.* -e'
stderr 'compile.* -p y'
! stderr 'compile.* -p [^z].* -e'

# -gcflags can specify package=flags, and can be repeated; last match wins
go build -n -v -gcflags=-e -gcflags=z1=-N z1 z2
stderr 'compile.* -p z1.* -N'
! stderr 'compile.* -p z1.* -e'
! stderr 'compile.* -p z2.* -N'
stderr 'compile.* -p z2.* -e'
stderr 'compile.* -p y'
! stderr 'compile.* -p [^z].* -e'
! stderr 'compile.* -p [^z].* -N'

# -gcflags can have arbitrary spaces around the flags
go build -n -v -gcflags='  z1 =  	-e 	' z1
stderr 'compile.* -p z1.* -e'

# -gcflags='all=-e' should apply to all packages, even with go test
go test -c -n -gcflags='all=-e' z1
stderr 'compile.* -p z3.* -e '

# this particular -gcflags argument made the compiler crash
! go build -gcflags=-d=ssa/ z1
stderr 'PhaseOptions usage'

# -ldflags for implicit test package applies to test binary
go test -c -n -gcflags=-N -ldflags=-X=x.y=z z1
stderr 'compile.* -N .*z_test.go'
stderr 'link.* -X=x.y=z'

# -ldflags for explicit test package applies to test binary
go test -c -n -gcflags=z1=-N -ldflags=z1=-X=x.y=z z1
stderr 'compile.* -N .*z_test.go'
stderr 'link.* -X=x.y=z'

# -ldflags applies to link of command
go build -n -ldflags=-X=math.pi=3 my/cmd/prog
stderr 'link.* -X=math.pi=3'

# -ldflags applies to link of command even with strange directory name
go build -n -ldflags=-X=math.pi=3 my/cmd/prog/
stderr 'link.* -X=math.pi=3'

# -ldflags applies to current directory
cd my/cmd/prog
go build -n -ldflags=-X=math.pi=3
stderr 'link.* -X=math.pi=3'

# -ldflags applies to current directory even if GOPATH is funny
[windows] cd $WORK/GoPath/src/my/cmd/prog
[darwin] cd $WORK/GoPath/src/my/cmd/prog
go build -n -ldflags=-X=math.pi=3
stderr 'link.* -X=math.pi=3'

# cgo.a should not be a dependency of internally-linked go package
go build -ldflags='-linkmode=external -linkmode=internal' -n prog.go
! stderr 'packagefile .*runtime/cgo.a'

-- z1/z.go --
package z1
import _ "y"
import _ "z2"

-- z1/z_test.go --
package z1_test
import "testing"
import _ "z3"
func Test(t *testing.T) {}

-- z2/z.go --
package z2

-- z3/z.go --
package z3

-- y/y.go --
package y

-- my/cmd/prog/prog.go --
package main
func main() {}