Add more Build/Rule/Pool params validation.
This change adds two new kinds of checks to params validation. First, all
BuildParams must have one or more outputs. Second, any Pool or Rule referenced
must be visible within the Blueprint scope of the caller (e.g. if it's defined
in another Go package then an Import call must have been made). If either of
these conditions are violated it will result in a panic.
Change-Id: Ibacb42513882d914c94eade23ef17269db5e8730
diff --git a/blueprint/ninja_defs.go b/blueprint/ninja_defs.go
index cc05085..b9690e5 100644
--- a/blueprint/ninja_defs.go
+++ b/blueprint/ninja_defs.go
@@ -1,6 +1,7 @@
package blueprint
import (
+ "errors"
"fmt"
"strconv"
"strings"
@@ -72,7 +73,7 @@
Depth int
}
-func parsePoolParams(scope variableLookup, params *PoolParams) (*poolDef,
+func parsePoolParams(scope scope, params *PoolParams) (*poolDef,
error) {
def := &poolDef{
@@ -107,7 +108,7 @@
Variables map[string]*ninjaString
}
-func parseRuleParams(scope variableLookup, params *RuleParams) (*ruleDef,
+func parseRuleParams(scope scope, params *RuleParams) (*ruleDef,
error) {
r := &ruleDef{
@@ -121,6 +122,10 @@
"specified")
}
+ if r.Pool != nil && !scope.IsPoolVisible(r.Pool) {
+ return nil, fmt.Errorf("Pool %s is not visible in this scope", r.Pool)
+ }
+
value, err := parseNinjaString(scope, params.Command)
if err != nil {
return nil, fmt.Errorf("error parsing Command param: %s", err)
@@ -217,7 +222,7 @@
Args map[Variable]*ninjaString
}
-func parseBuildParams(scope variableLookup, params *BuildParams) (*buildDef,
+func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
error) {
rule := params.Rule
@@ -226,6 +231,14 @@
Rule: rule,
}
+ if !scope.IsRuleVisible(rule) {
+ return nil, fmt.Errorf("Rule %s is not visible in this scope", rule)
+ }
+
+ if len(params.Outputs) == 0 {
+ return nil, errors.New("Outputs param has no elements")
+ }
+
var err error
b.Outputs, err = parseNinjaStrings(scope, params.Outputs)
if err != nil {