Skip to content

Commit d020264

Browse files
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 <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent d5d24db commit d020264

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/cmd/go/internal/work/exec.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -246,11 +246,11 @@ func (b *Builder) buildActionID(a *Action) cache.ActionID {
246246
if p.Internal.ForceLibrary {
247247
fmt.Fprintf(h, "forcelibrary\n")
248248
}
249-
if len(p.CgoFiles)+len(p.SwigFiles) > 0 {
249+
if len(p.CgoFiles)+len(p.SwigFiles)+len(p.SwigCXXFiles) > 0 {
250250
fmt.Fprintf(h, "cgo %q\n", b.toolID("cgo"))
251251
cppflags, cflags, cxxflags, fflags, ldflags, _ := b.CFlags(p)
252252
fmt.Fprintf(h, "CC=%q %q %q %q\n", b.ccExe(), cppflags, cflags, ldflags)
253-
if len(p.CXXFiles)+len(p.SwigFiles) > 0 {
253+
if len(p.CXXFiles)+len(p.SwigCXXFiles) > 0 {
254254
fmt.Fprintf(h, "CXX=%q %q\n", b.cxxExe(), cxxflags)
255255
}
256256
if len(p.FFiles) > 0 {
@@ -654,6 +654,10 @@ OverlayLoop:
654654
}
655655

656656
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)
657+
658+
// The files in cxxfiles have now been handled by b.cgo.
659+
cxxfiles = nil
660+
657661
if err != nil {
658662
return err
659663
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# go list should not report SWIG-generated C++ files in CompiledGoFiles.
2+
3+
[!exec:swig] skip
4+
[!exec:g++] skip
5+
6+
# CompiledGoFiles should contain 4 files:
7+
# a.go
8+
# a.swigcxx.go
9+
# _cgo_gotypes.go
10+
# a.cgo1.go
11+
12+
go list -f '{{.CompiledGoFiles}}' -compiled=true example/swig
13+
14+
# These names we see here, other than a.go, will be from the build cache,
15+
# so we just count them.
16+
stdout a\.go
17+
stdout -count=3 $GOCACHE
18+
19+
-- go.mod --
20+
module example
21+
22+
go 1.16
23+
24+
-- swig/a.go --
25+
package swig
26+
27+
-- swig/a.swigcxx --

0 commit comments

Comments
 (0)