]> Cypherpunks repositories - gostls13.git/commitdiff
test: recognize cgo build tag
authorIan Lance Taylor <iant@golang.org>
Wed, 24 Mar 2021 20:16:42 +0000 (13:16 -0700)
committerIan Lance Taylor <iant@golang.org>
Wed, 24 Mar 2021 21:19:57 +0000 (21:19 +0000)
This requires us to add a fake argument to issue36705.go so that the
test driver will build it with "go run" rather than "go tool compile".

Change-Id: Id08b97d898ee3e9d6c1fbb072a0a9317ed9faedd
Reviewed-on: https://go-review.googlesource.com/c/go/+/304569
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
test/fixedbugs/issue36705.go
test/run.go

index 83e41368452beb9da3a8f206c37104335909ef3f..d5a0e7fadef933be2691aa27704cb83f1b3ea8ba 100644 (file)
@@ -1,5 +1,5 @@
 // +build cgo
-// run
+// run fake-arg-to-force-use-of-go-run
 
 // Copyright 2020 The Go Authors. All rights reserved.
 // Use of this source code is governed by a BSD-style
index cc2fcf351868b130cdca5619cb96700a8bf41424..48115ed18d66d6d25ee5ab2e1780c19ead15d7aa 100644 (file)
@@ -56,6 +56,7 @@ func defaultAllCodeGen() bool {
 
 var (
        goos, goarch string
+       cgoEnabled   bool
 
        // dirs are the directories to look for *.go files in.
        // TODO(bradfitz): just use all directories?
@@ -82,6 +83,10 @@ func main() {
 
        goos = getenv("GOOS", runtime.GOOS)
        goarch = getenv("GOARCH", runtime.GOARCH)
+       cgoEnv, err := exec.Command(goTool(), "env", "CGO_ENABLED").Output()
+       if err == nil {
+               cgoEnabled, _ = strconv.ParseBool(strings.TrimSpace(string(cgoEnv)))
+       }
 
        findExecCmd()
 
@@ -367,9 +372,10 @@ func goDirPackages(longdir string, singlefilepkgs bool) ([][]string, error) {
 }
 
 type context struct {
-       GOOS     string
-       GOARCH   string
-       noOptEnv bool
+       GOOS       string
+       GOARCH     string
+       cgoEnabled bool
+       noOptEnv   bool
 }
 
 // shouldTest looks for build tags in a source file and returns
@@ -391,9 +397,10 @@ func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) {
                }
                gcFlags := os.Getenv("GO_GCFLAGS")
                ctxt := &context{
-                       GOOS:     goos,
-                       GOARCH:   goarch,
-                       noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
+                       GOOS:       goos,
+                       GOARCH:     goarch,
+                       cgoEnabled: cgoEnabled,
+                       noOptEnv:   strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
                }
 
                words := strings.Fields(line)
@@ -448,6 +455,10 @@ func (ctxt *context) match(name string) bool {
                }
        }
 
+       if name == "cgo" && ctxt.cgoEnabled {
+               return true
+       }
+
        if name == ctxt.GOOS || name == ctxt.GOARCH || name == "gc" {
                return true
        }