From d91e48ea57b83f7018a25d3f54bba96cf889d66d Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Sun, 16 Aug 2020 10:30:35 +0200 Subject: Add ability to initialize bootstrapped modules after loading root.build --- libbuild2/file.cxx | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'libbuild2/file.cxx') diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx index 171d136..252f885 100644 --- a/libbuild2/file.cxx +++ b/libbuild2/file.cxx @@ -1446,17 +1446,25 @@ namespace build2 if (scope* rs = root.parent_scope ()->root_scope ()) load_root (*rs); - // Finish off initializing bootstrapped modules. + // Finish off initializing bootstrapped modules (before mode). // - for (auto& s: root.root_extra->modules) + // Note that init() can load additional modules invalidating iterators. + // + size_t boot_mods (root.root_extra->modules.size ()); + + for (size_t i (0); i != boot_mods; ++i) { - if (s.boot && s.first) + module_state& s (root.root_extra->modules[i]); + + if (s.boot_init && *s.boot_init == module_boot_init::before_first) init_module (root, root, s.name, s.loc); } - for (auto& s: root.root_extra->modules) + for (size_t i (0); i != boot_mods; ++i) { - if (s.boot && !s.first) + module_state& s (root.root_extra->modules[i]); + + if (s.boot_init && *s.boot_init == module_boot_init::before) init_module (root, root, s.name, s.loc); } @@ -1482,6 +1490,16 @@ namespace build2 if (fe) {source_once (p, root, root, f, root);} if (he) {p.reset (); source_hooks (p, root, hd, false /* pre */);} + // Finish off initializing bootstrapped modules (after mode). + // + for (size_t i (0); i != boot_mods; ++i) + { + module_state& s (root.root_extra->modules[i]); + + if (s.boot_init && *s.boot_init == module_boot_init::after) + init_module (root, root, s.name, s.loc); + } + // Print the project configuration report, similar to how we do it in // build system modules. // -- cgit v1.1