<commit_before>[short] skip

# Compiler name is always added.
go build
go version -m m$GOEXE
stdout '^\tbuild\tcompiler\tgc$'
! stdout asmflags|gcflags|ldflags|gccgoflags

# Toolchain flags are added if present.
# The raw flags are included, with package patterns if specified.
go build -asmflags=all=-spectre=all
go version -m m$GOEXE
stdout '^\tbuild\tasmflags\tall=-spectre=all$'

go build -gcflags=all=-spectre=all
go version -m m$GOEXE
stdout '^\tbuild\tgcflags\tall=-spectre=all$'

go build -ldflags=-w
go version -m m$GOEXE
stdout '^\tbuild\tldflags\t-w$'

# gccgoflags are not added when gc is used, and vice versa.
# TODO: test gccgo.
go build -gccgoflags=all=UNUSED
go version -m m$GOEXE
! stdout gccgoflags

# Build and tool tags are added but not release tags.
# "race" is included with build tags but not "cgo".
go build -tags=a,b
go version -m m$GOEXE
stdout '^\tbuild\ttags\ta,b(,goexperiment\.[a-z0-9]+)*$'
[race] go build -race
[race] go version -m m$GOEXE
[race] stdout '^\tbuild\ttags\t.*race.*$'

# CGO flags are separate settings.
# CGO_ENABLED is always present.
# Other flags are added if CGO_ENABLED is true.
env CGO_ENABLED=0
go build
go version -m m$GOEXE
stdout '^\tbuild\tCGO_ENABLED\tfalse$'
! stdout CGO_CPPFLAGS|CGO_CFLAGS|CGO_CXXFLAGS|CGO_LDFLAGS
[cgo] env CGO_ENABLED=1
[cgo] env CGO_CPPFLAGS=-DFROM_CPPFLAGS=1
[cgo] env CGO_CFLAGS=-DFROM_CFLAGS=1
[cgo] env CGO_CXXFLAGS=-DFROM_CXXFLAGS=1
[cgo] env CGO_LDFLAGS=-L/extra/dir/does/not/exist
[cgo] go build
[cgo] go version -m m$GOEXE
[cgo] stdout '^\tbuild\tCGO_ENABLED\ttrue$'
[cgo] stdout '^\tbuild\tCGO_CPPFLAGS\t-DFROM_CPPFLAGS=1$'
[cgo] stdout '^\tbuild\tCGO_CFLAGS\t-DFROM_CFLAGS=1$'
[cgo] stdout '^\tbuild\tCGO_CXXFLAGS\t-DFROM_CXXFLAGS=1$'
[cgo] stdout '^\tbuild\tCGO_LDFLAGS\t-L/extra/dir/does/not/exist$'

-- go.mod --
module example.com/m

go 1.18
-- m.go --
package main

func main() {}
<commit_msg>cmd/go: use portable flags in TestScript/version_build_settings<commit_after>[short] skip

# Compiler name is always added.
go build
go version -m m$GOEXE
stdout '^\tbuild\tcompiler\tgc$'
! stdout asmflags|gcflags|ldflags|gccgoflags

# Toolchain flags are added if present.
# The raw flags are included, with package patterns if specified.
go build -asmflags=example.com/m=-D=FOO=bar
go version -m m$GOEXE
stdout '^\tbuild\tasmflags\texample\.com/m=-D=FOO=bar$'

go build -gcflags=example.com/m=-N
go version -m m$GOEXE
stdout '^\tbuild\tgcflags\texample\.com/m=-N$'

go build -ldflags=example.com/m=-w
go version -m m$GOEXE
stdout '^\tbuild\tldflags\texample\.com/m=-w$'

# gccgoflags are not added when gc is used, and vice versa.
# TODO: test gccgo.
go build -gccgoflags=all=UNUSED
go version -m m$GOEXE
! stdout gccgoflags

# Build and tool tags are added but not release tags.
# "race" is included with build tags but not "cgo".
go build -tags=a,b
go version -m m$GOEXE
stdout '^\tbuild\ttags\ta,b(,goexperiment\.[a-z0-9]+)*$'
[race] go build -race
[race] go version -m m$GOEXE
[race] stdout '^\tbuild\ttags\t.*race.*$'

# CGO flags are separate settings.
# CGO_ENABLED is always present.
# Other flags are added if CGO_ENABLED is true.
env CGO_ENABLED=0
go build
go version -m m$GOEXE
stdout '^\tbuild\tCGO_ENABLED\tfalse$'
! stdout CGO_CPPFLAGS|CGO_CFLAGS|CGO_CXXFLAGS|CGO_LDFLAGS
[cgo] env CGO_ENABLED=1
[cgo] env CGO_CPPFLAGS=-DFROM_CPPFLAGS=1
[cgo] env CGO_CFLAGS=-DFROM_CFLAGS=1
[cgo] env CGO_CXXFLAGS=-DFROM_CXXFLAGS=1
[cgo] env CGO_LDFLAGS=-L/extra/dir/does/not/exist
[cgo] go build
[cgo] go version -m m$GOEXE
[cgo] stdout '^\tbuild\tCGO_ENABLED\ttrue$'
[cgo] stdout '^\tbuild\tCGO_CPPFLAGS\t-DFROM_CPPFLAGS=1$'
[cgo] stdout '^\tbuild\tCGO_CFLAGS\t-DFROM_CFLAGS=1$'
[cgo] stdout '^\tbuild\tCGO_CXXFLAGS\t-DFROM_CXXFLAGS=1$'
[cgo] stdout '^\tbuild\tCGO_LDFLAGS\t-L/extra/dir/does/not/exist$'

-- go.mod --
module example.com/m

go 1.18
-- m.go --
package main

func main() {}

{'fraction_non_alphanumeric': 0.14068539036330843, 'fraction_numerical': 0.006699304303014687, 'mean_word_length': 4.650655021834061, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3745179', 'n_tokens_mistral': 1662, 'n_tokens_neox': 1636, 'n_words': 405}