diff options
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/file.cxx | 68 |
1 files changed, 43 insertions, 25 deletions
diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx index 7fd3f78..613f095 100644 --- a/libbuild2/file.cxx +++ b/libbuild2/file.cxx @@ -159,10 +159,8 @@ namespace build2 } } - using stage = parser::stage; - static void - source (scope& root, scope& base, lexer& l, stage s) + source (parser& p, scope& root, scope& base, lexer& l) { tracer trace ("source"); @@ -171,8 +169,6 @@ namespace build2 try { l5 ([&]{trace << "sourcing " << fn;}); - - parser p (root.ctx, s); p.parse_buildfile (l, root, base); } catch (const io_error& e) @@ -182,24 +178,24 @@ namespace build2 } static inline void - source (scope& root, + source (parser& p, + scope& root, scope& base, istream& is, - const path_name& in, - stage s) + const path_name& in) { lexer l (is, in); - source (root, base, l, s); + source (p, root, base, l); } static void - source (scope& root, scope& base, const path& bf, stage s) + source (parser& p, scope& root, scope& base, const path& bf) { path_name fn (bf); try { ifdstream ifs; - return source (root, base, open_file_or_stdin (fn, ifs), fn, s); + return source (p, root, base, open_file_or_stdin (fn, ifs), fn); } catch (const io_error& e) { @@ -208,7 +204,11 @@ namespace build2 } static bool - source_once (scope& root, scope& base, const path& bf, scope& once, stage s) + source_once (parser& p, + scope& root, + scope& base, + const path& bf, + scope& once) { tracer trace ("source_once"); @@ -218,32 +218,36 @@ namespace build2 return false; } - source (root, base, bf, s); + source (p, root, base, bf); return true; } void source (scope& root, scope& base, const path& bf) { - source (root, base, bf, stage::rest); + parser p (root.ctx); + source (p, root, base, bf); } void source (scope& root, scope& base, istream& is, const path_name& in) { - source (root, base, is, in, stage::rest); + parser p (root.ctx); + source (p, root, base, is, in); } void source (scope& root, scope& base, lexer& l) { - source (root, base, l, stage::rest); + parser p (root.ctx); + source (p, root, base, l); } bool source_once (scope& root, scope& base, const path& bf, scope& once) { - return source_once (root, base, bf, once, stage::rest); + parser p (root.ctx); + return source_once (p, root, base, bf, once); } // Source (once) pre-*.build (pre is true) or post-*.build (otherwise) hooks @@ -251,7 +255,7 @@ namespace build2 // must exist. // static void - source_hooks (scope& root, const dir_path& d, stage s, bool pre) + source_hooks (parser& p, scope& root, const dir_path& d, bool pre) { // While we could have used the wildcard pattern matching functionality, // our needs are pretty basic and performance is quite important, so let's @@ -286,7 +290,7 @@ namespace build2 fail << "unable to read buildfile " << f << ": " << e; } - source_once (root, root, f, root, s); + source_once (p, root, root, f, root); } } catch (const system_error& e) @@ -807,7 +811,10 @@ namespace build2 // root scope multiple time. // if (rs.buildfiles.insert (f).second) - source (rs, rs, f, stage::boot); + { + parser p (rs.ctx, parser::stage::boot); + source (p, rs, rs, f); + } else l5 ([&]{trace << "skipping already sourced " << f;}); @@ -1038,7 +1045,8 @@ namespace build2 if (root.root_extra == nullptr) setup_root_extra (root, altn); - source_hooks (root, d, stage::boot, true /* pre */); + parser p (root.ctx, parser::stage::boot); + source_hooks (p, root, d, true /* pre */); } } @@ -1050,7 +1058,10 @@ namespace build2 dir_path d (out_root / root.root_extra->bootstrap_dir); if (exists (d)) - source_hooks (root, d, stage::boot, false /* pre */); + { + parser p (root.ctx, parser::stage::boot); + source_hooks (p, root, d, false /* pre */); + } } bool @@ -1274,11 +1285,18 @@ namespace build2 // with a post-bootstrap hook. // dir_path hd (out_root / root.root_extra->root_dir); + bool he (exists (hd)); + bool fe (exists (f)); + + + // Reuse the parser to accumulate the configuration variable information. + // + parser p (root.ctx, parser::stage::root); - if (he) source_hooks (root, hd, stage::root, true /* pre */); - if (exists (f)) source_once (root, root, f, root, stage::root); - if (he) source_hooks (root, hd, stage::root, false /* pre */); + if (he) {source_hooks (p, root, hd, true /* pre */); p.reset ();} + if (fe) {source_once (p, root, root, f, root);} + if (he) {p.reset (); source_hooks (p, root, hd, false /* pre */);} } scope& |