Commit 6f428f09 authored by Joel Sing's avatar Joel Sing Committed by Russ Cox

cmd/go: clean test directories as they complete

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
parent 28397bef
...@@ -442,9 +442,14 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action, ...@@ -442,9 +442,14 @@ func (b *builder) test(p *Package) (buildAction, runAction, printAction *action,
p: p, p: p,
ignoreFail: true, ignoreFail: true,
} }
cleanAction := &action{
f: (*builder).cleanTest,
deps: []*action{runAction},
p: p,
}
printAction = &action{ printAction = &action{
f: (*builder).printTest, f: (*builder).printTest,
deps: []*action{runAction}, deps: []*action{cleanAction},
p: p, p: p,
} }
} }
...@@ -521,12 +526,22 @@ func (b *builder) runTest(a *action) error { ...@@ -521,12 +526,22 @@ func (b *builder) runTest(a *action) error {
} else { } else {
fmt.Fprintf(a.testOutput, "%s\n", err) 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 return nil
} }
// printTest is the action for printing a test result. // printTest is the action for printing a test result.
func (b *builder) printTest(a *action) error { 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()) os.Stdout.Write(run.testOutput.Bytes())
run.testOutput = nil run.testOutput = nil
return nil return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment