From 5974cab56148a18628bfb423189e016ade2d40f9 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 31 Aug 2015 13:45:57 +0200 Subject: Rework scoping logic Now the src directory is entered into the scope map and points to the same scope as out. This means that targets that are in src, not out (e.g., source files) will "see" rules, variables, etc. This becomes important when we try, for example, to install a source file (say, a header) from src: we need the rule as well as the install.* variables. --- build/dump.cxx | 72 +++++++++++++++++++++++----------------------------------- 1 file changed, 29 insertions(+), 43 deletions(-) (limited to 'build/dump.cxx') diff --git a/build/dump.cxx b/build/dump.cxx index f3b8c4b..7f4502e 100644 --- a/build/dump.cxx +++ b/build/dump.cxx @@ -4,7 +4,6 @@ #include -#include #include #include @@ -142,19 +141,21 @@ namespace build dump_scope (ostream& os, string& ind, action a, - scope& p, - scope_map::iterator& i, - set& rts) + scope_map::const_iterator& i) { + scope& p (*i->second); + const dir_path& d (i->first); + ++i; + // We don't want the extra notations (e.g., ~/) provided by // diag_relative() since we want the path to be relative to - // the global scope. + // the outer scope. // - os << ind << relative (p.path ()) << ":" << endl + os << ind << relative (d) << ":" << endl << ind << '{'; const dir_path* orb (relative_base); - relative_base = &p.path (); + relative_base = &d; ind += " "; @@ -179,10 +180,25 @@ namespace build vb = true; } - // Nested scopes of which we are a parent. + // Nested scopes of which we are an immediate parent. // - for (auto e (scopes.end ()); i != e && i->second.parent_scope () == &p; ) + for (auto e (scopes.end ()); i != e && i->second->parent_scope () == &p;) { + // See what kind of scope entry this is. It can be: + // + // 1. Out-of-project scope. + // 2. In-project out entry. + // 3. In-project src entry. + // + // We want to print #2 and #3 as a single, unified scope. + // + scope& s (*i->second); + if (s.src_path_ != s.out_path_ && s.src_path_ == &i->first) + { + ++i; + continue; + } + if (vb) { os << endl; @@ -193,9 +209,7 @@ namespace build os << endl; // Extra newline between scope blocks. os << endl; - scope& s (i->second); - dump_scope (os, ind, a, s, ++i, rts); - + dump_scope (os, ind, a, i); sb = true; } @@ -204,33 +218,8 @@ namespace build for (const auto& pt: targets) { const target& t (*pt); - const scope* ts (&t.base_scope ()); - - bool f (false); - if (ts == &p) - { - // If this is the global scope, check that this target hasn't - // been handled by the src logic below. - // - f = (ts != global_scope || rts.find (&t) == rts.end ()); - } - // If this target is in the global scope and we have a corresponding - // src directory (i.e., we are a scope inside a project), check - // whether this target is in our src. - // - else if (ts == global_scope && p.src_path_ != nullptr) - { - if (t.dir.sub (p.src_path ())) - { - // Check that it hasn't already been handled by a more qualified - // scope. - // - f = rts.insert (&t).second; - } - } - - if (!f) + if (&p != &t.base_scope ()) continue; if (vb || sb) @@ -254,14 +243,11 @@ namespace build dump (action a) { auto i (scopes.begin ()); - scope& g (i->second); // Global scope. - assert (&g == global_scope); + assert (i->second == global_scope); string ind; - set rts; - ostream& os (*diag_stream); - dump_scope (os, ind, a, g, ++i, rts); + dump_scope (os, ind, a, i); os << endl; } } -- cgit v1.1