Allow BuildParams to override ninja description

Allow the ninja description variable to be set on build statements
as well as rules.

Change-Id: I6abb2a8ec83a0c662348cc957fa1a307e6c9c6bb
This commit is contained in:
Colin Cross 2017-05-08 17:50:22 -07:00
parent a30a741c22
commit 7aa318f83d
2 changed files with 25 additions and 8 deletions

View file

@ -68,6 +68,13 @@ func (l *liveTracker) AddBuildDefDeps(def *buildDef) error {
return err return err
} }
for _, value := range def.Variables {
err = l.addNinjaStringDeps(value)
if err != nil {
return err
}
}
for _, value := range def.Args { for _, value := range def.Args {
err = l.addNinjaStringDeps(value) err = l.addNinjaStringDeps(value)
if err != nil { if err != nil {

View file

@ -79,6 +79,7 @@ type BuildParams struct {
Comment string // The comment that will appear above the definition. Comment string // The comment that will appear above the definition.
Depfile string // The dependency file name. Depfile string // The dependency file name.
Deps Deps // The format of the dependency file. Deps Deps // The format of the dependency file.
Description string // The description that Ninja will print for the build.
Rule Rule // The rule to invoke. Rule Rule // The rule to invoke.
Outputs []string // The list of explicit output targets. Outputs []string // The list of explicit output targets.
ImplicitOutputs []string // The list of implicit output targets. ImplicitOutputs []string // The list of implicit output targets.
@ -265,6 +266,13 @@ func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
Rule: rule, Rule: rule,
} }
setVariable := func(name string, value *ninjaString) {
if b.Variables == nil {
b.Variables = make(map[string]*ninjaString)
}
b.Variables[name] = value
}
if !scope.IsRuleVisible(rule) { if !scope.IsRuleVisible(rule) {
return nil, fmt.Errorf("Rule %s is not visible in this scope", rule) return nil, fmt.Errorf("Rule %s is not visible in this scope", rule)
} }
@ -301,22 +309,24 @@ func parseBuildParams(scope scope, params *BuildParams) (*buildDef,
b.Optional = params.Optional b.Optional = params.Optional
if params.Depfile != "" || params.Deps != DepsNone {
if b.Variables == nil {
b.Variables = make(map[string]*ninjaString)
}
}
if params.Depfile != "" { if params.Depfile != "" {
value, err := parseNinjaString(scope, params.Depfile) value, err := parseNinjaString(scope, params.Depfile)
if err != nil { if err != nil {
return nil, fmt.Errorf("error parsing Depfile param: %s", err) return nil, fmt.Errorf("error parsing Depfile param: %s", err)
} }
b.Variables["depfile"] = value setVariable("depfile", value)
} }
if params.Deps != DepsNone { if params.Deps != DepsNone {
b.Variables["deps"] = simpleNinjaString(params.Deps.String()) setVariable("deps", simpleNinjaString(params.Deps.String()))
}
if params.Description != "" {
value, err := parseNinjaString(scope, params.Description)
if err != nil {
return nil, fmt.Errorf("error parsing Description param: %s", err)
}
setVariable("description", value)
} }
argNameScope := rule.scope() argNameScope := rule.scope()