From bc3c8492f129d9295c9ef6c325bf2c99e88ca73e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 3 Jun 2020 08:39:36 +0200 Subject: Factor implementation-specific ad hoc recipe parsing to adhoc_*_rule --- libbuild2/rule.cxx | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'libbuild2/rule.cxx') 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 +#include + #include #include #include @@ -12,6 +14,8 @@ #include #include +#include // attributes + #include #include @@ -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 diag; + for (auto i (as.begin ()); i != as.end (); ) + { + attribute& a (*i); + const string& n (a.name); + + if (n == "diag") + try + { + diag = convert (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 { -- cgit v1.1