Commit b5c1b5d7 authored by Ian Lance Taylor's avatar Ian Lance Taylor

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/16761Reviewed-by: default avatarMatthew Dempsky <mdempsky@google.com>
Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 51fed716
......@@ -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 {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment