Add Temporary and DeleteTemporaryFiles to RuleBuilder

Temporary marks an output path as a temporary file that is not
necessary after the rule completes, removing it from the result of
Outputs.  DeleteTemporaryFiles adds a command to the command line
that deletes all files that have been marked with Temporary.

Test: rule_builder_test.go
Change-Id: Ie509ed800992962747fb287858e148e975eee54a
This commit is contained in:
Colin Cross
2019-02-02 21:25:18 -08:00
parent 758290d7ff
commit 5cb5b093d1
2 changed files with 86 additions and 9 deletions

View File

@@ -45,6 +45,45 @@ func ExampleRuleBuilder() {
// outputs: ["linked"]
}
func ExampleRuleBuilder_Temporary() {
rule := NewRuleBuilder()
rule.Command().Tool("cp").Input("a").Output("b")
rule.Command().Tool("cp").Input("b").Output("c")
rule.Temporary("b")
fmt.Printf("commands: %q\n", strings.Join(rule.Commands(), " && "))
fmt.Printf("tools: %q\n", rule.Tools())
fmt.Printf("inputs: %q\n", rule.Inputs())
fmt.Printf("outputs: %q\n", rule.Outputs())
// Output:
// commands: "cp a b && cp b c"
// tools: ["cp"]
// inputs: ["a"]
// outputs: ["c"]
}
func ExampleRuleBuilder_DeleteTemporaryFiles() {
rule := NewRuleBuilder()
rule.Command().Tool("cp").Input("a").Output("b")
rule.Command().Tool("cp").Input("b").Output("c")
rule.Temporary("b")
rule.DeleteTemporaryFiles()
fmt.Printf("commands: %q\n", strings.Join(rule.Commands(), " && "))
fmt.Printf("tools: %q\n", rule.Tools())
fmt.Printf("inputs: %q\n", rule.Inputs())
fmt.Printf("outputs: %q\n", rule.Outputs())
// Output:
// commands: "cp a b && cp b c && rm -f b"
// tools: ["cp"]
// inputs: ["a"]
// outputs: ["c"]
}
func ExampleRuleBuilderCommand() {
rule := NewRuleBuilder()