You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
rule a
command = echo "a: $lang"
rule b
command = echo "b: $lang"
build dep.txt: b
build output.txt: a dep.txt
lang = english
Here, I would expect the lang = english variable definition to apply when dep.txt is built, since that build is triggered from the output.txt build. Instead, it the variable is only used when rule a is executed. This may well be intended behavior, but if so then how to get b to see $lang?
The docs state the following, and it's not clear whether/how 2 & 3 apply:
Variable declarations indented in a build block are scoped to the build block. The full lookup order for a variable expanded in a build block (or the rule is uses) is:
1. Special built-in variables ($in, $out).
2. Build-level variables from the build block.
3. Rule-level variables from the rule block (i.e. $command). (Note from the above discussion on expansion that these are expanded "late", and may make use of in-scope bindings like $in.)
4. File-level variables from the file that the build line was in.
5. Variables from the file that included that file using the subninja keyword.
The text was updated successfully, but these errors were encountered:
build-level variables only apply to the command expansion for that build statement, so what you are seeing is the intended behavior. Ninja never propagates variable definitions through the build graph, intentionally. This kind of computation is complex and should be performed by the generator for your Ninja build plan.
In this specific case, one possibility is to define a rule-level variable whose value will be a default, that can be overridden by specific build statements, as in:
rule a
lang = english
command = echo "a: $lang"
rule b
lang = english
command = echo "b: $lang"
build dep.txt: b
build output.txt: a dep.txt
lang = french
But that is only a suggestion, this really depends on the problem you want to solve.
Consider the following
build.ninja
file:Here, I would expect the
lang = english
variable definition to apply whendep.txt
is built, since that build is triggered from theoutput.txt
build. Instead, it the variable is only used when rulea
is executed. This may well be intended behavior, but if so then how to getb
to see$lang
?The docs state the following, and it's not clear whether/how 2 & 3 apply:
The text was updated successfully, but these errors were encountered: