Skip to content

Commit 5d647f2

Browse files
committed
cmd/go: fix compile -p flag for building test of main package
Fixes #23180. Change-Id: I52404ee98dcc60b96972d4242c13db0ec4340d0d Reviewed-on: https://go-review.googlesource.com/86235 Run-TryBot: Russ Cox <[email protected]> Reviewed-by: Alessandro Arzilli <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent 7c2cf4e commit 5d647f2

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/cmd/go/go_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,19 @@ func TestPackageMainTestImportsArchiveNotBinary(t *testing.T) {
15891589
tg.run("test", "main_test")
15901590
}
15911591

1592+
func TestPackageMainTestCompilerFlags(t *testing.T) {
1593+
tg := testgo(t)
1594+
defer tg.cleanup()
1595+
tg.parallel()
1596+
tg.makeTempdir()
1597+
tg.setenv("GOPATH", tg.path("."))
1598+
tg.tempFile("src/p1/p1.go", "package main\n")
1599+
tg.tempFile("src/p1/p1_test.go", "package main\nimport \"testing\"\nfunc Test(t *testing.T){}\n")
1600+
tg.run("test", "-c", "-n", "p1")
1601+
tg.grepBothNot(`[\\/]compile.* -p main.*p1\.go`, "should not have run compile -p main p1.go")
1602+
tg.grepStderr(`[\\/]compile.* -p p1.*p1\.go`, "should have run compile -p p1 p1.go")
1603+
}
1604+
15921605
// The runtime version string takes one of two forms:
15931606
// "go1.X[.Y]" for Go releases, and "devel +hash" at tip.
15941607
// Determine whether we are in a released copy by

src/cmd/go/internal/work/gc.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (gcToolchain) gc(b *Builder, a *Action, archive string, importcfg []byte, a
4949
pkgpath := p.ImportPath
5050
if cfg.BuildBuildmode == "plugin" {
5151
pkgpath = pluginPath(a)
52-
} else if p.Name == "main" {
52+
} else if p.Name == "main" && !p.Internal.ForceLibrary {
5353
pkgpath = "main"
5454
}
5555
gcargs := []string{"-p", pkgpath}

0 commit comments

Comments
 (0)