summaryrefslogtreecommitdiff
path: root/src/cmd/go/clean.go
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@debian.org>2013-03-04 21:27:36 +0100
committerMichael Stapelberg <michael@stapelberg.de>2013-03-04 21:27:36 +0100
commit04b08da9af0c450d645ab7389d1467308cfc2db8 (patch)
treedb247935fa4f2f94408edc3acd5d0d4f997aa0d8 /src/cmd/go/clean.go
parent917c5fb8ec48e22459d77e3849e6d388f93d3260 (diff)
downloadgolang-upstream/1.1_hg20130304.tar.gz
Imported Upstream version 1.1~hg20130304upstream/1.1_hg20130304
Diffstat (limited to 'src/cmd/go/clean.go')
-rw-r--r--src/cmd/go/clean.go42
1 files changed, 34 insertions, 8 deletions
diff --git a/src/cmd/go/clean.go b/src/cmd/go/clean.go
index 773951826..ba600d3bb 100644
--- a/src/cmd/go/clean.go
+++ b/src/cmd/go/clean.go
@@ -34,6 +34,7 @@ source directories corresponding to the import paths:
DIR(.exe) from go build
DIR.test(.exe) from go test -c
MAINFILE(.exe) from go build MAINFILE.go
+ *.so from SWIG
In the list, DIR represents the final path element of the
directory, and MAINFILE is the base name of any Go source
@@ -93,11 +94,12 @@ var cleanFile = map[string]bool{
}
var cleanExt = map[string]bool{
- ".5": true,
- ".6": true,
- ".8": true,
- ".a": true,
- ".o": true,
+ ".5": true,
+ ".6": true,
+ ".8": true,
+ ".a": true,
+ ".o": true,
+ ".so": true,
}
func clean(p *Package) {
@@ -168,7 +170,9 @@ func clean(p *Package) {
continue
}
}
- os.RemoveAll(filepath.Join(p.Dir, name))
+ if err := os.RemoveAll(filepath.Join(p.Dir, name)); err != nil {
+ errorf("go clean: %v", err)
+ }
}
continue
}
@@ -178,7 +182,7 @@ func clean(p *Package) {
}
if cleanFile[name] || cleanExt[filepath.Ext(name)] || toRemove[name] {
- os.Remove(filepath.Join(p.Dir, name))
+ removeFile(filepath.Join(p.Dir, name))
}
}
@@ -187,7 +191,21 @@ func clean(p *Package) {
b.showcmd("", "rm -f %s", p.target)
}
if !cleanN {
- os.Remove(p.target)
+ removeFile(p.target)
+ }
+ }
+
+ if cleanI && p.usesSwig() {
+ for _, f := range stringList(p.SwigFiles, p.SwigCXXFiles) {
+ dir := p.swigDir(&buildContext)
+ soname := p.swigSoname(f)
+ target := filepath.Join(dir, soname)
+ if cleanN || cleanX {
+ b.showcmd("", "rm -f %s", target)
+ }
+ if !cleanN {
+ removeFile(target)
+ }
}
}
@@ -197,3 +215,11 @@ func clean(p *Package) {
}
}
}
+
+// removeFile tries to remove file f, if error other than file doesn't exist
+// occurs, it will report the error.
+func removeFile(f string) {
+ if err := os.Remove(f); err != nil && !os.IsNotExist(err) {
+ errorf("go clean: %v", err)
+ }
+}