From 7aa318f83d8a16c1684660d5eca805993f2d0ac5 Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Mon, 8 May 2017 17:50:22 -0700 Subject: [PATCH] Allow BuildParams to override ninja description Allow the ninja description variable to be set on build statements as well as rules. Change-Id: I6abb2a8ec83a0c662348cc957fa1a307e6c9c6bb --- live_tracker.go | 7 +++++++ ninja_defs.go | 26 ++++++++++++++++++-------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/live_tracker.go b/live_tracker.go index 8348988..63bdf8a 100644 --- a/live_tracker.go +++ b/live_tracker.go @@ -68,6 +68,13 @@ func (l *liveTracker) AddBuildDefDeps(def *buildDef) error { return err } + for _, value := range def.Variables { + err = l.addNinjaStringDeps(value) + if err != nil { + return err + } + } + for _, value := range def.Args { err = l.addNinjaStringDeps(value) if err != nil { diff --git a/ninja_defs.go b/ninja_defs.go index 8737ed2..64bab16 100644 --- a/ninja_defs.go +++ b/ninja_defs.go @@ -79,6 +79,7 @@ type BuildParams struct { Comment string // The comment that will appear above the definition. Depfile string // The dependency file name. 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. Outputs []string // The list of explicit output targets. ImplicitOutputs []string // The list of implicit output targets. @@ -265,6 +266,13 @@ func parseBuildParams(scope scope, params *BuildParams) (*buildDef, 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) { 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 - if params.Depfile != "" || params.Deps != DepsNone { - if b.Variables == nil { - b.Variables = make(map[string]*ninjaString) - } - } - if params.Depfile != "" { value, err := parseNinjaString(scope, params.Depfile) if err != nil { return nil, fmt.Errorf("error parsing Depfile param: %s", err) } - b.Variables["depfile"] = value + setVariable("depfile", value) } 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()