]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix cgo error output rewrite
authorShenghou Ma <minux.ma@gmail.com>
Thu, 13 Feb 2014 20:55:14 +0000 (15:55 -0500)
committerShenghou Ma <minux.ma@gmail.com>
Thu, 13 Feb 2014 20:55:14 +0000 (15:55 -0500)
for example, we now rewrite *_Ctype_int to *C.int.
Fixes #6781.

LGTM=iant
R=golang-codereviews, rsc, iant
CC=golang-codereviews
https://golang.org/cl/36860043

src/cmd/go/build.go

index 283e9c3aee85d7a3d1037c74b0d97eee5671fc83..5ffb9d9f3e1777a0a5913801dceda869d59340cc 100644 (file)
@@ -1302,6 +1302,7 @@ func relPaths(paths []string) []string {
 var errPrintedOutput = errors.New("already printed output - no need to show error")
 
 var cgoLine = regexp.MustCompile(`\[[^\[\]]+\.cgo1\.go:[0-9]+\]`)
+var cgoTypeSigRe = regexp.MustCompile(`\b_Ctype_\B`)
 
 // run runs the command given by cmdline in the directory dir.
 // If the command fails, run prints information about the failure
@@ -1328,11 +1329,11 @@ func (b *builder) processOutput(out []byte) string {
        messages := string(out)
        // Fix up output referring to cgo-generated code to be more readable.
        // Replace x.go:19[/tmp/.../x.cgo1.go:18] with x.go:19.
-       // Replace _Ctype_foo with C.foo.
+       // Replace *[100]_Ctype_foo with *[100]C.foo.
        // If we're using -x, assume we're debugging and want the full dump, so disable the rewrite.
        if !buildX && cgoLine.MatchString(messages) {
                messages = cgoLine.ReplaceAllString(messages, "")
-               messages = strings.Replace(messages, "type _Ctype_", "type C.", -1)
+               messages = cgoTypeSigRe.ReplaceAllString(messages, "C.")
        }
        return messages
 }