From 0d0d9a9c56822919e9794658d31db57f8fc3e2bf Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 10 Dec 2015 13:54:59 +0200 Subject: Implement two-phase initialization of modules loaded from bootstrap.build --- build/file.cxx | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'build/file.cxx') diff --git a/build/file.cxx b/build/file.cxx index 9595d8f..59fe1b9 100644 --- a/build/file.cxx +++ b/build/file.cxx @@ -75,8 +75,8 @@ namespace build return dir_path (); } - void - source (const path& bf, scope& root, scope& base) + static void + source (const path& bf, scope& root, scope& base, bool boot) { tracer trace ("source"); @@ -90,7 +90,7 @@ namespace build level5 ([&]{trace << "sourcing " << bf;}); - parser p; + parser p (boot); p.parse_buildfile (ifs, bf, root, base); } catch (const ifstream::failure&) @@ -100,6 +100,12 @@ namespace build } void + source (const path& bf, scope& root, scope& base) + { + return source (bf, root, base, false); + } + + void source_once (const path& bf, scope& root, scope& base, scope& once) { tracer trace ("source_once"); @@ -440,7 +446,11 @@ namespace build // process hard to reason about. But we may try to bootstrap the // same root scope multiple time. // - source_once (bf, root, root); + if (root.buildfiles.insert (bf).second) + source (bf, root, root, true); + else + level5 ([&]{trace << "skipping already sourced " << bf;}); + r = true; } @@ -722,6 +732,22 @@ namespace build if (scope* rs = root.parent_scope ()->root_scope ()) load_root_pre (*rs); + // Finish off loading bootstrapped modules. + // + for (auto& p: root.modules) + { + const string& n (p.first); + module_state& s (p.second); + + if (s.boot) + { + load_module (false, n, root, root, s.loc); + assert (!s.boot); + } + } + + // Load root.build. + // path bf (root.src_path () / path ("build/root.build")); if (file_exists (bf)) -- cgit v1.1