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

     1  [short] skip
     2  
     3  # Compiler name is always added.
     4  go build
     5  go version -m m$GOEXE
     6  stdout '^\tbuild\t-compiler=gc$'
     7  stdout '^\tbuild\tGOOS='
     8  stdout '^\tbuild\tGOARCH='
     9  [amd64] stdout '^\tbuild\tGOAMD64='
    10  ! stdout asmflags|gcflags|ldflags|gccgoflags
    11  
    12  # Toolchain flags are added if present.
    13  # The raw flags are included, with package patterns if specified.
    14  go build -asmflags=example.com/m=-D=FOO=bar
    15  go version -m m$GOEXE
    16  stdout '^\tbuild\t-asmflags=example\.com/m=-D=FOO=bar$'
    17  
    18  go build -gcflags=example.com/m=-N
    19  go version -m m$GOEXE
    20  stdout '^\tbuild\t-gcflags=example\.com/m=-N$'
    21  
    22  go build -ldflags=example.com/m=-w
    23  go version -m m$GOEXE
    24  stdout '^\tbuild\t-ldflags=example\.com/m=-w$'
    25  
    26  # gccgoflags are not added when gc is used, and vice versa.
    27  # TODO: test gccgo.
    28  go build -gccgoflags=all=UNUSED
    29  go version -m m$GOEXE
    30  ! stdout gccgoflags
    31  
    32  # Build and tool tags are added but not release tags.
    33  # "race" is included with build tags but not "cgo".
    34  go build -tags=a,b
    35  go version -m m$GOEXE
    36  stdout '^\tbuild\t-tags=a,b$'
    37  [race] go build -race
    38  [race] go version -m m$GOEXE
    39  [race] ! stdout '^\tbuild\t-tags='
    40  [race] stdout '^\tbuild\t-race=true$'
    41  
    42  # CGO flags are separate settings.
    43  # CGO_ENABLED is always present.
    44  # Other flags are added if CGO_ENABLED is true.
    45  env CGO_ENABLED=0
    46  go build
    47  go version -m m$GOEXE
    48  stdout '^\tbuild\tCGO_ENABLED=0$'
    49  ! stdout CGO_CPPFLAGS|CGO_CFLAGS|CGO_CXXFLAGS|CGO_LDFLAGS
    50  [cgo] env CGO_ENABLED=1
    51  [cgo] env CGO_CPPFLAGS=-DFROM_CPPFLAGS=1
    52  [cgo] env CGO_CFLAGS=-DFROM_CFLAGS=1
    53  [cgo] env CGO_CXXFLAGS=-DFROM_CXXFLAGS=1
    54  [cgo] env CGO_LDFLAGS=-L/extra/dir/does/not/exist
    55  [cgo] go build
    56  [cgo] go version -m m$GOEXE
    57  [cgo] stdout '^\tbuild\tCGO_ENABLED=1$'
    58  [cgo] stdout '^\tbuild\tCGO_CPPFLAGS=-DFROM_CPPFLAGS=1$'
    59  [cgo] stdout '^\tbuild\tCGO_CFLAGS=-DFROM_CFLAGS=1$'
    60  [cgo] stdout '^\tbuild\tCGO_CXXFLAGS=-DFROM_CXXFLAGS=1$'
    61  [cgo] stdout '^\tbuild\tCGO_LDFLAGS=-L/extra/dir/does/not/exist$'
    62  
    63  -- go.mod --
    64  module example.com/m
    65  
    66  go 1.18
    67  -- m.go --
    68  package main
    69  
    70  func main() {}
    71  

View as plain text