-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow scoping rules through subninja #921
Conversation
Ninja didn't support scoping rules through subninja and assumed a unique rule name in the whole namespace. With this change, this behavior is changed to allow scoping rules. Two rules can have the same name if they belong to two different scopes. However, two rules can NOT have the same name in the same scope.
The new test shows the added value of scoped rules by demonstrating a multi-level build where a single rules file gets included at all the levels. By scoping rules, this is possible.
Let's do this. I'm not super happy that Rule is moving into EvalEnv, but I can try to move it around later if I manage to figure out a better way of doing this. (Chances are I won't either.) Also, this needed some minor changes to build with libc++ for me, see nico@f6461f0 . I'll apply that myself after merging. Thanks for the patch! |
Allow scoping rules through subninja
It failed with error: field has incomplete type 'EvalString' note: in instantiation of exception specification for 'map' requested here explicit Rule(const string& name) : name_(name) {} ^
It failed with error: field has incomplete type 'EvalString' note: in instantiation of exception specification for 'map' requested here explicit Rule(const string& name) : name_(name) {} ^
string err; | ||
EXPECT_TRUE(parser.ParseTest("include rules.ninja\n" | ||
"subninja test.ninja\n" | ||
"build y : cat\n", &err)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This triggers an assert in debug builds (./configure --debug
):
[166/198] ParserTest.DuplicateRuleInDifferentSubninjasAssertion failed: (LookupRule(rule->name()) == NULL),
function AddRule, file src/eval_env.cc, line 33.
I guess AddRule needs to assert with LookupRuleCurrentScope now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. Sorry for that!
Fix an assert (and tests in --debug mode) after #921.
rules.ninja only defines rules. Up to ninja 1.5.x, include and subninja do the same thing for ninja files that only define rules. In ninja 1.6, we hope to change rules to be scoped to the current subninja ( ninja-build/ninja#921 ). With that change, `subninja rules.ninja` would define the rules in a new scope that closes at the end of the line and all the rules in rules.ninja would be ignores. `include` won't introduce a new scope and instead add the rules in the context of the parent build.ninja file. This change should have no effect on ninja up to 1.5.x, and it should keep the build working as previously with newer ninja versions.
Document the change from #921 in the manual.
Ninja didn't support scoping rules through subninja and assumed
a unique rule name in the whole namespace. With this change, this
behavior is changed to allow scoping rules. Two rules can have the
same name if they belong to two different scopes. However, two
rules can NOT have the same name in the same scope.