diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-09-24 10:48:45 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-09-24 10:59:45 +0200 |
commit | a414fa7b0ff469013598ca9ef2999ca6293ee7c1 (patch) | |
tree | d0b5b74d026f16a6eec64c4a84f82bb76162f48c /libbuild2/module.hxx | |
parent | 9eb84a8134c532029b9f74ced48696994d9c7fc5 (diff) |
Add post-boot module function
Diffstat (limited to 'libbuild2/module.hxx')
-rw-r--r-- | libbuild2/module.hxx | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/libbuild2/module.hxx b/libbuild2/module.hxx index 4f69914..770e694 100644 --- a/libbuild2/module.hxx +++ b/libbuild2/module.hxx @@ -33,12 +33,27 @@ namespace build2 ~module () = default; }; + // The module_*_extra arguments in boot and init are used to pass additional + // information that is only used by some modules. It is also a way for us to + // later pass more information without breaking source compatibility. + // + struct module_common_extra + { + shared_ptr<build2::module> module; // Module instance (in/out). + + // Convenience functions. + // + template <typename T> + T& set_module (T* p) {assert (!module); module.reset (p); return *p;} + + template <typename T> + T& module_as () {assert (module); return static_cast<T&> (*module);} + }; + // Module boot function signature. // - // The module_*_extra arguments (here and in init below) are used to pass - // additional information that is only used by some modules. It is also a - // way for us to later pass more information without breaking source - // compatibility. + // A booted module may set the post function which will be called after + // booting all the modules in bootstrap.build. // // By default a booted module is initialized before loading root.build. // @@ -60,18 +75,29 @@ namespace build2 after }; - struct module_boot_extra + struct module_boot_post_extra: module_common_extra { - shared_ptr<build2::module> module; // Module instance (out). - module_boot_init init; // Init mode (out). + module_boot_init init; // Init mode (in/out). - // Convenience functions. - // - template <typename T> - T& set_module (T* p) {assert (!module); module.reset (p); return *p;} + module_boot_post_extra (const shared_ptr<build2::module>& m, + module_boot_init i) + : module_common_extra {m}, init (i) {} // VC14 + }; - template <typename T> - T& module_as () {assert (module); return static_cast<T&> (*module);} + using module_boot_post_function = + void (scope& root, + const location&, + module_boot_post_extra&); + + struct module_boot_extra: module_common_extra + { + module_boot_post_function* post; // Post-boot function (out). + module_boot_init init; // Init mode (out). + + module_boot_extra (const shared_ptr<build2::module>& m, + module_boot_post_function* p, + module_boot_init i) + : module_common_extra {m}, post (p), init (i) {} // VC14 }; using module_boot_function = @@ -81,18 +107,13 @@ namespace build2 // Module init function signature. // - struct module_init_extra + struct module_init_extra: module_common_extra { - shared_ptr<build2::module> module; // Module instance (in/out). - const variable_map& hints; // Configuration hints (see below). - - // Convenience functions. - // - template <typename T> - T& set_module (T* p) {assert (!module); module.reset (p); return *p;} + const variable_map& hints; // Configuration hints (see below). - template <typename T> - T& module_as () {assert (module); return static_cast<T&> (*module);} + module_init_extra (const shared_ptr<build2::module>& m, + const variable_map& h) + : module_common_extra {m}, hints (h) {} // VC14 }; // Return false if the module configuration (normally based on the default @@ -142,6 +163,7 @@ namespace build2 { location_value loc; // Load location. const string name; + module_boot_post_function* boot_post; module_init_function* init; shared_ptr<build2::module> module; optional<module_boot_init> boot_init; @@ -181,6 +203,11 @@ namespace build2 LIBBUILD2_SYMEXPORT void boot_module (scope& root, const string& name, const location&); + // Post-boot the specified (as state) module. + // + LIBBUILD2_SYMEXPORT void + boot_post_module (scope& root, module_state&); + // Init the specified module loading its library if necessary. Used by the // parser but also by some modules to init prerequisite modules. Return a // pointer to the corresponding module state if the module was both |