From: Ian Lance Taylor Date: Mon, 9 Nov 2015 21:31:03 +0000 (-0800) Subject: cmd/go: fix build -n when adding to archive with gc toolchain X-Git-Tag: go1.6beta1~465 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=b5c1b5d7a035d589c5a970f17b7e0c52441d5d34;p=gostls13.git cmd/go: fix build -n when adding to archive with gc toolchain Fix the output of build -n when adding to an existing archive with the gc toolchain by observing that we are, now, always doing that. When using the gc toolchain the archive is now always created by the Go compiler, and never by the pack command. No test because we have not historically tested build -n output. Fixes #13118. Change-Id: I3a5c43cf45169fa6c9581e4741309c77d2b6e58b Reviewed-on: https://go-review.googlesource.com/16761 Reviewed-by: Matthew Dempsky Reviewed-by: David Crawshaw --- diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 40e1e41e4e..13e98c4a8b 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -2264,33 +2264,26 @@ func (gcToolchain) pack(b *builder, p *Package, objDir, afile string, ofiles []s for _, f := range ofiles { absOfiles = append(absOfiles, mkAbs(objDir, f)) } - cmd := "c" absAfile := mkAbs(objDir, afile) - appending := false - if _, err := os.Stat(absAfile); err == nil { - appending = true - cmd = "r" - } - cmdline := stringList("pack", cmd, absAfile, absOfiles) + // The archive file should have been created by the compiler. + // Since it used to not work that way, verify. + if _, err := os.Stat(absAfile); err != nil { + fatalf("os.Stat of archive file failed: %v", err) + } - if appending { - if buildN || buildX { - b.showcmd(p.Dir, "%s # internal", joinUnambiguously(cmdline)) - } - if buildN { - return nil - } - if err := packInternal(b, absAfile, absOfiles); err != nil { - b.showOutput(p.Dir, p.ImportPath, err.Error()+"\n") - return errPrintedOutput - } + if buildN || buildX { + cmdline := stringList("pack", "r", absAfile, absOfiles) + b.showcmd(p.Dir, "%s # internal", joinUnambiguously(cmdline)) + } + if buildN { return nil } - - // Need actual pack. - cmdline[0] = tool("pack") - return b.run(p.Dir, p.ImportPath, nil, buildToolExec, cmdline) + if err := packInternal(b, absAfile, absOfiles); err != nil { + b.showOutput(p.Dir, p.ImportPath, err.Error()+"\n") + return errPrintedOutput + } + return nil } func packInternal(b *builder, afile string, ofiles []string) error {