]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: only try to clean executables for package main
authorAndrew Gerrand <adg@golang.org>
Mon, 19 Aug 2013 06:22:33 +0000 (16:22 +1000)
committerAndrew Gerrand <adg@golang.org>
Mon, 19 Aug 2013 06:22:33 +0000 (16:22 +1000)
Fixes #5665.

R=golang-dev, r
CC=golang-dev
https://golang.org/cl/12807044

src/cmd/go/clean.go

index 8345c9af15e9c247f90c67d68b932614277b1988..bfae967a76b6632a8f1027c039d18d53a3373ad1 100644 (file)
@@ -137,22 +137,38 @@ func clean(p *Package) {
        }
 
        _, elem := filepath.Split(p.Dir)
-       allRemove := []string{
-               elem,
-               elem + ".exe",
-               elem + ".test",
-               elem + ".test.exe",
+       var allRemove []string
+
+       // Remove dir-named executable only if this is package main.
+       if p.Name == "main" {
+               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 {
                name := dir.Name()
                if packageFile[name] {
                        continue
                }
                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")]
                        allRemove = append(allRemove, base, base+".exe")
                }
        }
+
        if cleanN || cleanX {
                b.showcmd(p.Dir, "rm -f %s", strings.Join(allRemove, " "))
        }