Skip to content

Commit 8f98931

Browse files
cmd/go: initialize in get before loading packages
Otherwise the packages will not pick up the way that -installsuffix is changed by -buildmode and -race. Fixes #20512. Change-Id: Ieca32c958a531beb6331dff30d7e9a4998867dbb Reviewed-on: https://go-review.googlesource.com/44630 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Russ Cox <[email protected]>
1 parent a38c8df commit 8f98931

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

src/cmd/go/go_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3159,6 +3159,20 @@ func TestGoGetUpdate(t *testing.T) {
31593159
tg.run("get", "-d", "-u", "github.com/rsc/go-get-issue-9224-cmd")
31603160
}
31613161

3162+
// Issue #20512.
3163+
func TestGoGetRace(t *testing.T) {
3164+
testenv.MustHaveExternalNetwork(t)
3165+
if !canRace {
3166+
t.Skip("skipping because race detector not supported")
3167+
}
3168+
3169+
tg := testgo(t)
3170+
defer tg.cleanup()
3171+
tg.makeTempdir()
3172+
tg.setenv("GOPATH", tg.path("."))
3173+
tg.run("get", "-race", "github.com/rsc/go-get-issue-9224-cmd")
3174+
}
3175+
31623176
func TestGoGetDomainRoot(t *testing.T) {
31633177
// golang.org/issue/9357.
31643178
// go get foo.io (not foo.io/subdir) was not working consistently.

src/cmd/go/internal/get/get.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ func init() {
9090
}
9191

9292
func runGet(cmd *base.Command, args []string) {
93+
work.InstrumentInit()
94+
work.BuildModeInit()
95+
9396
if *getF && !*getU {
9497
base.Fatalf("go get: cannot use -f flag without -u")
9598
}

src/cmd/go/internal/work/build.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,8 @@ func libname(args []string, pkgs []*load.Package) (string, error) {
545545
}
546546

547547
func runInstall(cmd *base.Command, args []string) {
548+
InstrumentInit()
549+
BuildModeInit()
548550
InstallPackages(args, false)
549551
}
550552

@@ -553,8 +555,6 @@ func InstallPackages(args []string, forGet bool) {
553555
base.Fatalf("cannot install, GOBIN must be an absolute path")
554556
}
555557

556-
InstrumentInit()
557-
BuildModeInit()
558558
pkgs := pkgsFilter(load.PackagesForBuild(args))
559559

560560
for _, p := range pkgs {

0 commit comments

Comments
 (0)