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

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

View as plain text