]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: only check SWIG intsize once per build
authorIan Lance Taylor <iant@golang.org>
Tue, 9 Feb 2016 14:18:43 +0000 (06:18 -0800)
committerIan Lance Taylor <iant@golang.org>
Mon, 29 Feb 2016 00:08:51 +0000 (00:08 +0000)
Besides being more efficient in a large build, this avoids a possible
race when creating the input file.

Change-Id: Ifc2cb055925a76be9c90eac56d84ebd9e14f2bbc
Reviewed-on: https://go-review.googlesource.com/19392
Reviewed-by: Michael Hudson-Doyle <michael.hudson@canonical.com>
src/cmd/go/build.go

index 89ab1c0dd4059453b31e78096f58c227228ee5ae..56101694d64067ead47997ae0c6bd72860e463df 100644 (file)
@@ -3422,6 +3422,13 @@ func (b *builder) swigVersionCheck() error {
        return swigCheck
 }
 
+// Find the value to pass for the -intgosize option to swig.
+var (
+       swigIntSizeOnce  sync.Once
+       swigIntSize      string
+       swigIntSizeError error
+)
+
 // This code fails to build if sizeof(int) <= 32
 const swigIntSizeCode = `
 package main
@@ -3429,8 +3436,8 @@ const i int = 1 << 32
 `
 
 // Determine the size of int on the target system for the -intgosize option
-// of swig >= 2.0.9
-func (b *builder) swigIntSize(obj string) (intsize string, err error) {
+// of swig >= 2.0.9.  Run only once.
+func (b *builder) swigDoIntSize(obj string) (intsize string, err error) {
        if buildN {
                return "$INTBITS", nil
        }
@@ -3448,6 +3455,15 @@ func (b *builder) swigIntSize(obj string) (intsize string, err error) {
        return "64", nil
 }
 
+// Determine the size of int on the target system for the -intgosize option
+// of swig >= 2.0.9.
+func (b *builder) swigIntSize(obj string) (intsize string, err error) {
+       swigIntSizeOnce.Do(func() {
+               swigIntSize, swigIntSizeError = b.swigDoIntSize(obj)
+       })
+       return swigIntSize, swigIntSizeError
+}
+
 // Run SWIG on one SWIG input file.
 func (b *builder) swigOne(p *Package, file, obj string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outC string, err error) {
        cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _, _ := b.cflags(p, true)