aboutsummaryrefslogtreecommitdiff
path: root/libbuild2/functions-name.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-09-14 16:07:30 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-09-14 16:07:30 +0200
commitef2fdd0e104494c1a5beee51521563d013a3b3cc (patch)
tree97467cfa48340a68a2c9f213475b26b33c8e122b /libbuild2/functions-name.cxx
parent4e6c213ae904f291d954d430d30238057d7ad4ad (diff)
Add support for passing multiple names to $name.*() functions
Diffstat (limited to 'libbuild2/functions-name.cxx')
-rw-r--r--libbuild2/functions-name.cxx52
1 files changed, 49 insertions, 3 deletions
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<name> (move (ns))).first.value;
+ small_vector<string, 1> 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<name> (move (ns))).second;
};
@@ -86,7 +102,21 @@ namespace build2
};
fn["directory"] += [](const scope* s, names ns)
{
- return to_target_name (s, convert<name> (move (ns))).first.dir;
+ small_vector<dir_path, 1> 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<name> (move (ns))).first.type;
+ small_vector<string, 1> 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<name> (move (ns))).first.proj;
};