]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: add dependencies for implicit SWIG imports
authorIan Lance Taylor <iant@golang.org>
Wed, 8 Nov 2017 19:06:09 +0000 (11:06 -0800)
committerRuss Cox <rsc@golang.org>
Thu, 16 Nov 2017 16:27:13 +0000 (16:27 +0000)
This fixes the misc/swig tests.

Change-Id: I60c87bbd361fe8b4f69e4507b25dc99a226da3d7
Reviewed-on: https://go-review.googlesource.com/76610
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/go/internal/load/pkg.go

index b2cfc8c26d77e9eca5a6dd024228e3cba2a75703..27684fa1f3e270897af3e4cc068c212b45eb63c8 100644 (file)
@@ -958,13 +958,23 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
 
        // Cgo translation adds imports of "runtime/cgo" and "syscall",
        // except for certain packages, to avoid circular dependencies.
-       if len(p.CgoFiles) > 0 && (!p.Standard || !cgoExclude[p.ImportPath]) {
+       if p.UsesCgo() && (!p.Standard || !cgoExclude[p.ImportPath]) {
                addImport("runtime/cgo")
        }
-       if len(p.CgoFiles) > 0 && (!p.Standard || !cgoSyscallExclude[p.ImportPath]) {
+       if p.UsesCgo() && (!p.Standard || !cgoSyscallExclude[p.ImportPath]) {
                addImport("syscall")
        }
 
+       // SWIG adds imports of some standard packages.
+       if p.UsesSwig() {
+               addImport("runtime/cgo")
+               addImport("syscall")
+               addImport("sync")
+
+               // TODO: The .swig and .swigcxx files can use
+               // %go_import directives to import other packages.
+       }
+
        // The linker loads implicit dependencies.
        if p.Name == "main" && !p.Internal.ForceLibrary {
                for _, dep := range LinkerDeps(p) {