Last active
August 29, 2015 14:12
-
-
Save minux/13f18a1735f51edeaf7e to your computer and use it in GitHub Desktop.
Issue 9410
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
See https://golang.org/issue/9410 | |
To be used with https://github.com/minux/swig/tree/go1.5. | |
diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go | |
index e201f29..3ae2f86 100644 | |
--- a/src/cmd/go/build.go | |
+++ b/src/cmd/go/build.go | |
@@ -1827,7 +1827,7 @@ func (gcToolchain) ld(b *builder, p *Package, out string, allactions []*action, | |
} | |
func (gcToolchain) cc(b *builder, p *Package, objdir, ofile, cfile string) error { | |
- return fmt.Errorf("%s: C source files not supported without cgo", mkAbs(p.Dir, cfile)) | |
+ return fmt.Errorf("%s: C source files not supported without cgo/swig", mkAbs(p.Dir, cfile)) | |
} | |
// The Gccgo toolchain. | |
@@ -2430,30 +2430,24 @@ func (b *builder) swig(p *Package, obj string, pcCFLAGS, gccfiles, gxxfiles, mfi | |
} | |
for _, f := range p.SwigFiles { | |
- goFile, objFile, gccObjFile, err := b.swigOne(p, f, obj, pcCFLAGS, false, intgosize) | |
+ goFiles, gccObjFile, err := b.swigOne(p, f, obj, pcCFLAGS, false, intgosize) | |
if err != nil { | |
return nil, nil, err | |
} | |
- if goFile != "" { | |
- outGo = append(outGo, goFile) | |
- } | |
- if objFile != "" { | |
- outObj = append(outObj, objFile) | |
+ if len(goFiles) > 0 { | |
+ outGo = append(outGo, goFiles...) | |
} | |
if gccObjFile != "" { | |
outObj = append(outObj, gccObjFile) | |
} | |
} | |
for _, f := range p.SwigCXXFiles { | |
- goFile, objFile, gccObjFile, err := b.swigOne(p, f, obj, pcCFLAGS, true, intgosize) | |
+ goFiles, gccObjFile, err := b.swigOne(p, f, obj, pcCFLAGS, true, intgosize) | |
if err != nil { | |
return nil, nil, err | |
} | |
- if goFile != "" { | |
- outGo = append(outGo, goFile) | |
- } | |
- if objFile != "" { | |
- outObj = append(outObj, objFile) | |
+ if len(goFiles) > 0 { | |
+ outGo = append(outGo, goFiles...) | |
} | |
if gccObjFile != "" { | |
outObj = append(outObj, gccObjFile) | |
@@ -2524,7 +2518,7 @@ func (b *builder) swigIntSize(obj string) (intsize string, err error) { | |
} | |
// Run SWIG on one SWIG input file. | |
-func (b *builder) swigOne(p *Package, file, obj string, pcCFLAGS []string, cxx bool, intgosize string) (outGo, outObj, objGccObj string, err error) { | |
+func (b *builder) swigOne(p *Package, file, obj string, pcCFLAGS []string, cxx bool, intgosize string) (outGo []string, objGccObj string, err error) { | |
cgoCPPFLAGS, cgoCFLAGS, cgoCXXFLAGS, _ := b.cflags(p, true) | |
var cflags []string | |
if cxx { | |
@@ -2539,7 +2533,7 @@ func (b *builder) swigOne(p *Package, file, obj string, pcCFLAGS []string, cxx b | |
} | |
base := file[:len(file)-n] | |
goFile := base + ".go" | |
- cBase := base + "_gc." | |
+ goBase := base + "_gc.go" | |
gccBase := base + "_wrap." | |
gccExt := "c" | |
if cxx { | |
@@ -2576,36 +2570,32 @@ func (b *builder) swigOne(p *Package, file, obj string, pcCFLAGS []string, cxx b | |
if out, err := b.runOut(p.Dir, p.ImportPath, nil, "swig", args, file); err != nil { | |
if len(out) > 0 { | |
if bytes.Contains(out, []byte("Unrecognized option -intgosize")) { | |
- return "", "", "", errors.New("must have SWIG version >= 3.0") | |
+ return nil, "", errors.New("must have SWIG version >= 3.0") | |
} | |
b.showOutput(p.Dir, p.ImportPath, b.processOutput(out)) | |
- return "", "", "", errPrintedOutput | |
+ return nil, "", errPrintedOutput | |
} | |
- return "", "", "", err | |
+ return nil, "", err | |
} | |
- var cObj string | |
+ goFiles := []string{obj + goFile} | |
if !gccgo { | |
- // cc | |
- cObj = obj + cBase + archChar | |
- if err := buildToolchain.cc(b, p, obj, cObj, obj+cBase+"c"); err != nil { | |
- return "", "", "", err | |
- } | |
+ goFiles = append(goFiles, obj+goBase) | |
} | |
// gcc | |
gccObj := obj + gccBase + "o" | |
if !cxx { | |
if err := b.gcc(p, gccObj, cflags, obj+gccBase+gccExt); err != nil { | |
- return "", "", "", err | |
+ return nil, "", err | |
} | |
} else { | |
if err := b.gxx(p, gccObj, cflags, obj+gccBase+gccExt); err != nil { | |
- return "", "", "", err | |
+ return nil, "", err | |
} | |
} | |
- return obj + goFile, cObj, gccObj, nil | |
+ return goFiles, gccObj, nil | |
} | |
// An actionQueue is a priority queue of actions. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My full test script: