mirror of
https://github.com/golang/go
synced 2024-11-05 18:36:08 +00:00
test: recognize cgo build tag
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>
This commit is contained in:
parent
dade83a588
commit
63e9f6d5f0
2 changed files with 18 additions and 7 deletions
|
@ -1,5 +1,5 @@
|
||||||
// +build cgo
|
// +build cgo
|
||||||
// run
|
// run fake-arg-to-force-use-of-go-run
|
||||||
|
|
||||||
// Copyright 2020 The Go Authors. All rights reserved.
|
// Copyright 2020 The Go Authors. All rights reserved.
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
|
|
11
test/run.go
11
test/run.go
|
@ -56,6 +56,7 @@ func defaultAllCodeGen() bool {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
goos, goarch string
|
goos, goarch string
|
||||||
|
cgoEnabled bool
|
||||||
|
|
||||||
// dirs are the directories to look for *.go files in.
|
// dirs are the directories to look for *.go files in.
|
||||||
// TODO(bradfitz): just use all directories?
|
// TODO(bradfitz): just use all directories?
|
||||||
|
@ -82,6 +83,10 @@ func main() {
|
||||||
|
|
||||||
goos = getenv("GOOS", runtime.GOOS)
|
goos = getenv("GOOS", runtime.GOOS)
|
||||||
goarch = getenv("GOARCH", runtime.GOARCH)
|
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()
|
findExecCmd()
|
||||||
|
|
||||||
|
@ -369,6 +374,7 @@ func goDirPackages(longdir string, singlefilepkgs bool) ([][]string, error) {
|
||||||
type context struct {
|
type context struct {
|
||||||
GOOS string
|
GOOS string
|
||||||
GOARCH string
|
GOARCH string
|
||||||
|
cgoEnabled bool
|
||||||
noOptEnv bool
|
noOptEnv bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,6 +399,7 @@ func shouldTest(src string, goos, goarch string) (ok bool, whyNot string) {
|
||||||
ctxt := &context{
|
ctxt := &context{
|
||||||
GOOS: goos,
|
GOOS: goos,
|
||||||
GOARCH: goarch,
|
GOARCH: goarch,
|
||||||
|
cgoEnabled: cgoEnabled,
|
||||||
noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
|
noOptEnv: strings.Contains(gcFlags, "-N") || strings.Contains(gcFlags, "-l"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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" {
|
if name == ctxt.GOOS || name == ctxt.GOARCH || name == "gc" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue