aboutsummaryrefslogtreecommitdiff
path: root/build2/scope.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-11-30 14:48:19 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-11-30 14:48:19 +0200
commit879b5f52cb86f24352f4ed245fcce5f1ab885f97 (patch)
treeff483ce4aa64dda7d17b82f956333f0705257568 /build2/scope.hxx
parent074a8c04a384a9752466bd2af69b695333b2955c (diff)
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.
Diffstat (limited to 'build2/scope.hxx')
-rw-r--r--build2/scope.hxx33
1 files changed, 32 insertions, 1 deletions
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 <map>
#include <unordered_set>
-#include <unordered_map>
#include <libbutl/path-map.mxx>
@@ -17,11 +17,14 @@
#include <build2/variable.hxx>
#include <build2/target-key.hxx>
#include <build2/target-type.hxx>
+#include <build2/target-state.hxx>
#include <build2/rule-map.hxx>
#include <build2/operation.hxx>
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<callback> pre;
+ function<callback> post;
+ };
+
+ using operation_callback_map = std::multimap<action_id,
+ operation_callback>;
+
+ operation_callback_map operation_callbacks;
+
// Modules.
//
public: