Skip to content

Commit 28314cf

Browse files
author
Bryan C. Mills
committed
cmd/go: add a 'buildmode' condition for script tests
In CL 208233 I am fixing a panic that occurs only with a specific build mode. I want that test to run on all platforms that support that build mode, but the logic for determining support is somewhat involved. For now, I am duplicating that logic into the cmd/internal/sys package, which already reports platform support for other build flags. We can refactor cmd/go/internal/work to use the extracted function in a followup CL. Updates #35759 Change-Id: Ibbaedde4d1e8f683c650beedd10849bc27e7a6e7 Reviewed-on: https://go-review.googlesource.com/c/go/+/208457 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent c931f1b commit 28314cf

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

src/cmd/go/script_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"cmd/go/internal/robustio"
3131
"cmd/go/internal/txtar"
3232
"cmd/go/internal/work"
33+
"cmd/internal/sys"
3334
)
3435

3536
// TestScript runs the tests in testdata/script/*.txt.
@@ -303,6 +304,11 @@ Script:
303304
}
304305
break
305306
}
307+
if strings.HasPrefix(cond.tag, "buildmode:") {
308+
value := strings.TrimPrefix(cond.tag, "buildmode:")
309+
ok = sys.BuildModeSupported(runtime.Compiler, value, runtime.GOOS, runtime.GOARCH)
310+
break
311+
}
306312
if !imports.KnownArch[cond.tag] && !imports.KnownOS[cond.tag] && cond.tag != "gc" && cond.tag != "gccgo" {
307313
ts.fatalf("unknown condition %q", cond.tag)
308314
}

src/cmd/go/testdata/script/README

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ should only run when the condition is satisfied. The available conditions are:
7979
- [symlink] for testenv.HasSymlink()
8080
- [exec:prog] for whether prog is available for execution (found by exec.LookPath)
8181
- [GODEBUG:value] for whether value is one of the comma-separated entries in the GODEBUG variable
82+
- [buildmode:value] for whether -buildmode=value is supported
8283

8384
A condition can be negated: [!short] means to run the rest of the line
8485
when testing.Short() is false. Multiple conditions may be given for a single

src/cmd/internal/sys/supported.go

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,3 +43,76 @@ func MustLinkExternal(goos, goarch string) bool {
4343
}
4444
return false
4545
}
46+
47+
// BuildModeSupported reports whether goos/goarch supports the given build mode
48+
// using the given compiler.
49+
func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
50+
// This function mirrors the logic in cmd/go/internal/work.buildModeInit.
51+
//
52+
// TODO(bcmills): Refactor buildModeInit to use this function so that the two
53+
// don't get out of sync.
54+
55+
if compiler == "gccgo" {
56+
return true
57+
}
58+
59+
platform := goos + "/" + goarch
60+
61+
switch buildmode {
62+
case "archive":
63+
return true
64+
65+
case "c-archive":
66+
// TODO(bcmills): This seems dubious.
67+
// Do we really support c-archive mode on js/wasm‽
68+
return platform != "linux/ppc64"
69+
70+
case "c-shared":
71+
switch platform {
72+
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/s390x",
73+
"android/amd64", "android/arm", "android/arm64", "android/386",
74+
"freebsd/amd64",
75+
"darwin/amd64", "darwin/386",
76+
"windows/amd64", "windows/386":
77+
return true
78+
}
79+
return false
80+
81+
case "default":
82+
return true
83+
84+
case "exe":
85+
return true
86+
87+
case "pie":
88+
switch platform {
89+
case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x",
90+
"android/amd64", "android/arm", "android/arm64", "android/386",
91+
"freebsd/amd64",
92+
"darwin/amd64",
93+
"aix/ppc64":
94+
return true
95+
}
96+
return false
97+
98+
case "shared":
99+
switch platform {
100+
case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
101+
return true
102+
}
103+
return false
104+
105+
case "plugin":
106+
switch platform {
107+
case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
108+
"android/amd64", "android/arm", "android/arm64", "android/386",
109+
"darwin/amd64",
110+
"freebsd/amd64":
111+
return true
112+
}
113+
return false
114+
115+
default:
116+
return false
117+
}
118+
}

0 commit comments

Comments
 (0)