diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2021-12-16 09:24:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2021-12-16 09:24:06 +0200 |
commit | 5c3744e914d72916d30c9b4cb4804227d6aae736 (patch) | |
tree | 356f4a6a14f5c33772b9094416f37aa39cbd26ba /libbuild2 | |
parent | fb9f2206a3a9b860480d2e9967561b47c1e86351 (diff) |
Pass context to (meta-)operation hooks
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/config/operation.cxx | 8 | ||||
-rw-r--r-- | libbuild2/dist/operation.cxx | 18 | ||||
-rw-r--r-- | libbuild2/install/operation.cxx | 9 | ||||
-rw-r--r-- | libbuild2/module.cxx | 10 | ||||
-rw-r--r-- | libbuild2/operation.cxx | 2 | ||||
-rw-r--r-- | libbuild2/operation.hxx | 15 | ||||
-rw-r--r-- | libbuild2/test/operation.cxx | 9 |
7 files changed, 40 insertions, 31 deletions
diff --git a/libbuild2/config/operation.cxx b/libbuild2/config/operation.cxx index 5883d8c..8ceb4d4 100644 --- a/libbuild2/config/operation.cxx +++ b/libbuild2/config/operation.cxx @@ -806,7 +806,7 @@ namespace build2 operation_id (*pre) (const values&, meta_operation_id, const location&); static operation_id - configure_operation_pre (const values&, operation_id o) + configure_operation_pre (context&, const values&, operation_id o) { // Don't translate default to update. In our case unspecified // means configure everything. @@ -845,7 +845,7 @@ namespace build2 } static void - configure_pre (const values& params, const location& l) + configure_pre (context&, const values& params, const location& l) { forward (params, "configure", l); // Validate. } @@ -1152,13 +1152,13 @@ namespace build2 } static void - disfigure_pre (const values& params, const location& l) + disfigure_pre (context&, const values& params, const location& l) { forward (params, "disfigure", l); // Validate. } static operation_id - disfigure_operation_pre (const values&, operation_id o) + disfigure_operation_pre (context&, const values&, operation_id o) { // Don't translate default to update. In our case unspecified // means disfigure everything. diff --git a/libbuild2/dist/operation.cxx b/libbuild2/dist/operation.cxx index a799cfc..f3db8ad 100644 --- a/libbuild2/dist/operation.cxx +++ b/libbuild2/dist/operation.cxx @@ -56,7 +56,7 @@ namespace build2 const path& arc, const dir_path& dir, const string& ext); static operation_id - dist_operation_pre (const values&, operation_id o) + dist_operation_pre (context&, const values&, operation_id o) { if (o != default_id) fail << "explicit operation specified for dist meta-operation"; @@ -267,9 +267,9 @@ namespace build2 // Use standard (perform) match. // - if (oif->pre != nullptr) + if (auto pp = oif->pre_operation) { - if (operation_id pid = oif->pre (params, dist_id, loc)) + if (operation_id pid = pp (ctx, params, dist_id, loc)) { const operation_info* poif (ops[pid]); ctx.current_operation (*poif, oif, false /* diag_noise */); @@ -286,9 +286,9 @@ namespace build2 1 /* diag (failures only) */, false /* progress */); - if (oif->post != nullptr) + if (auto po = oif->post_operation) { - if (operation_id pid = oif->post (params, dist_id)) + if (operation_id pid = po (ctx, params, dist_id)) { const operation_info* poif (ops[pid]); ctx.current_operation (*poif, oif, false /* diag_noise */); @@ -411,7 +411,7 @@ namespace build2 // { if (mo_perform.meta_operation_pre != nullptr) - mo_perform.meta_operation_pre (params, loc); + mo_perform.meta_operation_pre (ctx, params, loc); // This is a hack since according to the rules we need to completely // reset the state. We could have done that (i.e., saved target @@ -427,7 +427,7 @@ namespace build2 ctx.current_on = on + 1; if (mo_perform.operation_pre != nullptr) - mo_perform.operation_pre (params, update_id); + mo_perform.operation_pre (ctx, params, update_id); ctx.current_operation (op_update, nullptr, false /* diag_noise */); @@ -442,10 +442,10 @@ namespace build2 prog /* progress */); if (mo_perform.operation_post != nullptr) - mo_perform.operation_post (params, update_id); + mo_perform.operation_post (ctx, params, update_id); if (mo_perform.meta_operation_post != nullptr) - mo_perform.meta_operation_post (params); + mo_perform.meta_operation_post (ctx, params); } } else diff --git a/libbuild2/install/operation.cxx b/libbuild2/install/operation.cxx index 54d5b9a..52e8c94 100644 --- a/libbuild2/install/operation.cxx +++ b/libbuild2/install/operation.cxx @@ -13,7 +13,10 @@ namespace build2 namespace install { static operation_id - install_pre (const values& params, meta_operation_id mo, const location& l) + install_pre (context&, + const values& params, + meta_operation_id mo, + const location& l) { if (!params.empty ()) fail (l) << "unexpected parameters for operation install"; @@ -82,8 +85,8 @@ namespace build2 op_update.name_done, op_update.mode, op_update.concurrency, - op_update.pre, - op_update.post, + op_update.pre_operation, + op_update.post_operation, op_update.adhoc_match, op_update.adhoc_apply }; diff --git a/libbuild2/module.cxx b/libbuild2/module.cxx index 9756860..3f4f1d0 100644 --- a/libbuild2/module.cxx +++ b/libbuild2/module.cxx @@ -91,8 +91,8 @@ namespace build2 // We use the same context for building any nested modules that might be // required while building modules. // - ctx.module_context = ctx.module_context_storage->get (); - ctx.module_context->module_context = ctx.module_context; + context& mctx (*(ctx.module_context = ctx.module_context_storage->get ())); + mctx.module_context = &mctx; // Setup the context to perform update. In a sense we have a long-running // perform meta-operation batch (indefinite, in fact, since we never call @@ -104,12 +104,12 @@ namespace build2 // recipes) we will see the old state. // if (mo_perform.meta_operation_pre != nullptr) - mo_perform.meta_operation_pre ({} /* parameters */, loc); + mo_perform.meta_operation_pre (mctx, {} /* parameters */, loc); - ctx.module_context->current_meta_operation (mo_perform); + mctx.current_meta_operation (mo_perform); if (mo_perform.operation_pre != nullptr) - mo_perform.operation_pre ({} /* parameters */, update_id); + mo_perform.operation_pre (mctx, {} /* parameters */, update_id); } // Note: also used by ad hoc recipes thus not static. diff --git a/libbuild2/operation.cxx b/libbuild2/operation.cxx index f1fc83c..8ef1a13 100644 --- a/libbuild2/operation.cxx +++ b/libbuild2/operation.cxx @@ -483,7 +483,7 @@ namespace build2 // info // static operation_id - info_operation_pre (const values&, operation_id o) + info_operation_pre (context&, const values&, operation_id o) { if (o != default_id) fail << "explicit operation specified for meta-operation info"; diff --git a/libbuild2/operation.hxx b/libbuild2/operation.hxx index d80a01c..2f88e88 100644 --- a/libbuild2/operation.hxx +++ b/libbuild2/operation.hxx @@ -82,8 +82,8 @@ namespace build2 // then default_id is used. If, however, operation_pre() is NULL, // then default_id is translated to update_id. // - void (*meta_operation_pre) (const values&, const location&); - operation_id (*operation_pre) (const values&, operation_id); + void (*meta_operation_pre) (context&, const values&, const location&); + operation_id (*operation_pre) (context&, const values&, operation_id); // Meta-operation-specific logic to load the buildfile, search and match // the targets, and execute the action on the targets. @@ -121,8 +121,8 @@ namespace build2 // End of operation and meta-operation batches. // - void (*operation_post) (const values&, operation_id); - void (*meta_operation_post) (const values&); + void (*operation_post) (context&, const values&, operation_id); + void (*meta_operation_post) (context&, const values&); // Optional prerequisite exclusion override callback. See include() for // details. Note that it's not called for include_type::normal; @@ -225,8 +225,11 @@ namespace build2 // as pre/post operations for this operation. Can be NULL if unused. // The returned operation_id shall not be default_id. // - operation_id (*pre) (const values&, meta_operation_id, const location&); - operation_id (*post) (const values&, meta_operation_id); + operation_id (*pre_operation) ( + context&, const values&, meta_operation_id, const location&); + + operation_id (*post_operation) ( + context&, const values&, meta_operation_id); // Operation-specific ad hoc rule callbacks. Essentially, if not NULL, // then every ad hoc rule match and apply call for this operation is diff --git a/libbuild2/test/operation.cxx b/libbuild2/test/operation.cxx index 0a65bed..841abb5 100644 --- a/libbuild2/test/operation.cxx +++ b/libbuild2/test/operation.cxx @@ -17,7 +17,10 @@ namespace build2 namespace test { static operation_id - test_pre (const values& params, meta_operation_id mo, const location& l) + test_pre (context&, + const values& params, + meta_operation_id mo, + const location& l) { if (!params.empty ()) fail (l) << "unexpected parameters for operation test"; @@ -85,8 +88,8 @@ namespace build2 op_update.name_done, op_update.mode, op_update.concurrency, - op_update.pre, - op_update.post, + op_update.pre_operation, + op_update.post_operation, op_update.adhoc_match, op_update.adhoc_apply }; |