From ef2fdd0e104494c1a5beee51521563d013a3b3cc Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 14 Sep 2021 16:07:30 +0200 Subject: Add support for passing multiple names to $name.*() functions --- libbuild2/functions-name.cxx | 52 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) (limited to 'libbuild2') diff --git a/libbuild2/functions-name.cxx b/libbuild2/functions-name.cxx index e821e52..980cd09 100644 --- a/libbuild2/functions-name.cxx +++ b/libbuild2/functions-name.cxx @@ -65,7 +65,21 @@ namespace build2 }; fn["name"] += [](const scope* s, names ns) { - return to_target_name (s, convert (move (ns))).first.value; + small_vector r; + + for (name& n: ns) + { + if (n.pair) + fail << "name pair in names"; + + r.push_back (to_target_name (s, move (n)).first.value); + } + + if (r.size () == 1) + return value (move (r[0])); + + return value (strings (make_move_iterator (r.begin ()), + make_move_iterator (r.end ()))); }; // Note: returns NULL if extension is unspecified (default) and empty if @@ -77,6 +91,8 @@ namespace build2 }; fn["extension"] += [](const scope* s, names ns) { + // Note: can't do multiple due to NULL semantics. + // return to_target_name (s, convert (move (ns))).second; }; @@ -86,7 +102,21 @@ namespace build2 }; fn["directory"] += [](const scope* s, names ns) { - return to_target_name (s, convert (move (ns))).first.dir; + small_vector r; + + for (name& n: ns) + { + if (n.pair) + fail << "name pair in names"; + + r.push_back (to_target_name (s, move (n)).first.dir); + } + + if (r.size () == 1) + return value (move (r[0])); + + return value (dir_paths (make_move_iterator (r.begin ()), + make_move_iterator (r.end ()))); }; fn["target_type"] += [](const scope* s, name n) @@ -95,7 +125,21 @@ namespace build2 }; fn["target_type"] += [](const scope* s, names ns) { - return to_target_name (s, convert (move (ns))).first.type; + small_vector r; + + for (name& n: ns) + { + if (n.pair) + fail << "name pair in names"; + + r.push_back (to_target_name (s, move (n)).first.type); + } + + if (r.size () == 1) + return value (move (r[0])); + + return value (strings (make_move_iterator (r.begin ()), + make_move_iterator (r.end ()))); }; // Note: returns NULL if no project specified. @@ -106,6 +150,8 @@ namespace build2 }; fn["project"] += [](const scope* s, names ns) { + // Note: can't do multiple due to NULL semantics. + // return to_target_name (s, convert (move (ns))).first.proj; }; -- cgit v1.1