aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorRuss Cox <rsc@golang.org>2014-09-24 15:10:38 -0400
committerRuss Cox <rsc@golang.org>2014-09-24 15:10:38 -0400
commita0785a53add4253db84349d58abbe2ba8be130d9 (patch)
treeea7ac2acdab39f87605d99153f334cfcf7c28ab5 /src
parent6f219e8b847c731a6c0d3695b74f312a1ea705a5 (diff)
downloadgo-a0785a53add4253db84349d58abbe2ba8be130d9.tar.xz
cmd/go: prohibit C sources files unless using cgo
Those C files would have been compiled with 6c. It's close to impossible to use C correctly anymore, and the C compilers are going away eventually. Make them unavailable now. go1.4.txt change in CL 145890046 LGTM=iant R=iant CC=golang-codereviews, r https://golang.org/cl/149720043
Diffstat (limited to 'src')
-rw-r--r--src/cmd/go/pkg.go10
-rwxr-xr-xsrc/cmd/go/test.bash14
-rw-r--r--src/cmd/go/testdata/src/badc/x.c1
-rw-r--r--src/cmd/go/testdata/src/badc/x.go1
-rw-r--r--src/net/empty.s (renamed from src/net/empty.c)0
-rw-r--r--src/runtime/debug/debug.s (renamed from src/runtime/debug/debug.c)0
6 files changed, 26 insertions, 0 deletions
diff --git a/src/cmd/go/pkg.go b/src/cmd/go/pkg.go
index 63875aed5a..4bbcc2b971 100644
--- a/src/cmd/go/pkg.go
+++ b/src/cmd/go/pkg.go
@@ -614,6 +614,16 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
}
p.Target = p.target
+ // Check for C code compiled with Plan 9 C compiler.
+ // No longer allowed except in runtime and runtime/cgo, for now.
+ if len(p.CFiles) > 0 && !p.usesCgo() && (!p.Standard || p.ImportPath != "runtime") {
+ p.Error = &PackageError{
+ ImportStack: stk.copy(),
+ Err: fmt.Sprintf("C source files not allowed when not using cgo: %s", strings.Join(p.CFiles, " ")),
+ }
+ return p
+ }
+
// In the absence of errors lower in the dependency tree,
// check for case-insensitive collisions of import paths.
if len(p.DepsErrors) == 0 {
diff --git a/src/cmd/go/test.bash b/src/cmd/go/test.bash
index 13886e158b..9ae17e1054 100755
--- a/src/cmd/go/test.bash
+++ b/src/cmd/go/test.bash
@@ -157,6 +157,20 @@ fi
rm -f ./testdata/err
unset GOPATH
+export GOPATH=$(pwd)/testdata/src
+TEST disallowed C source files
+export GOPATH=$(pwd)/testdata
+if ./testgo build badc 2>testdata/err; then
+ echo 'go build badc succeeded'
+ ok=false
+elif ! grep 'C source files not allowed' testdata/err >/dev/null; then
+ echo 'go test did not say C source files not allowed:'
+ cat testdata/err
+ ok=false
+fi
+rm -f ./testdata/err
+unset GOPATH
+
TEST error message for syntax error in test go file says FAIL
export GOPATH=$(pwd)/testdata
if ./testgo test syntaxerror 2>testdata/err; then
diff --git a/src/cmd/go/testdata/src/badc/x.c b/src/cmd/go/testdata/src/badc/x.c
new file mode 100644
index 0000000000..f6cbf6924d
--- /dev/null
+++ b/src/cmd/go/testdata/src/badc/x.c
@@ -0,0 +1 @@
+// C code!
diff --git a/src/cmd/go/testdata/src/badc/x.go b/src/cmd/go/testdata/src/badc/x.go
new file mode 100644
index 0000000000..bfa1de28bd
--- /dev/null
+++ b/src/cmd/go/testdata/src/badc/x.go
@@ -0,0 +1 @@
+package badc
diff --git a/src/net/empty.c b/src/net/empty.s
index a515c2fe29..a515c2fe29 100644
--- a/src/net/empty.c
+++ b/src/net/empty.s
diff --git a/src/runtime/debug/debug.c b/src/runtime/debug/debug.s
index a7292c477b..a7292c477b 100644
--- a/src/runtime/debug/debug.c
+++ b/src/runtime/debug/debug.s