@@ -10,21 +10,21 @@ import (
10
10
"cmd/internal/script/scripttest"
11
11
"errors"
12
12
"fmt"
13
- "internal/buildcfg"
14
- "internal/platform"
15
13
"internal/testenv"
16
14
"os"
17
15
"os/exec"
18
16
"path/filepath"
19
17
"runtime"
20
18
"runtime/debug"
21
- "strings"
22
19
"sync"
20
+ "testing"
23
21
)
24
22
25
- func scriptConditions () map [string ]script.Cond {
23
+ func scriptConditions (t * testing. T ) map [string ]script.Cond {
26
24
conds := scripttest .DefaultConds ()
27
25
26
+ scripttest .AddToolChainScriptConditions (t , conds , goHostOS , goHostArch )
27
+
28
28
add := func (name string , cond script.Cond ) {
29
29
if _ , ok := conds [name ]; ok {
30
30
panic (fmt .Sprintf ("condition %q is already registered" , name ))
@@ -37,26 +37,10 @@ func scriptConditions() map[string]script.Cond {
37
37
}
38
38
39
39
add ("abscc" , script .Condition ("default $CC path is absolute and exists" , defaultCCIsAbsolute ))
40
- add ("asan" , sysCondition ("-asan" , platform .ASanSupported , true ))
41
- add ("buildmode" , script .PrefixCondition ("go supports -buildmode=<suffix>" , hasBuildmode ))
42
40
add ("case-sensitive" , script .OnceCondition ("$WORK filesystem is case-sensitive" , isCaseSensitive ))
43
41
add ("cc" , script .PrefixCondition ("go env CC = <suffix> (ignoring the go/env file)" , ccIs ))
44
- add ("cgo" , script .BoolCondition ("host CGO_ENABLED" , testenv .HasCGO ()))
45
- add ("cgolinkext" , script .Condition ("platform requires external linking for cgo" , cgoLinkExt ))
46
- add ("cross" , script .BoolCondition ("cmd/go GOOS/GOARCH != GOHOSTOS/GOHOSTARCH" , goHostOS != runtime .GOOS || goHostArch != runtime .GOARCH ))
47
- add ("fuzz" , sysCondition ("-fuzz" , platform .FuzzSupported , false ))
48
- add ("fuzz-instrumented" , sysCondition ("-fuzz with instrumentation" , platform .FuzzInstrumented , false ))
49
42
add ("git" , lazyBool ("the 'git' executable exists and provides the standard CLI" , hasWorkingGit ))
50
- add ("GODEBUG" , script .PrefixCondition ("GODEBUG contains <suffix>" , hasGodebug ))
51
- add ("GOEXPERIMENT" , script .PrefixCondition ("GOEXPERIMENT <suffix> is enabled" , hasGoexperiment ))
52
- add ("go-builder" , script .BoolCondition ("GO_BUILDER_NAME is non-empty" , testenv .Builder () != "" ))
53
- add ("link" , lazyBool ("testenv.HasLink()" , testenv .HasLink ))
54
- add ("msan" , sysCondition ("-msan" , platform .MSanSupported , true ))
55
- add ("mustlinkext" , script .Condition ("platform always requires external linking" , mustLinkExt ))
56
43
add ("net" , script .PrefixCondition ("can connect to external network host <suffix>" , hasNet ))
57
- add ("pielinkext" , script .Condition ("platform requires external linking for PIE" , pieLinkExt ))
58
- add ("race" , sysCondition ("-race" , platform .RaceDetectorSupported , true ))
59
- add ("symlink" , lazyBool ("testenv.HasSymlink()" , testenv .HasSymlink ))
60
44
add ("trimpath" , script .OnceCondition ("test binary was built with -trimpath" , isTrimpath ))
61
45
62
46
return conds
@@ -84,23 +68,6 @@ func ccIs(s *script.State, want string) (bool, error) {
84
68
return cfg .DefaultCC (GOOS , GOARCH ) == want , nil
85
69
}
86
70
87
- func sysCondition (flag string , f func (goos , goarch string ) bool , needsCgo bool ) script.Cond {
88
- return script .Condition (
89
- "GOOS/GOARCH supports " + flag ,
90
- func (s * script.State ) (bool , error ) {
91
- GOOS , _ := s .LookupEnv ("GOOS" )
92
- GOARCH , _ := s .LookupEnv ("GOARCH" )
93
- cross := goHostOS != GOOS || goHostArch != GOARCH
94
- return (! needsCgo || (testenv .HasCGO () && ! cross )) && f (GOOS , GOARCH ), nil
95
- })
96
- }
97
-
98
- func hasBuildmode (s * script.State , mode string ) (bool , error ) {
99
- GOOS , _ := s .LookupEnv ("GOOS" )
100
- GOARCH , _ := s .LookupEnv ("GOARCH" )
101
- return platform .BuildModeSupported (runtime .Compiler , mode , GOOS , GOARCH ), nil
102
- }
103
-
104
71
var scriptNetEnabled sync.Map // testing.TB → already enabled
105
72
106
73
func hasNet (s * script.State , host string ) (bool , error ) {
@@ -137,35 +104,6 @@ func hasNet(s *script.State, host string) (bool, error) {
137
104
return true , nil
138
105
}
139
106
140
- func hasGodebug (s * script.State , value string ) (bool , error ) {
141
- godebug , _ := s .LookupEnv ("GODEBUG" )
142
- for _ , p := range strings .Split (godebug , "," ) {
143
- if strings .TrimSpace (p ) == value {
144
- return true , nil
145
- }
146
- }
147
- return false , nil
148
- }
149
-
150
- func hasGoexperiment (s * script.State , value string ) (bool , error ) {
151
- GOOS , _ := s .LookupEnv ("GOOS" )
152
- GOARCH , _ := s .LookupEnv ("GOARCH" )
153
- goexp , _ := s .LookupEnv ("GOEXPERIMENT" )
154
- flags , err := buildcfg .ParseGOEXPERIMENT (GOOS , GOARCH , goexp )
155
- if err != nil {
156
- return false , err
157
- }
158
- for _ , exp := range flags .All () {
159
- if value == exp {
160
- return true , nil
161
- }
162
- if strings .TrimPrefix (value , "no" ) == strings .TrimPrefix (exp , "no" ) {
163
- return false , nil
164
- }
165
- }
166
- return false , fmt .Errorf ("unrecognized GOEXPERIMENT %q" , value )
167
- }
168
-
169
107
func isCaseSensitive () (bool , error ) {
170
108
tmpdir , err := os .MkdirTemp (testTmpDir , "case-sensitive" )
171
109
if err != nil {
@@ -213,21 +151,3 @@ func hasWorkingGit() bool {
213
151
_ , err := exec .LookPath ("git" )
214
152
return err == nil
215
153
}
216
-
217
- func cgoLinkExt (s * script.State ) (bool , error ) {
218
- GOOS , _ := s .LookupEnv ("GOOS" )
219
- GOARCH , _ := s .LookupEnv ("GOARCH" )
220
- return platform .MustLinkExternal (GOOS , GOARCH , true ), nil
221
- }
222
-
223
- func mustLinkExt (s * script.State ) (bool , error ) {
224
- GOOS , _ := s .LookupEnv ("GOOS" )
225
- GOARCH , _ := s .LookupEnv ("GOARCH" )
226
- return platform .MustLinkExternal (GOOS , GOARCH , false ), nil
227
- }
228
-
229
- func pieLinkExt (s * script.State ) (bool , error ) {
230
- GOOS , _ := s .LookupEnv ("GOOS" )
231
- GOARCH , _ := s .LookupEnv ("GOARCH" )
232
- return ! platform .InternalLinkPIESupported (GOOS , GOARCH ), nil
233
- }
0 commit comments