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

     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.* -p z1.* -e '
    11  stderr 'compile.* -p z2.* -e '
    12  stderr 'compile.* -p y'
    13  ! stderr 'compile.* -p [^z].* -e '
    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.* -p z1.* -N '
    18  ! stderr 'compile.* -p z1.* -e '
    19  ! stderr 'compile.* -p z2.* -N '
    20  stderr 'compile.* -p z2.* -e '
    21  stderr 'compile.* -p y'
    22  ! stderr 'compile.* -p [^z].* -e '
    23  ! stderr 'compile.* -p [^z].* -N '
    24  
    25  # -gcflags can have arbitrary spaces around the flags
    26  go build -n -v -gcflags='  z1 =  	-e 	' z1
    27  stderr 'compile.* -p z1.* -e '
    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.* -p z3.* -e '
    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  [!case-sensitive] cd $WORK/GoPath/src/my/cmd/prog
    62  go build -n -ldflags=-X=math.pi=3
    63  stderr 'link.* -X=math.pi=3'
    64  
    65  # cgo.a should not be a dependency of internally-linked go package
    66  go build -ldflags='-linkmode=external -linkmode=internal' -n prog.go
    67  ! stderr 'packagefile .*runtime/cgo.a'
    68  
    69  -- z1/z.go --
    70  package z1
    71  import _ "y"
    72  import _ "z2"
    73  
    74  -- z1/z_test.go --
    75  package z1_test
    76  import "testing"
    77  import _ "z3"
    78  func Test(t *testing.T) {}
    79  
    80  -- z2/z.go --
    81  package z2
    82  
    83  -- z3/z.go --
    84  package z3
    85  
    86  -- y/y.go --
    87  package y
    88  
    89  -- my/cmd/prog/prog.go --
    90  package main
    91  func main() {}
    92  

View as plain text