From a414fa7b0ff469013598ca9ef2999ca6293ee7c1 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 24 Sep 2020 10:48:45 +0200 Subject: Add post-boot module function --- libbuild2/module.hxx | 73 +++++++++++++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 23 deletions(-) (limited to 'libbuild2/module.hxx') 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 module; // Module instance (in/out). + + // Convenience functions. + // + template + T& set_module (T* p) {assert (!module); module.reset (p); return *p;} + + template + T& module_as () {assert (module); return static_cast (*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 module; // Module instance (out). - module_boot_init init; // Init mode (out). + module_boot_init init; // Init mode (in/out). - // Convenience functions. - // - template - T& set_module (T* p) {assert (!module); module.reset (p); return *p;} + module_boot_post_extra (const shared_ptr& m, + module_boot_init i) + : module_common_extra {m}, init (i) {} // VC14 + }; - template - T& module_as () {assert (module); return static_cast (*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& 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 module; // Module instance (in/out). - const variable_map& hints; // Configuration hints (see below). - - // Convenience functions. - // - template - T& set_module (T* p) {assert (!module); module.reset (p); return *p;} + const variable_map& hints; // Configuration hints (see below). - template - T& module_as () {assert (module); return static_cast (*module);} + module_init_extra (const shared_ptr& 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 module; optional 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 -- cgit v1.1