]> Cypherpunks repositories - gostls13.git/commitdiff
go/build: reject directory with only cgo files if cgo not in use
authorRuss Cox <rsc@golang.org>
Wed, 11 Sep 2013 17:25:30 +0000 (13:25 -0400)
committerRuss Cox <rsc@golang.org>
Wed, 11 Sep 2013 17:25:30 +0000 (13:25 -0400)
The old test for "no Go files" was p.Name == "", meaning we never
saw a Go package statement. That test fails if there are cgo files
that we parsed (and recorded the package name) but then chose
not to use (because cgo is not available).

Test the actual file lists instead.

Fixes #6078.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/13661043

src/cmd/go/test.bash
src/cmd/go/testdata/src/cgotest/m.go [new file with mode: 0644]
src/pkg/go/build/build.go

index a2ba1ca95acacd46f8678a6e20ef3689d69cd7c9..c5effe757e4fbf63420035897e73d5be789ca3db 100755 (executable)
@@ -167,6 +167,19 @@ elif ! grep testdata/shadow/root1/src/foo testdata/err >/dev/null; then
 fi
 unset GOPATH
 
+TEST go install fails with no buildable files
+export GOPATH=$(pwd)/testdata
+export CGO_ENABLED=0
+if ./testgo install cgotest 2>testdata/err; then
+       echo "go install cgotest succeeded unexpectedly"
+elif ! grep 'no buildable Go source files' testdata/err >/dev/null; then
+       echo "go install cgotest did not report 'no buildable Go source files'"
+       cat testdata/err
+       ok=false
+fi
+unset CGO_ENABLED
+unset GOPATH
+
 # Test that without $GOBIN set, binaries get installed
 # into the GOPATH bin directory.
 TEST install into GOPATH
diff --git a/src/cmd/go/testdata/src/cgotest/m.go b/src/cmd/go/testdata/src/cgotest/m.go
new file mode 100644 (file)
index 0000000..4d68307
--- /dev/null
@@ -0,0 +1,5 @@
+package cgotest
+
+import "C"
+
+var _ C.int
index f259525f5efd945cb64078adeb7fce7708325cad..be48df9d38be82e5c35a0923927efc4abd118117 100644 (file)
@@ -747,6 +747,8 @@ Found:
                        allTags["cgo"] = true
                        if ctxt.CgoEnabled {
                                p.CgoFiles = append(p.CgoFiles, name)
+                       } else {
+                               p.IgnoredGoFiles = append(p.IgnoredGoFiles, name)
                        }
                } else if isXTest {
                        p.XTestGoFiles = append(p.XTestGoFiles, name)
@@ -756,7 +758,7 @@ Found:
                        p.GoFiles = append(p.GoFiles, name)
                }
        }
-       if p.Name == "" {
+       if len(p.GoFiles)+len(p.CgoFiles)+len(p.TestGoFiles)+len(p.XTestGoFiles) == 0 {
                return p, &NoGoError{p.Dir}
        }