]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix a bug printing error output from c compiler
authorMichael Matloob <matloob@golang.org>
Thu, 3 Nov 2022 17:18:13 +0000 (13:18 -0400)
committerMichael Matloob <matloob@golang.org>
Thu, 3 Nov 2022 20:32:06 +0000 (20:32 +0000)
fmt.Sprint should be called instead of fmt.Sprintf as is done
elsewhere in exec.go

Change-Id: I730c1f02238fccb24323701b587d3bf1391c9f62
Reviewed-on: https://go-review.googlesource.com/c/go/+/447656
Run-TryBot: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>

src/cmd/go/internal/work/exec.go
src/cmd/go/internal/work/gc.go
src/cmd/go/testdata/script/build_cgo_error.txt [new file with mode: 0644]

index 30f8f9540b40ee89326eb247bcdbfb21ba37cb91..746649f5d92c5c51ece5b3e89d72393151b8ecb7 100644 (file)
@@ -848,7 +848,8 @@ OverlayLoop:
                }
 
                if err != nil {
-                       return errors.New(fmt.Sprint(formatOutput(b.WorkDir, p.Dir, p.Desc(), output)))
+                       prefix, suffix := formatOutput(b.WorkDir, p.Dir, p.Desc(), output)
+                       return errors.New(prefix + suffix)
                } else {
                        b.showOutput(a, p.Dir, p.Desc(), output)
                }
@@ -2153,7 +2154,8 @@ func (b *Builder) run(a *Action, dir string, desc string, env []string, cmdargs
                        desc = b.fmtcmd(dir, "%s", strings.Join(str.StringList(cmdargs...), " "))
                }
                if err != nil {
-                       err = errors.New(fmt.Sprint(formatOutput(b.WorkDir, dir, desc, b.processOutput(out))))
+                       prefix, suffix := formatOutput(b.WorkDir, dir, desc, b.processOutput(out))
+                       err = errors.New(prefix + suffix)
                } else {
                        b.showOutput(a, dir, desc, b.processOutput(out))
                }
@@ -2500,7 +2502,8 @@ func (b *Builder) ccompile(a *Action, p *load.Package, outfile string, flags []s
                }
 
                if err != nil || os.Getenv("GO_BUILDER_NAME") != "" {
-                       err = errors.New(fmt.Sprintf(formatOutput(b.WorkDir, p.Dir, desc, b.processOutput(output))))
+                       prefix, suffix := formatOutput(b.WorkDir, p.Dir, desc, b.processOutput(output))
+                       err = errors.New(prefix + suffix)
                } else {
                        b.showOutput(a, p.Dir, desc, b.processOutput(output))
                }
@@ -3424,7 +3427,8 @@ func (b *Builder) swigOne(a *Action, p *load.Package, file, objdir string, pcCFL
                                return "", "", errors.New("must have SWIG version >= 3.0.6")
                        }
                        // swig error
-                       return "", "", errors.New(fmt.Sprint(formatOutput(b.WorkDir, p.Dir, p.Desc(), b.processOutput(out))))
+                       prefix, suffix := formatOutput(b.WorkDir, p.Dir, p.Desc(), b.processOutput(out))
+                       return "", "", errors.New(prefix + suffix)
                }
                return "", "", err
        }
index e87f048a0710b413ab71547ae2050cae045783d6..de32ad915863cccfaa44bc1b0c42cd41718e1e0e 100644 (file)
@@ -507,7 +507,8 @@ func (gcToolchain) pack(b *Builder, a *Action, afile string, ofiles []string) er
                return nil
        }
        if err := packInternal(absAfile, absOfiles); err != nil {
-               return errors.New(fmt.Sprint(formatOutput(b.WorkDir, p.Dir, p.Desc(), err.Error()+"\n")))
+               prefix, suffix := formatOutput(b.WorkDir, p.Dir, p.Desc(), err.Error()+"\n")
+               return errors.New(prefix + suffix)
        }
        return nil
 }
diff --git a/src/cmd/go/testdata/script/build_cgo_error.txt b/src/cmd/go/testdata/script/build_cgo_error.txt
new file mode 100644 (file)
index 0000000..c11ab46
--- /dev/null
@@ -0,0 +1,17 @@
+[short] skip
+[!cgo] skip
+
+! go build .
+stderr '# foo\nfoo.c:'
+! stderr 'EXTRA string'
+
+-- go.mod --
+module foo
+
+go 1.20
+-- foo.go --
+package foo
+
+import "C"
+-- foo.c --
+#include "doesnotexist.h"
\ No newline at end of file