Skip to content

Commit f17220c

Browse files
cmd/go: fix handling of vet.cfg with buggyInstall
The vet action assumes that a.Deps[0] is the compilation action for which vet information should be generated. However, when using -linkshared, the action graph is built with a ModeBuggyInstall action to install the shared library built from the compilation action. Adjust the set up of the vet action accordingly. Also don't clean up the working directory after completing the buggy install. Updates #26400 Change-Id: Ia51f9f6b8cde5614a6f2e41b6207478951547770 Reviewed-on: https://go-review.googlesource.com/124275 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 0c319ee commit f17220c

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

misc/cgo/testshared/shared_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -905,3 +905,9 @@ func TestGlobal(t *testing.T) {
905905
AssertIsLinkedTo(t, "./bin/global", soname)
906906
AssertHasRPath(t, "./bin/global", gorootInstallDir)
907907
}
908+
909+
// Run a test using -linkshared of an installed shared package.
910+
// Issue 26400.
911+
func TestTestInstalledShared(t *testing.T) {
912+
goCmd(nil, "test", "-linkshared", "-test.short", "sync/atomic")
913+
}

src/cmd/go/internal/work/action.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,16 @@ func (b *Builder) vetAction(mode, depMode BuildMode, p *load.Package) *Action {
407407
stk.Pop()
408408
aFmt := b.CompileAction(ModeBuild, depMode, p1)
409409

410-
deps := []*Action{a1, aFmt}
410+
var deps []*Action
411+
if a1.buggyInstall {
412+
// (*Builder).vet expects deps[0] to be the package
413+
// and deps[1] to be "fmt". If we see buggyInstall
414+
// here then a1 is an install of a shared library,
415+
// and the real package is a1.Deps[0].
416+
deps = []*Action{a1.Deps[0], aFmt, a1}
417+
} else {
418+
deps = []*Action{a1, aFmt}
419+
}
411420
for _, p1 := range load.PackageList(p.Internal.Imports) {
412421
deps = append(deps, b.vetAction(mode, depMode, p1))
413422
}
@@ -424,7 +433,7 @@ func (b *Builder) vetAction(mode, depMode BuildMode, p *load.Package) *Action {
424433
// Built-in packages like unsafe.
425434
return a
426435
}
427-
a1.needVet = true
436+
deps[0].needVet = true
428437
a.Func = (*Builder).vet
429438
return a
430439
})

src/cmd/go/internal/work/exec.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,9 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
13681368
// so the built target is not in the a1.Objdir tree that b.cleanup(a1) removes.
13691369
if a1.built == a.Target {
13701370
a.built = a.Target
1371-
b.cleanup(a1)
1371+
if !a.buggyInstall {
1372+
b.cleanup(a1)
1373+
}
13721374
// Whether we're smart enough to avoid a complete rebuild
13731375
// depends on exactly what the staleness and rebuild algorithms
13741376
// are, as well as potentially the state of the Go build cache.
@@ -1422,7 +1424,9 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
14221424
}
14231425
}
14241426

1425-
defer b.cleanup(a1)
1427+
if !a.buggyInstall {
1428+
defer b.cleanup(a1)
1429+
}
14261430

14271431
return b.moveOrCopyFile(a.Target, a1.built, perm, false)
14281432
}

0 commit comments

Comments
 (0)