]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: fix handling of vet.cfg with buggyInstall
authorIan Lance Taylor <iant@golang.org>
Tue, 17 Jul 2018 02:09:24 +0000 (19:09 -0700)
committerIan Lance Taylor <iant@golang.org>
Tue, 17 Jul 2018 05:41:06 +0000 (05:41 +0000)
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 <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
misc/cgo/testshared/shared_test.go
src/cmd/go/internal/work/action.go
src/cmd/go/internal/work/exec.go

index a2960057809117f7b3c0cb68e8dc111889e231b9..846a27173e3112f48f3126c8e6a8e03849f9cf3b 100644 (file)
@@ -905,3 +905,9 @@ func TestGlobal(t *testing.T) {
        AssertIsLinkedTo(t, "./bin/global", soname)
        AssertHasRPath(t, "./bin/global", gorootInstallDir)
 }
+
+// Run a test using -linkshared of an installed shared package.
+// Issue 26400.
+func TestTestInstalledShared(t *testing.T) {
+       goCmd(nil, "test", "-linkshared", "-test.short", "sync/atomic")
+}
index 9cbc89f32b82de138615ff5f3db1c3b86b662f34..e26f8655faaa87854c15e51e93b243d1474d7d32 100644 (file)
@@ -407,7 +407,16 @@ func (b *Builder) vetAction(mode, depMode BuildMode, p *load.Package) *Action {
                stk.Pop()
                aFmt := b.CompileAction(ModeBuild, depMode, p1)
 
-               deps := []*Action{a1, aFmt}
+               var deps []*Action
+               if a1.buggyInstall {
+                       // (*Builder).vet expects deps[0] to be the package
+                       // and deps[1] to be "fmt". If we see buggyInstall
+                       // here then a1 is an install of a shared library,
+                       // and the real package is a1.Deps[0].
+                       deps = []*Action{a1.Deps[0], aFmt, a1}
+               } else {
+                       deps = []*Action{a1, aFmt}
+               }
                for _, p1 := range load.PackageList(p.Internal.Imports) {
                        deps = append(deps, b.vetAction(mode, depMode, p1))
                }
@@ -424,7 +433,7 @@ func (b *Builder) vetAction(mode, depMode BuildMode, p *load.Package) *Action {
                        // Built-in packages like unsafe.
                        return a
                }
-               a1.needVet = true
+               deps[0].needVet = true
                a.Func = (*Builder).vet
                return a
        })
index 514d9c3867c286a96fe0ee2d689ef612a43899cd..e00b528522ea63f05af6fe378e83842902fbe0ea 100644 (file)
@@ -1368,7 +1368,9 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
        // so the built target is not in the a1.Objdir tree that b.cleanup(a1) removes.
        if a1.built == a.Target {
                a.built = a.Target
-               b.cleanup(a1)
+               if !a.buggyInstall {
+                       b.cleanup(a1)
+               }
                // Whether we're smart enough to avoid a complete rebuild
                // depends on exactly what the staleness and rebuild algorithms
                // are, as well as potentially the state of the Go build cache.
@@ -1422,7 +1424,9 @@ func BuildInstallFunc(b *Builder, a *Action) (err error) {
                }
        }
 
-       defer b.cleanup(a1)
+       if !a.buggyInstall {
+               defer b.cleanup(a1)
+       }
 
        return b.moveOrCopyFile(a.Target, a1.built, perm, false)
 }