cmd/go: drop runtime, runtime/internal/sys, runtime/internal/atomic, unsafe as deps of everything

This was a hack to make a new make.bash avoid reusing installed packages.
The new content-based staleness is precise enough not to need this hack;
now it's just causing unnecessary rebuilds: if a package doesn't import "runtime",
for example, it doesn't need to be recompiled when runtime changes.
(It does need to be relinked, and we still arrange that.)

Change-Id: I4ddf6e16d754cf21b16e9db1ed52bddbf82e96c6
Reviewed-on: https://go-review.googlesource.com/76015
Run-TryBot: Russ Cox <rsc@golang.org>
Reviewed-by: David Crawshaw <crawshaw@golang.org>
This commit is contained in:
Russ Cox 2017-11-05 16:22:02 -05:00
parent da109c6075
commit f3c46355d7
3 changed files with 34 additions and 52 deletions

View File

@ -3295,12 +3295,12 @@ func TestGoInstallPkgdir(t *testing.T) {
defer tg.cleanup() defer tg.cleanup()
tg.makeTempdir() tg.makeTempdir()
pkg := tg.path(".") pkg := tg.path(".")
tg.run("install", "-pkgdir", pkg, "errors") tg.run("install", "-pkgdir", pkg, "sync")
tg.mustExist(filepath.Join(pkg, "errors.a")) tg.mustExist(filepath.Join(pkg, "sync.a"))
tg.mustNotExist(filepath.Join(pkg, "runtime.a")) tg.mustNotExist(filepath.Join(pkg, "sync/atomic.a"))
tg.run("install", "-i", "-pkgdir", pkg, "errors") tg.run("install", "-i", "-pkgdir", pkg, "sync")
tg.mustExist(filepath.Join(pkg, "errors.a")) tg.mustExist(filepath.Join(pkg, "sync.a"))
tg.mustExist(filepath.Join(pkg, "runtime.a")) tg.mustExist(filepath.Join(pkg, "sync/atomic.a"))
} }
func TestGoTestRaceInstallCgo(t *testing.T) { func TestGoTestRaceInstallCgo(t *testing.T) {
@ -3611,15 +3611,6 @@ func TestGoBuildARM(t *testing.T) {
tg.grepStderrNot("unable to find math.a", "did not build math.a correctly") tg.grepStderrNot("unable to find math.a", "did not build math.a correctly")
} }
func TestIssue13655(t *testing.T) {
tg := testgo(t)
defer tg.cleanup()
for _, pkg := range []string{"runtime", "runtime/internal/atomic"} {
tg.run("list", "-f", "{{.Deps}}", pkg)
tg.grepStdout("runtime/internal/sys", "did not find required dependency of "+pkg+" on runtime/internal/sys")
}
}
// For issue 14337. // For issue 14337.
func TestParallelTest(t *testing.T) { func TestParallelTest(t *testing.T) {
tg := testgo(t) tg := testgo(t)
@ -4726,12 +4717,16 @@ func TestBuildCache(t *testing.T) {
tg.makeTempdir() tg.makeTempdir()
tg.setenv("GOCACHE", tg.tempdir) tg.setenv("GOCACHE", tg.tempdir)
// complex/x is a trivial non-main package. // complex/w is a trivial non-main package.
// It imports nothing, so there should be no Deps.
tg.run("list", "-f={{join .Deps \" \"}}", "complex/w")
tg.grepStdoutNot(".+", "complex/w depends on unexpected packages")
tg.run("build", "-x", "complex/w") tg.run("build", "-x", "complex/w")
tg.grepStderr(`[\\/]compile|gccgo`, "did not run compiler") tg.grepStderr(`[\\/]compile|gccgo`, "did not run compiler")
tg.run("build", "-x", "complex/w") tg.run("build", "-x", "complex/w")
tg.grepStderrNot(`[\\/]compile|gccgo`, "did not run compiler") tg.grepStderrNot(`[\\/]compile|gccgo`, "ran compiler incorrectly")
// complex is a non-trivial main package. // complex is a non-trivial main package.
// the link step should not be cached. // the link step should not be cached.

View File

@ -946,26 +946,6 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
} }
} }
// If runtime/internal/sys/zversion.go changes, it very likely means the
// compiler has been recompiled with that new version, so all existing
// archives are now stale. Make everything appear to import runtime/internal/sys,
// so that in this situation everything will appear stale and get recompiled.
// Due to the rules for visibility of internal packages, things outside runtime
// must import runtime, and runtime imports runtime/internal/sys.
// Content-based staleness that includes a check of the compiler version
// will make this hack unnecessary; once that lands, this whole comment
// and switch statement should be removed.
switch {
case p.Standard && p.ImportPath == "runtime/internal/sys":
// nothing
case p.Standard && p.ImportPath == "unsafe":
// nothing - not a real package, and used by runtime
case p.Standard && strings.HasPrefix(p.ImportPath, "runtime"):
addImport("runtime/internal/sys")
default:
addImport("runtime")
}
// Check for case-insensitive collision of input files. // Check for case-insensitive collision of input files.
// To avoid problems on case-insensitive files, we reject any package // To avoid problems on case-insensitive files, we reject any package
// where two different input files have equal names under a case-insensitive // where two different input files have equal names under a case-insensitive
@ -1117,9 +1097,10 @@ func (p *Package) load(stk *ImportStack, bp *build.Package, err error) {
} }
} }
// LinkerDeps returns the list of linker-induced dependencies for p. // LinkerDeps returns the list of linker-induced dependencies for main package p.
func LinkerDeps(p *Package) []string { func LinkerDeps(p *Package) []string {
var deps []string // Everything links runtime.
deps := []string{"runtime"}
// External linking mode forces an import of runtime/cgo. // External linking mode forces an import of runtime/cgo.
if cfg.ExternalLinkingForced() { if cfg.ExternalLinkingForced() {

View File

@ -627,10 +627,18 @@ func (b *Builder) linkSharedAction(mode, depMode BuildMode, shlib string, a1 *Ac
// TODO(rsc): Find out and explain here why gccgo is excluded. // TODO(rsc): Find out and explain here why gccgo is excluded.
// If the answer is that gccgo is different in implicit linker deps, maybe // If the answer is that gccgo is different in implicit linker deps, maybe
// load.LinkerDeps should be used and updated. // load.LinkerDeps should be used and updated.
// Link packages into a shared library.
a := &Action{
Mode: "go build -buildmode=shared",
Objdir: b.NewObjdir(),
Func: (*Builder).linkShared,
Deps: []*Action{a1},
}
a.Target = filepath.Join(a.Objdir, shlib)
if cfg.BuildToolchainName != "gccgo" { if cfg.BuildToolchainName != "gccgo" {
add := func(pkg string) { add := func(a1 *Action, pkg string, force bool) {
for _, a2 := range a1.Deps { for _, a2 := range a1.Deps {
if a2.Package.ImportPath == pkg { if a2.Package != nil && a2.Package.ImportPath == pkg {
return return
} }
} }
@ -644,23 +652,21 @@ func (b *Builder) linkSharedAction(mode, depMode BuildMode, shlib string, a1 *Ac
// then that shared library also contains runtime, // then that shared library also contains runtime,
// so that anything we do will depend on that library, // so that anything we do will depend on that library,
// so we don't need to include pkg in our shared library. // so we don't need to include pkg in our shared library.
if p.Shlib == "" || filepath.Base(p.Shlib) == pkg { if force || p.Shlib == "" || filepath.Base(p.Shlib) == pkg {
a1.Deps = append(a1.Deps, b.CompileAction(depMode, depMode, p)) a1.Deps = append(a1.Deps, b.CompileAction(depMode, depMode, p))
} }
} }
add("runtime/cgo") add(a1, "runtime/cgo", false)
if cfg.Goarch == "arm" { if cfg.Goarch == "arm" {
add("math") add(a1, "math", false)
}
// The linker step still needs all the usual linker deps.
// (For example, the linker always opens runtime.a.)
for _, dep := range load.LinkerDeps(nil) {
add(a, dep, true)
} }
} }
// Link packages into a shared library.
a := &Action{
Mode: "go build -buildmode=shared",
Objdir: b.NewObjdir(),
Func: (*Builder).linkShared,
Deps: []*Action{a1},
}
a.Target = filepath.Join(a.Objdir, shlib)
b.addTransitiveLinkDeps(a, a1, shlib) b.addTransitiveLinkDeps(a, a1, shlib)
return a return a
}) })