From d02026414cc0b292ee2aef4fbc36f185c56db0c8 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Fri, 23 Apr 2021 12:03:48 -0700 Subject: [PATCH] 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 Run-TryBot: Ian Lance Taylor Reviewed-by: Bryan C. Mills --- src/cmd/go/internal/work/exec.go | 8 ++++-- src/cmd/go/testdata/script/list_swigcxx.txt | 27 +++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) create mode 100644 src/cmd/go/testdata/script/list_swigcxx.txt diff --git a/src/cmd/go/internal/work/exec.go b/src/cmd/go/internal/work/exec.go index ab9ce88c3ce..38e826607e2 100644 --- a/src/cmd/go/internal/work/exec.go +++ b/src/cmd/go/internal/work/exec.go @@ -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 index 00000000000..c6acd9ecdba --- /dev/null +++ b/src/cmd/go/testdata/script/list_swigcxx.txt @@ -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 --