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
diff --git a/android/rule_builder_test.go b/android/rule_builder_test.go
index c896719..f7577a6 100644
--- a/android/rule_builder_test.go
+++ b/android/rule_builder_test.go
@@ -45,6 +45,45 @@
// 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()