diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go index 1bf178d0ad54e1b1dc5b064e72783def9f9457c8..d920db9b886f004466b9ae9d803bc396ddabfee9 100644 --- a/src/cmd/dist/build.go +++ b/src/cmd/dist/build.go @@ -614,33 +614,6 @@ func mustLinkExternal(goos, goarch string, cgoEnabled bool) bool { return false } -// deptab lists changes to the default dependencies for a given prefix. -// deps ending in /* read the whole directory; deps beginning with - -// exclude files with that prefix. -// Note that this table applies only to the build of cmd/go, -// after the main compiler bootstrap. -// Files listed here should also be listed in ../distpack/pack.go's srcArch.Remove list. -var deptab = []struct { - prefix string // prefix of target - dep []string // dependency tweaks for targets with that prefix -}{ - {"cmd/go/internal/cfg", []string{ - "zdefaultcc.go", - }}, - {"go/build", []string{ - "zcgo.go", - }}, - {"internal/platform", []string{ - "zosarch.go", - }}, - {"runtime/internal/sys", []string{ - "zversion.go", - }}, - {"time/tzdata", []string{ - "zzipdata.go", - }}, -} - // depsuffix records the allowed suffixes for source files. var depsuffix = []string{ ".s", @@ -648,15 +621,17 @@ var depsuffix = []string{ } // gentab records how to generate some trivial files. +// Files listed here should also be listed in ../distpack/pack.go's srcArch.Remove list. var gentab = []struct { - nameprefix string - gen func(string, string) + pkg string // Relative to $GOROOT/src + file string + gen func(dir, file string) }{ - {"zcgo.go", mkzcgo}, - {"zdefaultcc.go", mkzdefaultcc}, - {"zosarch.go", mkzosarch}, - {"zversion.go", mkzversion}, - {"zzipdata.go", mktzdata}, + {"go/build", "zcgo.go", mkzcgo}, + {"cmd/go/internal/cfg", "zdefaultcc.go", mkzdefaultcc}, + {"internal/platform", "zosarch.go", mkzosarch}, + {"runtime/internal/sys", "zversion.go", mkzversion}, + {"time/tzdata", "zzipdata.go", mktzdata}, } // installed maps from a dir name (as given to install) to a chan @@ -680,7 +655,7 @@ func startInstall(dir string) chan struct{} { return ch } -// runInstall installs the library, package, or binary associated with dir, +// runInstall installs the library, package, or binary associated with pkg, // which is relative to $GOROOT/src. func runInstall(pkg string, ch chan struct{}) { if pkg == "net" || pkg == "os/user" || pkg == "crypto/x509" { @@ -767,12 +742,10 @@ func runInstall(pkg string, ch chan struct{}) { return !strings.HasPrefix(p, ".") && (!strings.HasPrefix(p, "_") || !strings.HasSuffix(p, ".go")) }) - for _, dt := range deptab { - if pkg == dt.prefix || strings.HasSuffix(dt.prefix, "/") && strings.HasPrefix(pkg, dt.prefix) { - for _, p := range dt.dep { - p = os.ExpandEnv(p) - files = append(files, p) - } + // Add generated files for this package. + for _, gt := range gentab { + if gt.pkg == pkg { + files = append(files, gt.file) } } files = uniq(files) @@ -785,7 +758,7 @@ func runInstall(pkg string, ch chan struct{}) { } // Is the target up-to-date? - var gofiles, sfiles, missing []string + var gofiles, sfiles []string stale := rebuildall files = filter(files, func(p string) bool { for _, suf := range depsuffix { @@ -807,9 +780,6 @@ func runInstall(pkg string, ch chan struct{}) { if t.After(ttarg) { stale = true } - if t.IsZero() { - missing = append(missing, p) - } return true }) @@ -837,32 +807,22 @@ func runInstall(pkg string, ch chan struct{}) { } // Generate any missing files; regenerate existing ones. - for _, p := range files { - elem := filepath.Base(p) - for _, gt := range gentab { - if gt.gen == nil { - continue - } - if strings.HasPrefix(elem, gt.nameprefix) { - if vflag > 1 { - errprintf("generate %s\n", p) - } - gt.gen(dir, p) - // Do not add generated file to clean list. - // In runtime, we want to be able to - // build the package with the go tool, - // and it assumes these generated files already - // exist (it does not know how to build them). - // The 'clean' command can remove - // the generated files. - goto built - } + for _, gt := range gentab { + if gt.pkg != pkg { + continue } - // Did not rebuild p. - if find(p, missing) >= 0 { - fatalf("missing file %s", p) + p := pathf("%s/%s", dir, gt.file) + if vflag > 1 { + errprintf("generate %s\n", p) } - built: + gt.gen(dir, p) + // Do not add generated file to clean list. + // In runtime, we want to be able to + // build the package with the go tool, + // and it assumes these generated files already + // exist (it does not know how to build them). + // The 'clean' command can remove + // the generated files. } // Resolve imported packages to actual package paths. @@ -1186,26 +1146,11 @@ var runtimegen = []string{ "zversion.go", } -// cleanlist is a list of packages with generated files and commands. -var cleanlist = []string{ - "runtime/internal/sys", - "cmd/cgo", - "cmd/go/internal/cfg", - "internal/platform", - "go/build", -} - func clean() { - for _, name := range cleanlist { - path := pathf("%s/src/%s", goroot, name) - // Remove generated files. - for _, elem := range xreaddir(path) { - for _, gt := range gentab { - if strings.HasPrefix(elem, gt.nameprefix) { - xremove(pathf("%s/%s", path, elem)) - } - } - } + // Remove generated files. + for _, gt := range gentab { + path := pathf("%s/src/%s/%s", goroot, gt.pkg, gt.file) + xremove(path) } // remove runtimegen files. diff --git a/src/cmd/distpack/pack.go b/src/cmd/distpack/pack.go index 55e07f88c331215bfd4684739269ec6f874b6217..cddbd0747dd0256b24a5fd7fb13c6c33adf9ba2d 100644 --- a/src/cmd/distpack/pack.go +++ b/src/cmd/distpack/pack.go @@ -113,7 +113,7 @@ func main() { "bin/**", "pkg/**", - // Generated during cmd/dist. See ../dist/build.go:/deptab. + // Generated during cmd/dist. See ../dist/build.go:/gentab. "src/cmd/go/internal/cfg/zdefaultcc.go", "src/go/build/zcgo.go", "src/internal/platform/zosarch.go",