diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2020-08-16 16:21:35 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2020-08-16 16:21:35 +0200 |
commit | 534ca7619a62a74bce8e4b30931aaf99f9c3beb6 (patch) | |
tree | 2e4ffc0b8aa6651f5003009df0f372529754b1f5 /libbuild2/config/utility.hxx | |
parent | d91e48ea57b83f7018a25d3f54bba96cf889d66d (diff) |
Add support for post-configure and pre-disfigure hooks
Diffstat (limited to 'libbuild2/config/utility.hxx')
-rw-r--r-- | libbuild2/config/utility.hxx | 47 |
1 files changed, 40 insertions, 7 deletions
diff --git a/libbuild2/config/utility.hxx b/libbuild2/config/utility.hxx index fb3023b..209ef5c 100644 --- a/libbuild2/config/utility.hxx +++ b/libbuild2/config/utility.hxx @@ -22,13 +22,14 @@ namespace build2 // // The only persistence-specific aspects of this functionality are marking // of the variables as to be persisted (saved, potentially with flags), - // establishing the module saving order (priority), and configuration - // creation (the create meta-operation implementation) These are accessed - // through the config module entry points (which are NULL for transient - // configurations). Note also that the exact interpretation of the save - // flags and module order depends on the config module implementation (which - // may ignore them as not applicable). An implementation may also define - // custom save flags (for example, accessible through the config.save + // establishing the module saving order (priority), configuration creation + // (the create meta-operation implementation), as well as configure and + // disfigure hooks (for example, for second-level configuration). These are + // accessed through the config module entry points (which are NULL for + // transient configurations). Note also that the exact interpretation of the + // save flags and module order depends on the config module implementation + // (which may ignore them as not applicable). An implementation may also + // define custom save flags (for example, accessible through the config.save // attribute). Such flags should start from 0x100000000. // LIBBUILD2_SYMEXPORT extern void @@ -44,6 +45,12 @@ namespace build2 bool, const location&); + LIBBUILD2_SYMEXPORT extern bool + (*config_configure_post) (scope&, bool (*)(action, const scope&)); + + LIBBUILD2_SYMEXPORT extern bool + (*config_disfigure_pre) (scope&, bool (*)(action, const scope&)); + namespace config { // Mark the variable to be saved during configuration. @@ -77,6 +84,32 @@ namespace build2 config_save_module (rs, module, prio); } + // Post-configure and pre-disfigure hooks. Normally used to save/remove + // persistent state. Return true if anything has been done (used for + // diagnostics). + // + // The registration functions return true if the hook has been registered. + // + // Note that the hooks are called for the top-level project and all its + // subprojects (if registered in the subproject root scope), from outer to + // inner for configure and from inner to outer for disfigure. It's the + // responsibility of the hook implementation to handle any aggregation. + // + using configure_post_hook = bool (action, const scope&); + using disfigure_pre_hook = bool (action, const scope&); + + inline bool + configure_post (scope& rs, configure_post_hook* h) + { + return config_configure_post != nullptr && config_configure_post (rs, h); + } + + inline bool + disfigure_pre (scope& rs, disfigure_pre_hook* h) + { + return config_disfigure_pre != nullptr && config_disfigure_pre (rs, h); + } + // Lookup a config.* variable value and, if the value is defined, mark it // as saved. // |