Make RuleBuilder fail fast when passed a nil Path
Previously, the RuleBuilder would add all supplied Paths directly to one of its lists of Paths without checking to make sure it was not nil only to panic somewhere in its Build() method when it attempted to convert it to a string. Deferring the failure made it harder to debug. This change fails fast by checking every Path when it is passed to the RuleBuilder. Test: m nothing Change-Id: I06b35da02101f6dfab80d2daaf3d8e44ded8b6be
This commit is contained in:
parent
8bb9c6a1d9
commit
3866b89d15
1 changed files with 22 additions and 2 deletions
|
@ -769,16 +769,25 @@ type rspFileAndPaths struct {
|
|||
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 @@ func (c *RuleBuilderCommand) FlagWithList(flag string, list []string, sep string
|
|||
// 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 @@ func (c *RuleBuilderCommand) OrderOnlys(paths Paths) *RuleBuilderCommand {
|
|||
// 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 @@ func (c *RuleBuilderCommand) Validation(path Path) *RuleBuilderCommand {
|
|||
// 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 @@ func (c *RuleBuilderCommand) OutputDir() *RuleBuilderCommand {
|
|||
// 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 @@ func (c *RuleBuilderCommand) ImplicitOutputs(paths WritablePaths) *RuleBuilderCo
|
|||
// 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 @@ func (c *RuleBuilderCommand) ImplicitSymlinkOutputs(paths WritablePaths) *RuleBu
|
|||
// 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)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue