From: Russ Cox Date: Fri, 1 Feb 2013 16:34:21 +0000 (-0800) Subject: cmd/go: clean cgo compiler errors X-Git-Tag: go1.1rc2~1199 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=32a6097fdea70f64e56a03709befe3adc3c70038;p=gostls13.git cmd/go: clean cgo compiler errors Cut out temporary cgo file in error message. Show C.foo instead of _Ctype_foo. Before: x.go:20[/var/folders/00/05_b8000h01000cxqpysvccm000n9d/T/go-build242036121/command-line-arguments/_obj/x.cgo1.go:19]: cannot use tv.Usec (type int32) as type _Ctype___darwin_suseconds_t in assignment After: x.go:20: cannot use tv.Usec (type int32) as type C.__darwin_suseconds_t in assignment Fixes #4255. R=golang-dev, iant CC=golang-dev https://golang.org/cl/7231075 --- diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 7bdbb09aa0..126bb465e4 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -814,11 +814,11 @@ func (b *builder) build(a *action) (err error) { // Compile Go. if len(gofiles) > 0 { - if out, err := buildToolchain.gc(b, a.p, obj, inc, gofiles); err != nil { + out, err := buildToolchain.gc(b, a.p, obj, inc, gofiles) + if err != nil { return err - } else { - objects = append(objects, out) } + objects = append(objects, out) } // Copy .h files named for goos or goarch or goos_goarch @@ -1177,6 +1177,8 @@ func relPaths(paths []string) []string { // print this error. var errPrintedOutput = errors.New("already printed output - no need to show error") +var cgoLine = regexp.MustCompile(`\[[^\[\]]+\.cgo1\.go:[0-9]+\]`) + // run runs the command given by cmdline in the directory dir. // If the command fails, run prints information about the failure // and returns a non-nil error. @@ -1189,7 +1191,16 @@ func (b *builder) run(dir string, desc string, cmdargs ...interface{}) error { if desc == "" { desc = b.fmtcmd(dir, "%s", strings.Join(stringList(cmdargs...), " ")) } - b.showOutput(dir, desc, string(out)) + out := 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. + // If we're using -x, assume we're debugging and want the full dump, so disable the rewrite. + if !buildX && cgoLine.MatchString(out) { + out = cgoLine.ReplaceAllString(out, "") + out = strings.Replace(out, "type _Ctype_", "type C.", -1) + } + b.showOutput(dir, desc, out) if err != nil { err = errPrintedOutput }