From e2445d5d031b9489215cbac4f39db56cd40270df Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 2 Jun 2020 08:06:31 +0200 Subject: Add $target.process_path() analogous to $target.path() --- libbuild2/functions-name.cxx | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'libbuild2/functions-name.cxx') diff --git a/libbuild2/functions-name.cxx b/libbuild2/functions-name.cxx index 70659ee..ca0f8ce 100644 --- a/libbuild2/functions-name.cxx +++ b/libbuild2/functions-name.cxx @@ -114,7 +114,7 @@ namespace build2 fn["path"] = [](const scope* s, names ns) { if (s == nullptr) - fail << "target.path() called out of scope" << endf; + fail << "target.path() called out of scope"; // Most of the time we will have a single target so optimize for that. // @@ -150,6 +150,34 @@ namespace build2 make_move_iterator (r.end ()))); }; + // This one can only be called on a single target since we don't support + // containers of process_path's (though we probably could). + // + fn["process_path"] = [](const scope* s, names ns) + { + if (s == nullptr) + fail << "target.process_path() called out of scope"; + + if (ns.empty () || ns.size () != (ns[0].pair ? 2 : 1)) + fail << "target.process_path() expects single target"; + + name o; + const target& t ( + to_target (*s, move (ns[0]), move (ns[0].pair ? ns[1] : o))); + + if (const auto* et = t.is_a ()) + { + process_path r (et->process_path ()); + + if (r.empty ()) + fail << "target " << t << " path is not assigned"; + + return r; + } + else + fail << "target " << t << " is not process_path-based" << endf; + }; + // Name-specific overloads from builtins. // function_family fb (m, "builtin"); -- cgit v1.1