Add MissingDeps to RuleBuilder
Add a method to be used when Config.AllowMissingDependencies() is true
to produce an error rule when the rule is missing dependencies.
Test: m checkbuild
Change-Id: If370fbb2734237a84a100b99b5238c7a2256c405
diff --git a/android/rule_builder.go b/android/rule_builder.go
index d005839..38018be 100644
--- a/android/rule_builder.go
+++ b/android/rule_builder.go
@@ -31,6 +31,7 @@
installs []RuleBuilderInstall
temporariesSet map[string]bool
restat bool
+ missingDeps []string
}
// NewRuleBuilder returns a newly created RuleBuilder.
@@ -45,6 +46,15 @@
From, To string
}
+// MissingDeps adds modules to the list of missing dependencies. If MissingDeps
+// is called with a non-empty input, any call to Build will result in a rule
+// that will print an error listing the missing dependencies and fail.
+// MissingDeps should only be called if Config.AllowMissingDependencies() is
+// true.
+func (r *RuleBuilder) MissingDeps(missingDeps []string) {
+ r.missingDeps = append(r.missingDeps, missingDeps...)
+}
+
// Restat marks the rule as a restat rule, which will be passed to ModuleContext.Rule in BuildParams.Restat.
func (r *RuleBuilder) Restat() *RuleBuilder {
r.restat = true
@@ -219,6 +229,18 @@
}
}
+ if len(r.missingDeps) > 0 {
+ ctx.Build(pctx, BuildParams{
+ Rule: ErrorRule,
+ Outputs: outputs,
+ Description: desc,
+ Args: map[string]string{
+ "error": "missing dependencies: " + strings.Join(r.missingDeps, ", "),
+ },
+ })
+ return
+ }
+
if len(r.Commands()) > 0 {
ctx.Build(pctx, BuildParams{
Rule: ctx.Rule(pctx, name, blueprint.RuleParams{