aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/rule.hxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2020-06-03 08:39:36 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2020-06-03 08:39:36 +0200
commitbc3c8492f129d9295c9ef6c325bf2c99e88ca73e (patch)
tree79fa0ccfbf030568caa2d521f3bc3dbc613d4796 /libbuild2/rule.hxx
parent7368566619bc990b69f90a4828be2966854fa785 (diff)
Factor implementation-specific ad hoc recipe parsing to adhoc_*_rule
Diffstat (limited to 'libbuild2/rule.hxx')
-rw-r--r--libbuild2/rule.hxx32
1 files changed, 24 insertions, 8 deletions
diff --git a/libbuild2/rule.hxx b/libbuild2/rule.hxx
index 36e4733..05be9eb 100644
--- a/libbuild2/rule.hxx
+++ b/libbuild2/rule.hxx
@@ -116,7 +116,7 @@ namespace build2
// Ad hoc rule.
//
- // Note: not exported
+ // Note: not exported.
//
class adhoc_rule: public rule
{
@@ -129,6 +129,13 @@ namespace build2
braces (b),
rule_match ("adhoc", static_cast<const rule&> (*this)) {}
+ // Set the rule text, handle any recipe-specific attributes, and return
+ // true if the recipe builds anything in the build/recipes/ directory and
+ // therefore requires cleanup.
+ //
+ virtual bool
+ recipe_text (context&, string&&, attributes&) = 0;
+
public:
// Some of the operations come in compensating pairs, such as update and
// clean, install and uninstall. An ad hoc rule implementation may choose
@@ -184,13 +191,16 @@ namespace build2
virtual void
dump (ostream&, string&) const override;
- using script_type = build::script::script;
-
adhoc_script_rule (const location& l, size_t b): adhoc_rule (l, b) {}
+ virtual bool
+ recipe_text (context&, string&&, attributes&) override;
+
public:
+ using script_type = build::script::script;
+
script_type script;
- string checksum; // Script text hashsum.
+ string checksum; // Script text hash.
};
// Ad hoc C++ rule.
@@ -200,7 +210,6 @@ namespace build2
class LIBBUILD2_SYMEXPORT cxx_rule: public rule
{
public:
-
// A robust recipe may want to incorporate the recipe_state into its
// up-to-date decision as if the recipe library was a prerequisite (it
// cannot be injected as a real prerequisite since it's from a different
@@ -232,8 +241,15 @@ namespace build2
virtual void
dump (ostream&, string&) const override;
- adhoc_cxx_rule (string c, const location& l, size_t b)
- : adhoc_rule (l, b), code (move (c)), impl (nullptr) {}
+ adhoc_cxx_rule (const location& l, size_t b)
+ : adhoc_rule (l, b), impl (nullptr) {}
+
+ virtual bool
+ recipe_text (context&, string&& t, attributes&) override
+ {
+ code = move (t);
+ return true;
+ }
virtual
~adhoc_cxx_rule () override;
@@ -242,7 +258,7 @@ namespace build2
// Note that this recipe (rule instance) can be shared between multiple
// targets which could all be matched in parallel.
//
- const string code;
+ string code;
mutable atomic<cxx_rule*> impl;
};
}