From 879b5f52cb86f24352f4ed245fcce5f1ab885f97 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 30 Nov 2017 14:48:19 +0200 Subject: Implement support for scope operation callbacks An entity (module, core) can register a function that will be called when an action is executed on the dir{} target that corresponds to the scope. The pre callback is called just before the recipe and the post -- immediately after. --- build2/scope.hxx | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'build2/scope.hxx') diff --git a/build2/scope.hxx b/build2/scope.hxx index ad1b295..00aba52 100644 --- a/build2/scope.hxx +++ b/build2/scope.hxx @@ -5,8 +5,8 @@ #ifndef BUILD2_SCOPE_HXX #define BUILD2_SCOPE_HXX +#include #include -#include #include @@ -17,11 +17,14 @@ #include #include #include +#include #include #include namespace build2 { + class dir; + class scope { public: @@ -240,6 +243,34 @@ namespace build2 public: rule_map rules; + // Operation callbacks. + // + // An entity (module, core) can register a function that will be called + // when an action is executed on the dir{} target that corresponds to this + // scope. The pre callback is called just before the recipe and the post + // -- immediately after. The callbacks are only called if the recipe + // (including noop recipe) is executed for the corresponding target. The + // callbacks should only be registered during the load phase. + // + // It only makes sense for callbacks to return target_state changed or + // unchanged and to throw failed in case of an error. These pre/post + // states will be merged with the recipe state and become the target + // state. See execute_recipe() for details. + // + public: + struct operation_callback + { + using callback = target_state (action, const scope&, const dir&); + + function pre; + function post; + }; + + using operation_callback_map = std::multimap; + + operation_callback_map operation_callbacks; + // Modules. // public: -- cgit v1.1