]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix build -n when adding to archive with gc toolchain
authorIan Lance Taylor <iant@golang.org>
Mon, 9 Nov 2015 21:31:03 +0000 (13:31 -0800)
committerIan Lance Taylor <iant@golang.org>
Fri, 13 Nov 2015 14:23:27 +0000 (14:23 +0000)
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 <mdempsky@google.com>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
src/cmd/go/build.go

index 40e1e41e4e3ee1fe292d638f437eaa49ff25ae3c..13e98c4a8bed8492b444aaeef07a2014e4f8ada5 100644 (file)
@@ -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 {