aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-04-28 07:29:11 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-04-30 14:44:21 +0200
commit9498585efc6e92eabca596d2ecbb78ffb343bca2 (patch)
tree6cee37adc289643e37f7c5827490669a6e9e1dda /libbuild2
parent68cc1badd2eb96fd1f89e8b6519d45039ff983ba (diff)
Factor recipe to separate header/source files
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/action.hxx7
-rw-r--r--libbuild2/algorithm.hxx11
-rw-r--r--libbuild2/recipe.cxx14
-rw-r--r--libbuild2/recipe.hxx53
-rw-r--r--libbuild2/rule.hxx1
-rw-r--r--libbuild2/target.cxx7
-rw-r--r--libbuild2/target.hxx48
-rw-r--r--libbuild2/target.ixx3
8 files changed, 86 insertions, 58 deletions
diff --git a/libbuild2/action.hxx b/libbuild2/action.hxx
index ec2701f..c1e4697 100644
--- a/libbuild2/action.hxx
+++ b/libbuild2/action.hxx
@@ -40,9 +40,10 @@ namespace build2
// it via rule/recipe override but that didn't end up well, to put it
// mildly). While the outer operation normally "directs" the inner, inner
// rules can still be matched/executed directly, without outer's involvement
- // (e.g., because of other inner rules). A typical implementation of an
- // outer rule either returns noop or delegates to the inner rule. In
- // particular, it should not replace or override the inner's logic.
+ // (e.g., because of dependencies in other inner rules). A typical
+ // implementation of an outer rule either returns noop or delegates to the
+ // inner rule. In particular, it should not replace or override the inner's
+ // logic.
//
// While most of the relevant target state is duplicated, certain things are
// shared among the inner/outer rules, such as the target data pad and the
diff --git a/libbuild2/algorithm.hxx b/libbuild2/algorithm.hxx
index ad4ee74..390516a 100644
--- a/libbuild2/algorithm.hxx
+++ b/libbuild2/algorithm.hxx
@@ -10,6 +10,7 @@
#include <libbuild2/action.hxx>
#include <libbuild2/target.hxx>
+#include <libbuild2/recipe.hxx>
#include <libbuild2/export.hxx>
@@ -673,12 +674,18 @@ namespace build2
LIBBUILD2_SYMEXPORT target_state
noop_action (action, const target&);
- // Default action implementation which forwards to the prerequisites.
- // Use default_recipe instead of using this function directly.
+ // Default action implementation which forwards to the prerequisites. Use
+ // default_recipe instead of using this function directly.
//
LIBBUILD2_SYMEXPORT target_state
default_action (action, const target&);
+ // Group action which calls the group's recipe. Use group_recipe instead of
+ // using this function directly.
+ //
+ LIBBUILD2_SYMEXPORT target_state
+ group_action (action, const target&);
+
// Standard perform(clean) action implementation for the file target
// (or derived).
//
diff --git a/libbuild2/recipe.cxx b/libbuild2/recipe.cxx
new file mode 100644
index 0000000..3720059
--- /dev/null
+++ b/libbuild2/recipe.cxx
@@ -0,0 +1,14 @@
+// file : libbuild2/target.cxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#include <libbuild2/target.hxx>
+
+#include <libbuild2/algorithm.hxx>
+
+namespace build2
+{
+ const recipe empty_recipe;
+ const recipe noop_recipe (&noop_action);
+ const recipe default_recipe (&default_action);
+ const recipe group_recipe (&group_action);
+}
diff --git a/libbuild2/recipe.hxx b/libbuild2/recipe.hxx
new file mode 100644
index 0000000..508c059
--- /dev/null
+++ b/libbuild2/recipe.hxx
@@ -0,0 +1,53 @@
+// file : libbuild2/recipe.hxx -*- C++ -*-
+// license : MIT; see accompanying LICENSE file
+
+#ifndef LIBBUILD2_RECIPE_HXX
+#define LIBBUILD2_RECIPE_HXX
+
+#include <libbuild2/types.hxx>
+#include <libbuild2/forward.hxx>
+#include <libbuild2/utility.hxx>
+
+#include <libbuild2/action.hxx>
+#include <libbuild2/target-state.hxx>
+
+#include <libbuild2/export.hxx>
+
+namespace build2
+{
+ // The returned target state is normally changed or unchanged. If there is
+ // an error, then the recipe should throw failed rather than returning (this
+ // is the only exception that a recipe can throw).
+ //
+ // The return value of the recipe is used to update the target state. If it
+ // is target_state::group then the target's state is the group's state.
+ //
+ // The recipe may also return postponed in which case the target state is
+ // assumed to be unchanged (normally this means a prerequisite was postponed
+ // and while the prerequisite will be re-examined via another dependency,
+ // this target is done).
+ //
+ // Note that max size for the "small capture optimization" in std::function
+ // ranges (in pointer sizes) from 0 (GCC prior to 5) to 2 (GCC 5) to 6 (VC
+ // 14.2). With the size ranging (in bytes for 64-bit target) from 32 (GCC)
+ // to 64 (VC).
+ //
+ using recipe_function = target_state (action, const target&);
+ using recipe = function<recipe_function>;
+
+ // Commonly-used recipes.
+ //
+ // The default recipe executes the action on all the prerequisites in a
+ // loop, skipping ignored. Specifically, for actions with the "first"
+ // execution mode, it calls execute_prerequisites() while for those with
+ // "last" -- reverse_execute_prerequisites() (see <libbuild2/operation.hxx>,
+ // <libbuild2/algorithm.hxx> for details). The group recipe calls the
+ // group's recipe.
+ //
+ LIBBUILD2_SYMEXPORT extern const recipe empty_recipe;
+ LIBBUILD2_SYMEXPORT extern const recipe noop_recipe;
+ LIBBUILD2_SYMEXPORT extern const recipe default_recipe;
+ LIBBUILD2_SYMEXPORT extern const recipe group_recipe;
+}
+
+#endif // LIBBUILD2_RECIPE_HXX
diff --git a/libbuild2/rule.hxx b/libbuild2/rule.hxx
index e5e53d1..9eab1f6 100644
--- a/libbuild2/rule.hxx
+++ b/libbuild2/rule.hxx
@@ -10,6 +10,7 @@
#include <libbuild2/action.hxx>
#include <libbuild2/target.hxx>
+#include <libbuild2/recipe.hxx>
#include <libbuild2/export.hxx>
diff --git a/libbuild2/target.cxx b/libbuild2/target.cxx
index d313b05..83ed4a5 100644
--- a/libbuild2/target.cxx
+++ b/libbuild2/target.cxx
@@ -82,13 +82,6 @@ namespace build2
return os << target_state_[static_cast<uint8_t> (ts)];
}
- // recipe
- //
- const recipe empty_recipe;
- const recipe noop_recipe (&noop_action);
- const recipe default_recipe (&default_action);
- const recipe group_recipe (&group_action);
-
// target
//
const target::prerequisites_type target::empty_prerequisites_;
diff --git a/libbuild2/target.hxx b/libbuild2/target.hxx
index 8adaa2c..eea43df 100644
--- a/libbuild2/target.hxx
+++ b/libbuild2/target.hxx
@@ -16,6 +16,7 @@
#include <libbuild2/scope.hxx>
#include <libbuild2/action.hxx>
+#include <libbuild2/recipe.hxx>
#include <libbuild2/context.hxx>
#include <libbuild2/variable.hxx>
#include <libbuild2/target-key.hxx>
@@ -52,51 +53,6 @@ namespace build2
value v_;
};
- // Recipe.
- //
- // The returned target state is normally changed or unchanged. If there is
- // an error, then the recipe should throw failed rather than returning (this
- // is the only exception that a recipe can throw).
- //
- // The return value of the recipe is used to update the target state. If it
- // is target_state::group then the target's state is the group's state.
- //
- // The recipe may also return postponed in which case the target state is
- // assumed to be unchanged (normally this means a prerequisite was postponed
- // and while the prerequisite will be re-examined via another dependency,
- // this target is done).
- //
- // Note that max size for the "small capture optimization" in std::function
- // ranges (in pointer sizes) from 0 (GCC prior to 5) to 2 (GCC 5) to 6 (VC
- // 14.2). With the size ranging (in bytes for 64-bit target) from 32 (GCC)
- // to 64 (VC).
- //
- using recipe_function = target_state (action, const target&);
- using recipe = function<recipe_function>;
-
- // Commonly-used recipes. The default recipe executes the action on
- // all the prerequisites in a loop, skipping ignored. Specifically,
- // for actions with the "first" execution mode, it calls
- // execute_prerequisites() while for those with the "last" mode --
- // reverse_execute_prerequisites(); see <libbuild2/operation.hxx>,
- // <libbuild2/algorithm.hxx> for details. The group recipe call's the
- // group's recipe.
- //
- LIBBUILD2_SYMEXPORT extern const recipe empty_recipe;
- LIBBUILD2_SYMEXPORT extern const recipe noop_recipe;
- LIBBUILD2_SYMEXPORT extern const recipe default_recipe;
- LIBBUILD2_SYMEXPORT extern const recipe group_recipe;
-
- // Defined in <libbuild2/algorithm.hxx>.
- //
- LIBBUILD2_SYMEXPORT target_state
- noop_action (action, const target&);
-
- // Defined in <libbuild2/algorithm.hxx>.
- //
- LIBBUILD2_SYMEXPORT target_state
- group_action (action, const target&);
-
// A view of target group members.
//
struct group_view
@@ -484,7 +440,7 @@ namespace build2
static const size_t offset_executed = 5; // Recipe has been executed.
static const size_t offset_busy = 6; // Match/execute in progress.
- // Inner/outer operation state. See <libbuild2/operation.hxx> for details.
+ // Inner/outer operation state. See <libbuild2/action.hxx> for details.
//
class LIBBUILD2_SYMEXPORT opstate
{
diff --git a/libbuild2/target.ixx b/libbuild2/target.ixx
index 5f53f3d..4717800 100644
--- a/libbuild2/target.ixx
+++ b/libbuild2/target.ixx
@@ -87,6 +87,9 @@ namespace build2
return c >= offset_matched;
}
+ LIBBUILD2_SYMEXPORT target_state
+ group_action (action, const target&); // <libbuild2/algorithm.hxx>
+
inline bool target::
group_state (action a) const
{