Merge "Make RuleBuilder fail fast when passed a nil Path"
diff --git a/android/rule_builder.go b/android/rule_builder.go
index 6605869..c9a9ddd 100644
--- a/android/rule_builder.go
+++ b/android/rule_builder.go
@@ -769,16 +769,25 @@
paths Paths
}
+func checkPathNotNil(path Path) {
+ if path == nil {
+ panic("rule_builder paths cannot be nil")
+ }
+}
+
func (c *RuleBuilderCommand) addInput(path Path) string {
+ checkPathNotNil(path)
c.inputs = append(c.inputs, path)
return c.PathForInput(path)
}
func (c *RuleBuilderCommand) addImplicit(path Path) {
+ checkPathNotNil(path)
c.implicits = append(c.implicits, path)
}
func (c *RuleBuilderCommand) addOrderOnly(path Path) {
+ checkPathNotNil(path)
c.orderOnlys = append(c.orderOnlys, path)
}
@@ -1004,19 +1013,23 @@
// Tool adds the specified tool path to the command line. The path will be also added to the dependencies returned by
// RuleBuilder.Tools.
func (c *RuleBuilderCommand) Tool(path Path) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.tools = append(c.tools, path)
return c.Text(c.PathForTool(path))
}
// Tool adds the specified tool path to the dependencies returned by RuleBuilder.Tools.
func (c *RuleBuilderCommand) ImplicitTool(path Path) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.tools = append(c.tools, path)
return c
}
// Tool adds the specified tool path to the dependencies returned by RuleBuilder.Tools.
func (c *RuleBuilderCommand) ImplicitTools(paths Paths) *RuleBuilderCommand {
- c.tools = append(c.tools, paths...)
+ for _, path := range paths {
+ c.ImplicitTool(path)
+ }
return c
}
@@ -1093,6 +1106,7 @@
// Validation adds the specified input path to the validation dependencies by
// RuleBuilder.Validations without modifying the command line.
func (c *RuleBuilderCommand) Validation(path Path) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.validations = append(c.validations, path)
return c
}
@@ -1100,13 +1114,16 @@
// Validations adds the specified input paths to the validation dependencies by
// RuleBuilder.Validations without modifying the command line.
func (c *RuleBuilderCommand) Validations(paths Paths) *RuleBuilderCommand {
- c.validations = append(c.validations, paths...)
+ for _, path := range paths {
+ c.Validation(path)
+ }
return c
}
// Output adds the specified output path to the command line. The path will also be added to the outputs returned by
// RuleBuilder.Outputs.
func (c *RuleBuilderCommand) Output(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.outputs = append(c.outputs, path)
return c.Text(c.PathForOutput(path))
}
@@ -1133,6 +1150,7 @@
// line, and causes RuleBuilder.Build file to set the depfile flag for ninja. If multiple depfiles are added to
// commands in a single RuleBuilder then RuleBuilder.Build will add an extra command to merge the depfiles together.
func (c *RuleBuilderCommand) DepFile(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.depFiles = append(c.depFiles, path)
return c.Text(c.PathForOutput(path))
}
@@ -1155,6 +1173,7 @@
// will be a symlink instead of a regular file. Does not modify the command
// line.
func (c *RuleBuilderCommand) ImplicitSymlinkOutput(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.symlinkOutputs = append(c.symlinkOutputs, path)
return c.ImplicitOutput(path)
}
@@ -1172,6 +1191,7 @@
// SymlinkOutput declares the specified path as an output that will be a symlink
// instead of a regular file. Modifies the command line.
func (c *RuleBuilderCommand) SymlinkOutput(path WritablePath) *RuleBuilderCommand {
+ checkPathNotNil(path)
c.symlinkOutputs = append(c.symlinkOutputs, path)
return c.Output(path)
}