]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: ignore C files when CGO_ENABLED=0
authorRuss Cox <rsc@golang.org>
Thu, 28 Jan 2016 16:44:07 +0000 (11:44 -0500)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 8 Mar 2016 20:10:52 +0000 (20:10 +0000)
Before, those C files might have been intended for the Plan 9 C compiler,
but that option was removed in Go 1.5. We can simplify the maintenance
of cgo packages now if we assume C files (and C++ and M and SWIG files)
should only be considered when cgo is enabled.

Also remove newly unnecessary build tags in runtime/cgo's C files.

Fixes #14123

Change-Id: Ia5a7fe62b9469965aa7c3547fe43c6c9292b8205
Reviewed-on: https://go-review.googlesource.com/19613
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

37 files changed:
src/cmd/go/build.go
src/cmd/go/go_test.go
src/cmd/go/pkg.go
src/runtime/cgo/gcc_android.c
src/runtime/cgo/gcc_android_386.c
src/runtime/cgo/gcc_android_amd64.c
src/runtime/cgo/gcc_android_arm.c
src/runtime/cgo/gcc_android_arm64.c
src/runtime/cgo/gcc_darwin_386.c
src/runtime/cgo/gcc_darwin_amd64.c
src/runtime/cgo/gcc_darwin_arm.c
src/runtime/cgo/gcc_darwin_arm64.c
src/runtime/cgo/gcc_dragonfly_amd64.c
src/runtime/cgo/gcc_fatalf.c
src/runtime/cgo/gcc_freebsd_386.c
src/runtime/cgo/gcc_freebsd_amd64.c
src/runtime/cgo/gcc_freebsd_arm.c
src/runtime/cgo/gcc_libinit_linux_ppc64x.c
src/runtime/cgo/gcc_libinit_openbsd.c
src/runtime/cgo/gcc_libinit_windows.c
src/runtime/cgo/gcc_linux_386.c
src/runtime/cgo/gcc_linux_amd64.c
src/runtime/cgo/gcc_linux_arm.c
src/runtime/cgo/gcc_linux_arm64.c
src/runtime/cgo/gcc_linux_ppc64x.c
src/runtime/cgo/gcc_mmap.c
src/runtime/cgo/gcc_netbsd_386.c
src/runtime/cgo/gcc_netbsd_amd64.c
src/runtime/cgo/gcc_netbsd_arm.c
src/runtime/cgo/gcc_openbsd_386.c
src/runtime/cgo/gcc_openbsd_amd64.c
src/runtime/cgo/gcc_signal_darwin_armx.c
src/runtime/cgo/gcc_signal_darwin_lldb.c
src/runtime/cgo/gcc_solaris_amd64.c
src/runtime/cgo/gcc_util.c
src/runtime/cgo/gcc_windows_386.c
src/runtime/cgo/gcc_windows_amd64.c

index 5977828a3a183c2ecfe7cff3596ce86899926d0d..3f9537834c940e63737fb1f3b64d9607238b2afa 100644 (file)
@@ -1419,6 +1419,8 @@ func (b *builder) build(a *action) (err error) {
                // cgo and non-cgo worlds, so it necessarily has files in both.
                // In that case gcc only gets the gcc_* files.
                var gccfiles []string
+               gccfiles = append(gccfiles, cfiles...)
+               cfiles = nil
                if a.p.Standard && a.p.ImportPath == "runtime/cgo" {
                        filter := func(files, nongcc, gcc []string) ([]string, []string) {
                                for _, f := range files {
@@ -1430,11 +1432,9 @@ func (b *builder) build(a *action) (err error) {
                                }
                                return nongcc, gcc
                        }
-                       cfiles, gccfiles = filter(cfiles, cfiles[:0], gccfiles)
                        sfiles, gccfiles = filter(sfiles, sfiles[:0], gccfiles)
                } else {
-                       gccfiles = append(cfiles, sfiles...)
-                       cfiles = nil
+                       gccfiles = append(gccfiles, sfiles...)
                        sfiles = nil
                }
 
index 2af715a3a46397060a44b556d8d0a5201054ce47..5526aec8f937bb7437d306a1a82e269d8eff4e34 100644 (file)
@@ -1226,14 +1226,6 @@ func TestGetGitDefaultBranch(t *testing.T) {
        tg.grepStdout(`\* another-branch`, "not on correct default branch")
 }
 
-func TestDisallowedCSourceFiles(t *testing.T) {
-       tg := testgo(t)
-       defer tg.cleanup()
-       tg.setenv("GOPATH", filepath.Join(tg.pwd(), "testdata"))
-       tg.runFail("build", "badc")
-       tg.grepStderr("C source files not allowed", "go test did not say C source files not allowed")
-}
-
 func TestErrorMessageForSyntaxErrorInTestGoFileSaysFAIL(t *testing.T) {
        tg := testgo(t)
        defer tg.cleanup()
index 8b0508894fe916b20b6495d6fdd5f4266ac6546d..927d68d1c60d5b76d9dd735e2d0e8f76e957d457 100644 (file)
@@ -1012,6 +1012,19 @@ func (p *Package) load(stk *importStack, bp *build.Package, err error) *Package
        }
        p.Target = p.target
 
+       // If cgo is not enabled, ignore cgo supporting sources
+       // just as we ignore go files containing import "C".
+       if !buildContext.CgoEnabled {
+               p.CFiles = nil
+               p.CXXFiles = nil
+               p.MFiles = nil
+               p.SwigFiles = nil
+               p.SwigCXXFiles = nil
+               p.SysoFiles = nil
+               // Note that SFiles are okay (they go to the Go assembler)
+               // and HFiles are okay (they might be used by the SFiles).
+       }
+
        // The gc toolchain only permits C source files with cgo.
        if len(p.CFiles) > 0 && !p.usesCgo() && !p.usesSwig() && buildContext.Compiler == "gc" {
                p.Error = &PackageError{
index b500b29c5ed39efbd4bf44ce9bc9c49ace4f6428..b756edefa90249b98cca3d348bed2f2500fab170 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <stdarg.h>
 #include <android/log.h>
 #include "libcgo.h"
index 92c77900d2165aa1ce59fc91fe2fcc4d9469bd5d..23a15f1c87e0f4de221481a3b23b98a5b9932836 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <string.h> /* for strerror */
 #include <pthread.h>
 #include <signal.h>
index fce7d56a4b93e98155f991c4aea6682ff94f9bd5..e006c49bcf5e718d132604c86faf63c5902a4ac9 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <string.h> /* for strerror */
 #include <pthread.h>
 #include <signal.h>
index 06f4217d22bd3ebb4dcea4dacab31490f064ca85..c7b13f9a7f4dde6b4be9f4657ca7c970b070ebfc 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
index 9aaf1ba73fd14b875bbdb5403008e9c84f8ba746..f8ad684de344cb8c9f24e90008f208d2defd75ec 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <pthread.h>
 #include <signal.h>
 #include <stdio.h>
index a633728a45384b77dd323406a12909918c81785b..effbcdfd4b47d7453c37be8099d54370ba90765d 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <string.h> /* for strerror */
 #include <pthread.h>
 #include <signal.h>
index 58e99e5549b04b4a5d99cb7bd9722adf86f3cd18..15396b0d258f7d8444b46fd13a10a6a84be105a8 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <string.h> /* for strerror */
 #include <pthread.h>
 #include <signal.h>
index 967f44385d158c46af7464447fd149bcad56fe98..dbf88c34ac510d0b0ecd43c0aa78328bed035ddd 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <limits.h>
 #include <pthread.h>
 #include <signal.h>
index 21912298cfe8d4d1a7157375eff98581bbb72225..a9eb4f2cd2d2a31396a701adc5190239ee52a38f 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <limits.h>
 #include <pthread.h>
 #include <signal.h>
index 85c53ca707625b4cd49ed8167980a1ee46379ef0..b534dccf79710bfbab31833f25a9d3bcdc9da1d5 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <sys/signalvar.h>
 #include <pthread.h>
index 08aebaa806d51218ee7ee34f242fe7c54f7e964d..5ac419b412084de1a04ac856e0ec779a5beba305 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 // +build !android,linux
 
 #include <stdarg.h>
index 522f95b2ddc896d7f2049bc3b49e628ef60a0211..d288666a3dbca67085fb43c404105ccd3e364190 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <sys/signalvar.h>
 #include <pthread.h>
index 31ab136998ed8f04f49ca29717fb563744eca6dd..e532ad69d6933a564d8bdddd2369c61b4ddc1efd 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <sys/signalvar.h>
 #include <pthread.h>
index 73f32792c55b54f3cf3c5f88d897337cf8becd6b..c4e7574326138f1231aadb2095ece543b4780a26 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <machine/sysarch.h>
 #include <sys/signalvar.h>
index 147872a7bf2e22ca3d1cefbfa9611ebc2d970b51..c133142f9385afd83b74041d33f117fc7ffbf9d2 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 // TODO: see issue #10410
 // +build linux
 // +build ppc64 ppc64le
index 5fa84c4de6e55fced9ddc655fb3d30e0e76c76f0..eb798ce5e809bca74c9e2ec07fa07928eed33f1f 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <stdio.h>
 #include <stdlib.h>
 
index 5fa84c4de6e55fced9ddc655fb3d30e0e76c76f0..eb798ce5e809bca74c9e2ec07fa07928eed33f1f 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <stdio.h>
 #include <stdlib.h>
 
index 15e0a8a30253a83fd11ec2e67471ca9f2543b433..30fe92bfea9b4f38c52b65680483bbee3c571f8d 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <pthread.h>
 #include <string.h>
 #include <signal.h>
index 0ab4912238988db3e00481ea7cebaff36486c2c4..50a7e6e078e52a9c6adce5017ae33ce838c94597 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <pthread.h>
 #include <errno.h>
 #include <string.h> // strerror
index f5524219570b09adbb60777e18cb9d43c248a417..945c3f19e498ec39c821c057b34af9e1a0a2950b 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <pthread.h>
 #include <string.h>
 #include <signal.h>
index 84bd7c0b499cc5bc1ef694712dbc752f5b681900..ca9ba0ba6e7090575de3835498c03c62d8fcf7d3 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <pthread.h>
 #include <string.h>
 #include <signal.h>
index 2721384e6beeb9c99d807371c2440bee5274be2a..fb19805bdae7e9026213c9f43abb9a3749042efa 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 // +build ppc64 ppc64le
 
 #include <pthread.h>
index 45786f94ea28681dd5463ac3d617449d846ae300..14efa5489da97bb8724714bae898a57adc92cb8d 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 // +build linux,amd64
 
 #include <errno.h>
index 32f2e156789d2cc734ca9f5bab7fe30656550968..99558ea1401562bbeeb1d79b41ca6ce065142abd 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <pthread.h>
 #include <signal.h>
index aa357459c725c8063f966a0b6345002f5f90354b..f5c8b1e74f0507a2e0b144c50c72862955bb7d53 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <pthread.h>
 #include <signal.h>
index 9589780ac84041e66efcb84a980d59cdecd97855..97ce908485e02564ff46fe5de2935142a20a40e3 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <pthread.h>
 #include <signal.h>
index bf56c8db2643c209878774b1db85306deb2e6b47..22941a4c6d458ff220587e182fa4b077bbb4e42a 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <dlfcn.h>
 #include <errno.h>
index b9f2a9d5a995121b73a1bdebb9356a86cf882da7..e84fe6c18b035f9e789cb43b92c561ef5d910d38 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <sys/types.h>
 #include <dlfcn.h>
 #include <errno.h>
index ac3c2571c0d5154c75586ce1dc89b71ce8c2f31c..e77c507e9359aad44c7faa5d6e61a7c6edc97d78 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 // Emulation of the Unix signal SIGSEGV.
 //
 // On iOS, Go tests and apps under development are run by lldb.
index 598482d350d29881c38386fc1201cfead84613b2..12cc388400fe3bfb1f5b5eb4442f07dd31dc7170 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 // +build !lldb
 // +build darwin
 // +build arm arm64
index 5a01e0826e330ca5992fd1253f1bab411b18f9e8..98a1a8be532a3bf9cebee1f86adf14bdb64f9b72 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include <pthread.h>
 #include <string.h>
 #include <signal.h>
index a15c2d23bbc34f7d6613ee2ecac10076f16b2b44..e20d206be6d7996407b9cb84e6118bdff161d270 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #include "libcgo.h"
 
 /* Stub for calling malloc from Go */
index 536a024c564a9f2099f5744b14c5961573ecf43c..fa0c69bc13804a0c2eee3d7e513a5da7868ff78a 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <process.h>
index 75d87f0cf8b07f0510cdd3386bcd4972f55ec5e4..a3c3896edfca5e5a480d76dfb34e302b817505da 100644 (file)
@@ -2,8 +2,6 @@
 // Use of this source code is governed by a BSD-style
 // license that can be found in the LICENSE file.
 
-// +build cgo
-
 #define WIN64_LEAN_AND_MEAN
 #include <windows.h>
 #include <process.h>