]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: clean test directories as they complete
authorJoel Sing <jsing@google.com>
Tue, 31 Jan 2012 15:37:21 +0000 (10:37 -0500)
committerRuss Cox <rsc@golang.org>
Tue, 31 Jan 2012 15:37:21 +0000 (10:37 -0500)
A go build currently generates around 400MB of test output prior to
cleaning up. With this change we use a maximum of ~15MB.

R=golang-dev, rsc
CC=golang-dev
https://golang.org/cl/5588044

src/cmd/go/test.go

index 5a7f321d23b5719c42eb2762bce6a8f9ac8ad5ef..e47090582cbdba4d10fba562e33f09d94c2d697e 100644 (file)
@@ -442,9 +442,14 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
                        p:          p,
                        ignoreFail: true,
                }
+               cleanAction := &action{
+                       f:    (*builder).cleanTest,
+                       deps: []*action{runAction},
+                       p:    p,
+               }
                printAction = &action{
                        f:    (*builder).printTest,
-                       deps: []*action{runAction},
+                       deps: []*action{cleanAction},
                        p:    p,
                }
        }
@@ -521,12 +526,22 @@ func (b *builder) runTest(a *action) error {
        } else {
                fmt.Fprintf(a.testOutput, "%s\n", err)
        }
+
+       return nil
+}
+
+// cleanTest is the action for cleaning up after a test.
+func (b *builder) cleanTest(a *action) error {
+       run := a.deps[0]
+       testDir := filepath.Join(b.work, filepath.FromSlash(run.p.ImportPath+"/_test"))
+       os.RemoveAll(testDir)
        return nil
 }
 
 // printTest is the action for printing a test result.
 func (b *builder) printTest(a *action) error {
-       run := a.deps[0]
+       clean := a.deps[0]
+       run := clean.deps[0]
        os.Stdout.Write(run.testOutput.Bytes())
        run.testOutput = nil
        return nil