From 47113641cd52e7af8e6f4fa7fc42f2f4eff5950a Mon Sep 17 00:00:00 2001 From: Colin Cross Date: Tue, 17 Oct 2017 13:49:28 -0700 Subject: [PATCH] Allow rules to specify order-only dependencies Commands that contain tools that don't affect the build results may want an order-only dependency on the tool. Allow rules to specify order-only dependencies the same way they specify implicit dependencies. Test: builds Change-Id: I3e0f886ae047b0fadf7a5c0dfeb9827d2c5c411d --- live_tracker.go | 5 +++++ ninja_defs.go | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/live_tracker.go b/live_tracker.go index 63bdf8a..5e13a87 100644 --- a/live_tracker.go +++ b/live_tracker.go @@ -109,6 +109,11 @@ func (l *liveTracker) addRule(r Rule) (def *ruleDef, err error) { return nil, err } + err = l.addNinjaStringListDeps(def.CommandOrderOnly) + if err != nil { + return nil, err + } + for _, value := range def.Variables { err = l.addNinjaStringDeps(value) if err != nil { diff --git a/ninja_defs.go b/ninja_defs.go index 64bab16..b27658b 100644 --- a/ninja_defs.go +++ b/ninja_defs.go @@ -67,8 +67,9 @@ type RuleParams struct { RspfileContent string // The response file content. // These fields are used internally in Blueprint - CommandDeps []string // Command-specific implicit dependencies to prepend to builds - Comment string // The comment that will appear above the definition. + CommandDeps []string // Command-specific implicit dependencies to prepend to builds + CommandOrderOnly []string // Command-specific order-only dependencies to prepend to builds + Comment string // The comment that will appear above the definition. } // A BuildParams object contains the set of parameters that make up a Ninja @@ -127,10 +128,11 @@ func (p *poolDef) WriteTo(nw *ninjaWriter, name string) error { // A ruleDef describes a rule definition. It does not include the name of the // rule. type ruleDef struct { - CommandDeps []*ninjaString - Comment string - Pool Pool - Variables map[string]*ninjaString + CommandDeps []*ninjaString + CommandOrderOnly []*ninjaString + Comment string + Pool Pool + Variables map[string]*ninjaString } func parseRuleParams(scope scope, params *RuleParams) (*ruleDef, @@ -207,6 +209,11 @@ func parseRuleParams(scope scope, params *RuleParams) (*ruleDef, return nil, fmt.Errorf("error parsing CommandDeps param: %s", err) } + r.CommandOrderOnly, err = parseNinjaStrings(scope, params.CommandOrderOnly) + if err != nil { + return nil, fmt.Errorf("error parsing CommandDeps param: %s", err) + } + return r, nil } @@ -370,6 +377,7 @@ func (b *buildDef) WriteTo(nw *ninjaWriter, pkgNames map[*packageContext]string) if b.RuleDef != nil { implicitDeps = append(valueList(b.RuleDef.CommandDeps, pkgNames, inputEscaper), implicitDeps...) + orderOnlyDeps = append(valueList(b.RuleDef.CommandOrderOnly, pkgNames, inputEscaper), orderOnlyDeps...) } err := nw.Build(comment, rule, outputs, implicitOuts, explicitDeps, implicitDeps, orderOnlyDeps)