From: Mohit Agarwal Date: Thu, 24 Mar 2016 17:16:10 +0000 (+0530) Subject: cmd/go: stat the archive file only when executing the commands X-Git-Tag: go1.7beta1~1092 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=edb19aa1cdc5a712d85c77a76b90f69bd9a2b673;p=gostls13.git cmd/go: stat the archive file only when executing the commands Fixes #14944 Change-Id: I73e0997cb6ebaeced1045b0ddadac893319bd78f Reviewed-on: https://go-review.googlesource.com/21065 Reviewed-by: Ian Lance Taylor Run-TryBot: Ian Lance Taylor --- diff --git a/src/cmd/go/build.go b/src/cmd/go/build.go index 08062ea9a5..01b32c30ed 100644 --- a/src/cmd/go/build.go +++ b/src/cmd/go/build.go @@ -2346,8 +2346,10 @@ func (gcToolchain) pack(b *builder, p *Package, objDir, afile string, ofiles []s // 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 !buildN { + if _, err := os.Stat(absAfile); err != nil { + fatalf("os.Stat of archive file failed: %v", err) + } } if buildN || buildX { diff --git a/src/cmd/go/go_test.go b/src/cmd/go/go_test.go index e20ec814c5..05e509d41d 100644 --- a/src/cmd/go/go_test.go +++ b/src/cmd/go/go_test.go @@ -1982,6 +1982,27 @@ func TestCoverageUsesActualSettingToOverrideEvenForRace(t *testing.T) { checkCoverage(tg, data) } +func TestBuildDryRunWithCgo(t *testing.T) { + if !canCgo { + t.Skip("skipping because cgo not enabled") + } + + tg := testgo(t) + defer tg.cleanup() + tg.tempFile("foo.go", `package main + +/* +#include +*/ +import "C" + +func main() { + println(C.INT_MAX) +}`) + tg.run("build", "-n", tg.path("foo.go")) + tg.grepStderrNot(`os.Stat .* no such file or directory`, "unexpected stat of archive file") +} + func TestCoverageWithCgo(t *testing.T) { if !canCgo { t.Skip("skipping because cgo not enabled")