Black Lives Matter. Support the Equal Justice Initiative.

Text file src/cmd/go/testdata/script/gcflags_patterns.txt

Documentation: cmd/go/testdata/script

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

View as plain text