Skip to content

Commit 8bd803f

Browse files
committed
cmd/internal/sys: migrate support.go functions to new internal pkg
Separate out the functions from cmd/internal/sys/support.go and migrate them to a new package internal/platform, so that functions such as "RaceDetectorSupported" can be called from tests in std as well as in cmd. This isn't a complete move of everything in cmd/internal/sys; there are still many functions left. The original version of this CL (patch set 1) called the new package "internal/sys", but for packages that needed both "internal/sys" and "cmd/internal/sys" the import of the former had to be done with a different name, which was confusing and also required a hack in cmd/dist. Updates #56006. Change-Id: I866d62e75adbf3a640a06e2c7386a6e9e2a18d91 Reviewed-on: https://go-review.googlesource.com/c/go/+/438475 Reviewed-by: Bryan Mills <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Cherry Mui <[email protected]> Run-TryBot: Than McIntosh <[email protected]>
1 parent dfd8aa4 commit 8bd803f

19 files changed

Lines changed: 42 additions & 69 deletions

File tree

src/cmd/compile/internal/base/flag.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"internal/buildcfg"
1212
"internal/coverage"
13+
"internal/platform"
1314
"log"
1415
"os"
1516
"reflect"
@@ -176,13 +177,13 @@ func ParseFlags() {
176177
registerFlags()
177178
objabi.Flagparse(usage)
178179

179-
if Flag.MSan && !sys.MSanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
180+
if Flag.MSan && !platform.MSanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
180181
log.Fatalf("%s/%s does not support -msan", buildcfg.GOOS, buildcfg.GOARCH)
181182
}
182-
if Flag.ASan && !sys.ASanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
183+
if Flag.ASan && !platform.ASanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
183184
log.Fatalf("%s/%s does not support -asan", buildcfg.GOOS, buildcfg.GOARCH)
184185
}
185-
if Flag.Race && !sys.RaceDetectorSupported(buildcfg.GOOS, buildcfg.GOARCH) {
186+
if Flag.Race && !platform.RaceDetectorSupported(buildcfg.GOOS, buildcfg.GOARCH) {
186187
log.Fatalf("%s/%s does not support -race", buildcfg.GOOS, buildcfg.GOARCH)
187188
}
188189
if (*Flag.Shared || *Flag.Dynlink || *Flag.LinkShared) && !Ctxt.Arch.InFamily(sys.AMD64, sys.ARM, sys.ARM64, sys.I386, sys.PPC64, sys.RISCV64, sys.S390X) {

src/cmd/dist/buildtool.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ var bootstrapDirs = []string{
6767
"internal/pkgbits",
6868
"internal/race",
6969
"internal/saferio",
70+
"internal/platform",
7071
"internal/unsafeheader",
7172
"internal/xcoff",
7273
"math/big",

src/cmd/dist/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1711,7 +1711,7 @@ func (t *tester) runPrecompiledStdTest(timeout time.Duration) error {
17111711
}
17121712

17131713
// raceDetectorSupported is a copy of the function
1714-
// cmd/internal/sys.RaceDetectorSupported, which can't be used here
1714+
// internal/platform.RaceDetectorSupported, which can't be used here
17151715
// because cmd/dist has to be buildable by Go 1.4.
17161716
// The race detector only supports 48-bit VMA on arm64. But we don't have
17171717
// a good solution to check VMA size(See https://golang.org/issue/29948)

src/cmd/go/go_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"fmt"
1515
"go/format"
1616
"internal/godebug"
17+
"internal/platform"
1718
"internal/testenv"
1819
"io"
1920
"io/fs"
@@ -260,17 +261,17 @@ func TestMain(m *testing.M) {
260261
}
261262
testGOCACHE = strings.TrimSpace(string(out))
262263

263-
canMSan = canCgo && sys.MSanSupported(runtime.GOOS, runtime.GOARCH)
264-
canASan = canCgo && sys.ASanSupported(runtime.GOOS, runtime.GOARCH)
265-
canRace = canCgo && sys.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH)
264+
canMSan = canCgo && platform.MSanSupported(runtime.GOOS, runtime.GOARCH)
265+
canASan = canCgo && platform.ASanSupported(runtime.GOOS, runtime.GOARCH)
266+
canRace = canCgo && platform.RaceDetectorSupported(runtime.GOOS, runtime.GOARCH)
266267
// The race detector doesn't work on Alpine Linux:
267268
// golang.org/issue/14481
268269
// gccgo does not support the race detector.
269270
if isAlpineLinux() || runtime.Compiler == "gccgo" {
270271
canRace = false
271272
}
272-
canFuzz = sys.FuzzSupported(runtime.GOOS, runtime.GOARCH)
273-
fuzzInstrumented = sys.FuzzInstrumented(runtime.GOOS, runtime.GOARCH)
273+
canFuzz = platform.FuzzSupported(runtime.GOOS, runtime.GOARCH)
274+
fuzzInstrumented = platform.FuzzInstrumented(runtime.GOOS, runtime.GOARCH)
274275
}
275276

276277
// Don't let these environment variables confuse the test.

src/cmd/go/internal/load/pkg.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"go/build"
1616
"go/scanner"
1717
"go/token"
18+
"internal/platform"
1819
"io/fs"
1920
"os"
2021
"os/exec"
@@ -43,7 +44,6 @@ import (
4344
"cmd/go/internal/trace"
4445
"cmd/go/internal/vcs"
4546
"cmd/internal/pkgpattern"
46-
"cmd/internal/sys"
4747

4848
"golang.org/x/mod/modfile"
4949
"golang.org/x/mod/module"
@@ -2604,7 +2604,7 @@ func externalLinkingForced(p *Package) bool {
26042604
// -ldflags=-linkmode=external. External linking mode forces
26052605
// an import of runtime/cgo.
26062606
// If there are multiple -linkmode options, the last one wins.
2607-
pieCgo := cfg.BuildBuildmode == "pie" && !sys.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH)
2607+
pieCgo := cfg.BuildBuildmode == "pie" && !platform.InternalLinkPIESupported(cfg.BuildContext.GOOS, cfg.BuildContext.GOARCH)
26082608
linkmodeExternal := false
26092609
if p != nil {
26102610
ldflags := BuildLdflags.For(p)

src/cmd/go/internal/test/test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"context"
1010
"errors"
1111
"fmt"
12+
"internal/platform"
1213
"io"
1314
"io/fs"
1415
"os"
@@ -30,7 +31,6 @@ import (
3031
"cmd/go/internal/str"
3132
"cmd/go/internal/trace"
3233
"cmd/go/internal/work"
33-
"cmd/internal/sys"
3434
"cmd/internal/test2json"
3535

3636
"golang.org/x/mod/module"
@@ -664,7 +664,7 @@ func runTest(ctx context.Context, cmd *base.Command, args []string) {
664664
base.Fatalf("cannot use -o flag with multiple packages")
665665
}
666666
if testFuzz != "" {
667-
if !sys.FuzzSupported(cfg.Goos, cfg.Goarch) {
667+
if !platform.FuzzSupported(cfg.Goos, cfg.Goarch) {
668668
base.Fatalf("-fuzz flag is not supported on %s/%s", cfg.Goos, cfg.Goarch)
669669
}
670670
if len(pkgs) != 1 {

src/cmd/go/internal/work/gc.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"bufio"
99
"bytes"
1010
"fmt"
11+
"internal/platform"
1112
"io"
1213
"log"
1314
"os"
@@ -22,7 +23,6 @@ import (
2223
"cmd/go/internal/str"
2324
"cmd/internal/objabi"
2425
"cmd/internal/quoted"
25-
"cmd/internal/sys"
2626
"crypto/sha1"
2727
)
2828

@@ -640,7 +640,7 @@ func (gcToolchain) ld(b *Builder, root *Action, out, importcfg, mainpkg string)
640640
// linker's build id, which will cause our build id to not
641641
// match the next time the tool is built.
642642
// Rely on the external build id instead.
643-
if !sys.MustLinkExternal(cfg.Goos, cfg.Goarch) {
643+
if !platform.MustLinkExternal(cfg.Goos, cfg.Goarch) {
644644
ldflags = append(ldflags, "-X=cmd/internal/objabi.buildID="+root.buildID)
645645
}
646646
}

src/cmd/go/internal/work/init.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313
"cmd/go/internal/fsys"
1414
"cmd/go/internal/modload"
1515
"cmd/internal/quoted"
16-
"cmd/internal/sys"
1716
"fmt"
17+
"internal/platform"
1818
"os"
1919
"os/exec"
2020
"path/filepath"
@@ -93,7 +93,7 @@ func BuildInit() {
9393
// instrumentation is added. 'go test -fuzz' still works without coverage,
9494
// but it generates random inputs without guidance, so it's much less effective.
9595
func fuzzInstrumentFlags() []string {
96-
if !sys.FuzzInstrumented(cfg.Goos, cfg.Goarch) {
96+
if !platform.FuzzInstrumented(cfg.Goos, cfg.Goarch) {
9797
return nil
9898
}
9999
return []string{"-d=libfuzzer"}
@@ -118,17 +118,17 @@ func instrumentInit() {
118118
base.SetExitStatus(2)
119119
base.Exit()
120120
}
121-
if cfg.BuildMSan && !sys.MSanSupported(cfg.Goos, cfg.Goarch) {
121+
if cfg.BuildMSan && !platform.MSanSupported(cfg.Goos, cfg.Goarch) {
122122
fmt.Fprintf(os.Stderr, "-msan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
123123
base.SetExitStatus(2)
124124
base.Exit()
125125
}
126-
if cfg.BuildRace && !sys.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
126+
if cfg.BuildRace && !platform.RaceDetectorSupported(cfg.Goos, cfg.Goarch) {
127127
fmt.Fprintf(os.Stderr, "-race is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
128128
base.SetExitStatus(2)
129129
base.Exit()
130130
}
131-
if cfg.BuildASan && !sys.ASanSupported(cfg.Goos, cfg.Goarch) {
131+
if cfg.BuildASan && !platform.ASanSupported(cfg.Goos, cfg.Goarch) {
132132
fmt.Fprintf(os.Stderr, "-asan is not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
133133
base.SetExitStatus(2)
134134
base.Exit()
@@ -299,12 +299,12 @@ func buildModeInit() {
299299
base.Fatalf("buildmode=%s not supported", cfg.BuildBuildmode)
300300
}
301301

302-
if !sys.BuildModeSupported(cfg.BuildToolchainName, cfg.BuildBuildmode, cfg.Goos, cfg.Goarch) {
302+
if !platform.BuildModeSupported(cfg.BuildToolchainName, cfg.BuildBuildmode, cfg.Goos, cfg.Goarch) {
303303
base.Fatalf("-buildmode=%s not supported on %s/%s\n", cfg.BuildBuildmode, cfg.Goos, cfg.Goarch)
304304
}
305305

306306
if cfg.BuildLinkshared {
307-
if !sys.BuildModeSupported(cfg.BuildToolchainName, "shared", cfg.Goos, cfg.Goarch) {
307+
if !platform.BuildModeSupported(cfg.BuildToolchainName, "shared", cfg.Goos, cfg.Goarch) {
308308
base.Fatalf("-linkshared not supported on %s/%s\n", cfg.Goos, cfg.Goarch)
309309
}
310310
if gccgo {

src/cmd/go/script_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"fmt"
1616
"go/build"
1717
"internal/buildcfg"
18+
"internal/platform"
1819
"internal/testenv"
1920
"internal/txtar"
2021
"io/fs"
@@ -35,7 +36,6 @@ import (
3536
"cmd/go/internal/par"
3637
"cmd/go/internal/robustio"
3738
"cmd/go/internal/work"
38-
"cmd/internal/sys"
3939
)
4040

4141
var testSum = flag.String("testsum", "", `may be tidy, listm, or listall. If set, TestScript generates a go.sum file at the beginning of each test and updates test files if they pass.`)
@@ -459,7 +459,7 @@ Script:
459459
break
460460
}
461461
if value, found := strings.CutPrefix(cond.tag, "buildmode:"); found {
462-
ok = sys.BuildModeSupported(runtime.Compiler, value, runtime.GOOS, runtime.GOARCH)
462+
ok = platform.BuildModeSupported(runtime.Compiler, value, runtime.GOOS, runtime.GOARCH)
463463
break
464464
}
465465
if strings.HasPrefix(cond.tag, "GOEXPERIMENT:") {

src/cmd/internal/sys/supported_test.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)