aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/file.cxx34
-rw-r--r--libbuild2/module.hxx9
-rw-r--r--libbuild2/version/init.cxx4
3 files changed, 21 insertions, 26 deletions
diff --git a/libbuild2/file.cxx b/libbuild2/file.cxx
index d60a2dc..e1dde1f 100644
--- a/libbuild2/file.cxx
+++ b/libbuild2/file.cxx
@@ -1450,23 +1450,21 @@ namespace build2
//
// 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)
+ auto init_modules =
+ [&root, n = root.root_extra->modules.size ()] (module_boot_init v)
{
- 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 (size_t i (0); i != n; ++i)
+ {
+ module_state& s (root.root_extra->modules[i]);
- for (size_t i (0); i != boot_mods; ++i)
- {
- module_state& s (root.root_extra->modules[i]);
+ if (s.boot_init && *s.boot_init == v)
+ init_module (root, root, s.name, s.loc);
+ }
+ };
- if (s.boot_init && *s.boot_init == module_boot_init::before)
- init_module (root, root, s.name, s.loc);
- }
+ init_modules (module_boot_init::before_first);
+ init_modules (module_boot_init::before_second);
+ init_modules (module_boot_init::before);
// Load hooks and root.build.
//
@@ -1492,13 +1490,7 @@ namespace build2
// 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);
- }
+ init_modules (module_boot_init::after);
// Print the project configuration report, similar to how we do it in
// build system modules.
diff --git a/libbuild2/module.hxx b/libbuild2/module.hxx
index 4110682..4f69914 100644
--- a/libbuild2/module.hxx
+++ b/libbuild2/module.hxx
@@ -42,9 +42,11 @@ namespace build2
//
// By default a booted module is initialized before loading root.build.
//
- // The module should specify the before_first initialization mode if it
- // should be initialized first (within the resulting two groups the modules
- // are initializated in the order loaded).
+ // The module should specify the before_{first,second} initialization modes
+ // if it should be initialized in the first or second batch (within the
+ // resulting three groups the modules are initializated in the order
+ // loaded). The before_first mode is pretty much reserved for the config
+ // module.
//
// The module should specify the after initialization mode if it should be
// initialized after loading root.build. Note that in this case the module
@@ -53,6 +55,7 @@ namespace build2
enum class module_boot_init
{
before_first,
+ before_second,
before,
after
};
diff --git a/libbuild2/version/init.cxx b/libbuild2/version/init.cxx
index 43b6b92..d11b2f3 100644
--- a/libbuild2/version/init.cxx
+++ b/libbuild2/version/init.cxx
@@ -279,9 +279,9 @@ namespace build2
rewritten,
move (ds)));
- // Initialize first (dist.package, etc).
+ // Initialize second (dist.package, etc).
//
- extra.init = module_boot_init::before_first;
+ extra.init = module_boot_init::before_second;
}
static void