aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/rule.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-04-06 11:26:52 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-04-06 13:51:56 +0200
commit76be0a35f6c37cda7ba65530330f1ac246fb52a8 (patch)
treef613ceafcf6c7208984d4536653061c4e0c23be7 /libbuild2/rule.cxx
parent0a9dd0c7d31cbba2170fdfda4b747a1fe5ce665a (diff)
Add support for rule hints
A rule hint is a target attribute, for example: [rule_hint=cxx] exe{hello}: c{hello} Rule hints can be used to resolve ambiguity when multiple rules match the same target as well as to override an unambiguous match.
Diffstat (limited to 'libbuild2/rule.cxx')
-rw-r--r--libbuild2/rule.cxx29
1 files changed, 22 insertions, 7 deletions
diff --git a/libbuild2/rule.cxx b/libbuild2/rule.cxx
index c573339..acb46e8 100644
--- a/libbuild2/rule.cxx
+++ b/libbuild2/rule.cxx
@@ -22,12 +22,20 @@ namespace build2
{
}
+ bool rule::
+ sub_match (const string& n, operation_id o,
+ action a, target& t, match_extra& me) const
+ {
+ const string& h (t.find_hint (o));
+ return name_rule_map::sub (h, n) && match (a, t, h, me);
+ }
+
// simple_rule
//
bool simple_rule::
- match (action a, target& t, const string& h, match_extra&) const
+ match (action a, target& t, const string&, match_extra&) const
{
- return match (a, t, h);
+ return match (a, t);
}
recipe simple_rule::
@@ -36,6 +44,13 @@ namespace build2
return apply (a, t);
}
+ bool simple_rule::
+ sub_match (const string& n, operation_id o,
+ action a, target& t) const
+ {
+ return name_rule_map::sub (t.find_hint (o), n) && match (a, t);
+ }
+
// file_rule
//
// Note that this rule is special. It is the last, fallback rule. If
@@ -46,7 +61,7 @@ namespace build2
// use it as a guide to implement your own, normal, rules.
//
bool file_rule::
- match (action a, target& t, const string&) const
+ match (action a, target& t, const string&, match_extra&) const
{
tracer trace ("file_rule::match");
@@ -124,7 +139,7 @@ namespace build2
}
recipe file_rule::
- apply (action a, target& t) const
+ apply (action a, target& t, match_extra&) const
{
// Update triggers the update of this target's prerequisites so it would
// seem natural that we should also trigger their cleanup. However, this
@@ -161,7 +176,7 @@ namespace build2
// alias_rule
//
bool alias_rule::
- match (action, target&, const string&) const
+ match (action, target&) const
{
return true;
}
@@ -183,7 +198,7 @@ namespace build2
// fsdir_rule
//
bool fsdir_rule::
- match (action, target&, const string&) const
+ match (action, target&) const
{
return true;
}
@@ -318,7 +333,7 @@ namespace build2
// noop_rule
//
bool noop_rule::
- match (action, target&, const string&) const
+ match (action, target&) const
{
return true;
}