aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/rule.cxx
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.cxx
parent7368566619bc990b69f90a4828be2966854fa785 (diff)
Factor implementation-specific ad hoc recipe parsing to adhoc_*_rule
Diffstat (limited to 'libbuild2/rule.cxx')
-rw-r--r--libbuild2/rule.cxx42
1 files changed, 42 insertions, 0 deletions
diff --git a/libbuild2/rule.cxx b/libbuild2/rule.cxx
index 5f532ef..7f9c357 100644
--- a/libbuild2/rule.cxx
+++ b/libbuild2/rule.cxx
@@ -3,6 +3,8 @@
#include <libbuild2/rule.hxx>
+#include <sstream>
+
#include <libbuild2/file.hxx>
#include <libbuild2/depdb.hxx>
#include <libbuild2/scope.hxx>
@@ -12,6 +14,8 @@
#include <libbuild2/filesystem.hxx>
#include <libbuild2/diagnostics.hxx>
+#include <libbuild2/parser.hxx> // attributes
+
#include <libbuild2/build/script/parser.hxx>
#include <libbuild2/build/script/runner.hxx>
@@ -360,6 +364,44 @@ namespace build2
// adhoc_script_rule
//
+ bool adhoc_script_rule::
+ recipe_text (context& ctx, string&& t, attributes& as)
+ {
+ // Handle and erase recipe-specific attributes.
+ //
+ optional<string> diag;
+ for (auto i (as.begin ()); i != as.end (); )
+ {
+ attribute& a (*i);
+ const string& n (a.name);
+
+ if (n == "diag")
+ try
+ {
+ diag = convert<string> (move (a.value));
+ }
+ catch (const invalid_argument& e)
+ {
+ fail (as.loc) << "invalid " << n << " attribute value: " << e;
+ }
+ else
+ {
+ ++i;
+ continue;
+ }
+
+ i = as.erase (i);
+ }
+
+ checksum = sha256 (t).string ();
+
+ istringstream is (move (t));
+ build::script::parser p (ctx);
+ script = p.pre_parse (is, loc.file, loc.line + 1, move (diag));
+
+ return false;
+ }
+
void adhoc_script_rule::
dump (ostream& os, string& ind) const
{