mirror of
https://github.com/golang/go
synced 2024-11-22 11:14:47 -07:00
cmd/go: only try to clean executables for package main
Fixes #5665. R=golang-dev, r CC=golang-dev https://golang.org/cl/12807044
This commit is contained in:
parent
c974b8b6ac
commit
2f6e9a1e24
@ -137,22 +137,38 @@ func clean(p *Package) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
_, elem := filepath.Split(p.Dir)
|
_, elem := filepath.Split(p.Dir)
|
||||||
allRemove := []string{
|
var allRemove []string
|
||||||
elem,
|
|
||||||
elem + ".exe",
|
// Remove dir-named executable only if this is package main.
|
||||||
elem + ".test",
|
if p.Name == "main" {
|
||||||
elem + ".test.exe",
|
allRemove = append(allRemove,
|
||||||
|
elem,
|
||||||
|
elem+".exe",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove package test executables.
|
||||||
|
allRemove = append(allRemove,
|
||||||
|
elem+".test",
|
||||||
|
elem+".test.exe",
|
||||||
|
)
|
||||||
|
|
||||||
|
// Remove a potental executable for each .go file in the directory that
|
||||||
|
// is not part of the directory's package.
|
||||||
for _, dir := range dirs {
|
for _, dir := range dirs {
|
||||||
name := dir.Name()
|
name := dir.Name()
|
||||||
if packageFile[name] {
|
if packageFile[name] {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !dir.IsDir() && strings.HasSuffix(name, ".go") {
|
if !dir.IsDir() && strings.HasSuffix(name, ".go") {
|
||||||
|
// TODO(adg,rsc): check that this .go file is actually
|
||||||
|
// in "package main", and therefore capable of building
|
||||||
|
// to an executable file.
|
||||||
base := name[:len(name)-len(".go")]
|
base := name[:len(name)-len(".go")]
|
||||||
allRemove = append(allRemove, base, base+".exe")
|
allRemove = append(allRemove, base, base+".exe")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if cleanN || cleanX {
|
if cleanN || cleanX {
|
||||||
b.showcmd(p.Dir, "rm -f %s", strings.Join(allRemove, " "))
|
b.showcmd(p.Dir, "rm -f %s", strings.Join(allRemove, " "))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user