1
0
mirror of https://github.com/golang/go synced 2024-11-26 11:58:07 -07:00

cmd/go: don't add generated SWIG C++ files to CompiledGoFiles

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>
This commit is contained in:
Ian Lance Taylor 2021-04-23 12:03:48 -07:00
parent d5d24dbe41
commit d02026414c
2 changed files with 33 additions and 2 deletions

View File

@ -246,11 +246,11 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
if p.Internal.ForceLibrary { if p.Internal.ForceLibrary {
fmt.Fprintf(h, "forcelibrary\n") 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")) fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p) cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
fmt.Fprintf(h, "CC=%q %q %q %q\n", b.ccExe(), cppflags, cflags, ldflags) 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) fmt.Fprintf(h, "CXX=%q %q\n", b.cxxExe(), cxxflags)
} }
if len(p.FFiles) > 0 { 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) 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 { if err != nil {
return err return err
} }

View File

@ -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 --