]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: don't add generated SWIG C++ files to CompiledGoFiles
authorIan Lance Taylor <iant@golang.org>
Fri, 23 Apr 2021 19:03:48 +0000 (12:03 -0700)
committerIan Lance Taylor <iant@golang.org>
Mon, 26 Apr 2021 17:52:46 +0000 (17:52 +0000)
Also include SWIG C++ files in cgo hash.

For #28749
Fixes #37098

Change-Id: I6d912db2788200c2abdf328e382d4fbefda0a9ac
Reviewed-on: https://go-review.googlesource.com/c/go/+/313131
Trust: Ian Lance Taylor <iant@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/work/exec.go
src/cmd/go/testdata/script/list_swigcxx.txt [new file with mode: 0644]

index ab9ce88c3ce535d3f3f97c5b3c4d7f3c2aaf70d5..38e826607e28fa79a1a7328bb3c41441c553e55a 100644 (file)
@@ -246,11 +246,11 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
        if p.Internal.ForceLibrary {
                fmt.Fprintf(h, "forcelibrary\n")
        }
-       if len(p.CgoFiles)+len(p.SwigFiles) > 0 {
+       if len(p.CgoFiles)+len(p.SwigFiles)+len(p.SwigCXXFiles) > 0 {
                fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
                cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
                fmt.Fprintf(h, "CC=%q %q %q %q\n", b.ccExe(), cppflags, cflags, ldflags)
-               if len(p.CXXFiles)+len(p.SwigFiles) > 0 {
+               if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 {
                        fmt.Fprintf(h, "CXX=%q %q\n", b.cxxExe(), cxxflags)
                }
                if len(p.FFiles) > 0 {
@@ -654,6 +654,10 @@ OverlayLoop:
                }
 
                outGo, outObj, err := b.cgo(a, base.Tool("cgo"), objdir, pcCFLAGS, pcLDFLAGS, mkAbsFiles(a.Package.Dir, cgofiles), gccfiles, cxxfiles, a.Package.MFiles, a.Package.FFiles)
+
+               // The files in cxxfiles have now been handled by b.cgo.
+               cxxfiles = nil
+
                if err != nil {
                        return err
                }
diff --git a/src/cmd/go/testdata/script/list_swigcxx.txt b/src/cmd/go/testdata/script/list_swigcxx.txt
new file mode 100644 (file)
index 0000000..c6acd9e
--- /dev/null
@@ -0,0 +1,27 @@
+# go list should not report SWIG-generated C++ files in CompiledGoFiles.
+
+[!exec:swig] skip
+[!exec:g++] skip
+
+# CompiledGoFiles should contain 4 files:
+#  a.go
+#  a.swigcxx.go
+#  _cgo_gotypes.go
+#  a.cgo1.go
+
+go list -f '{{.CompiledGoFiles}}' -compiled=true example/swig
+
+# These names we see here, other than a.go, will be from the build cache,
+# so we just count them.
+stdout a\.go
+stdout -count=3 $GOCACHE
+
+-- go.mod --
+module example
+
+go 1.16
+
+-- swig/a.go --
+package swig
+
+-- swig/a.swigcxx --