From ea57c514dc169afb3ece21ff2e4c1d2ab0c47d6a Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 4 Aug 2021 06:45:02 +0200 Subject: Take into account file-base'ness in ad hoc buildscript recipes --- libbuild2/adhoc-rule-buildscript.cxx | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'libbuild2/adhoc-rule-buildscript.cxx') diff --git a/libbuild2/adhoc-rule-buildscript.cxx b/libbuild2/adhoc-rule-buildscript.cxx index c715ff2..61b4cb2 100644 --- a/libbuild2/adhoc-rule-buildscript.cxx +++ b/libbuild2/adhoc-rule-buildscript.cxx @@ -23,7 +23,10 @@ using namespace std; namespace build2 { bool adhoc_buildscript_rule:: - recipe_text (const scope& s, string&& t, attributes& as) + recipe_text (const scope& s, + const target_type& tt, + string&& t, + attributes& as) { // Handle and erase recipe-specific attributes. // @@ -52,11 +55,12 @@ namespace build2 } checksum = sha256 (t).string (); + ttype = &tt; istringstream is (move (t)); build::script::parser p (s.ctx); - script = p.pre_parse (s, actions, + script = p.pre_parse (s, tt, actions, is, loc.file, loc.line + 1, move (diag), as.loc); @@ -109,6 +113,25 @@ namespace build2 perform_update_id) != actions.end (); } + bool adhoc_buildscript_rule:: + match (action a, target& t, const string& h, match_extra& me) const + { + // We pre-parsed the script with the assumption it will be used on a + // non/file-based target. Note that this should not be possible with + // patterns. + // + if (pattern == nullptr) + { + if ((t.is_a () != nullptr) != ttype->is_a ()) + { + fail (loc) << "incompatible target types used with shared recipe" << + info << "all targets must be file-based or non-file-based"; + } + } + + return adhoc_rule::match (a, t, h, me); + } + recipe adhoc_buildscript_rule:: apply (action a, target& t, match_extra& me) const { -- cgit v1.1