...

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

Documentation: cmd/go/testdata/script

     1[short] skip
     2
     3# Compiler name is always added.
     4go build
     5go version -m m$GOEXE
     6stdout '^\tbuild\t-compiler=gc$'
     7stdout '^\tbuild\tGOOS='
     8stdout '^\tbuild\tGOARCH='
     9[GOARCH: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.
    14go build -asmflags=example.com/m=-D=FOO=bar
    15go version -m m$GOEXE
    16stdout '^\tbuild\t-asmflags=example\.com/m=-D=FOO=bar$'
    17
    18go build -gcflags=example.com/m=-N
    19go version -m m$GOEXE
    20stdout '^\tbuild\t-gcflags=example\.com/m=-N$'
    21
    22go build -ldflags=example.com/m=-w
    23go version -m m$GOEXE
    24stdout '^\tbuild\t-ldflags=example\.com/m=-w$'
    25
    26go build -trimpath
    27go version -m m$GOEXE
    28stdout '\tbuild\t-trimpath=true$'
    29
    30# gccgoflags are not added when gc is used, and vice versa.
    31# TODO: test gccgo.
    32go build -gccgoflags=all=UNUSED
    33go version -m m$GOEXE
    34! stdout gccgoflags
    35
    36# Build and tool tags are added but not release tags.
    37# "race" is included with build tags but not "cgo".
    38go build -tags=a,b
    39go version -m m$GOEXE
    40stdout '^\tbuild\t-tags=a,b$'
    41[race] go build -race
    42[race] go version -m m$GOEXE
    43[race] ! stdout '^\tbuild\t-tags='
    44[race] stdout '^\tbuild\t-race=true$'
    45
    46# CGO flags are separate settings.
    47# CGO_ENABLED is always present.
    48# Other flags are added if CGO_ENABLED is true.
    49env CGO_ENABLED=0
    50go build
    51go version -m m$GOEXE
    52stdout '^\tbuild\tCGO_ENABLED=0$'
    53! stdout CGO_CPPFLAGS|CGO_CFLAGS|CGO_CXXFLAGS|CGO_LDFLAGS
    54
    55[cgo] env CGO_ENABLED=1
    56[cgo] env CGO_CPPFLAGS=-DFROM_CPPFLAGS=1
    57[cgo] env CGO_CFLAGS=-DFROM_CFLAGS=1
    58[cgo] env CGO_CXXFLAGS=-DFROM_CXXFLAGS=1
    59[cgo] env CGO_LDFLAGS=-L/extra/dir/does/not/exist
    60[cgo] go build '-ldflags=all=-linkmode=external -extldflags=-L/bonus/dir/does/not/exist'
    61[cgo] go version -m m$GOEXE
    62[cgo] stdout '^\tbuild\t-ldflags="all=-linkmode=external -extldflags=-L/bonus/dir/does/not/exist"$'
    63[cgo] stdout '^\tbuild\tCGO_ENABLED=1$'
    64[cgo] stdout '^\tbuild\tCGO_CPPFLAGS=-DFROM_CPPFLAGS=1$'
    65[cgo] stdout '^\tbuild\tCGO_CFLAGS=-DFROM_CFLAGS=1$'
    66[cgo] stdout '^\tbuild\tCGO_CXXFLAGS=-DFROM_CXXFLAGS=1$'
    67[cgo] stdout '^\tbuild\tCGO_LDFLAGS=-L/extra/dir/does/not/exist$'
    68
    69# https://go.dev/issue/52372: a cgo-enabled binary should not be stamped with
    70# CGO_ flags that contain paths.
    71[cgo] env CGO_ENABLED=1
    72[cgo] env CGO_CPPFLAGS=-DFROM_CPPFLAGS=1
    73[cgo] env CGO_CFLAGS=-DFROM_CFLAGS=1
    74[cgo] env CGO_CXXFLAGS=-DFROM_CXXFLAGS=1
    75[cgo] env CGO_LDFLAGS=-L/extra/dir/does/not/exist
    76[cgo] go build -trimpath '-ldflags=all=-linkmode=external -extldflags=-L/bonus/dir/does/not/exist'
    77[cgo] go version -m m$GOEXE
    78[cgo] ! stdout '/extra/dir/does/not/exist'
    79[cgo] ! stdout '/bonus/dir/does/not/exist'
    80[cgo] stdout '^\tbuild\tCGO_ENABLED=1$'
    81
    82-- go.mod --
    83module example.com/m
    84
    85go 1.18
    86-- m.go --
    87package main
    88
    89func main() {}

View as plain text