aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2021-12-02 10:16:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2021-12-02 10:19:27 +0200
commitbe57ba464fae756d5eb44cf4faf192536dec43ec (patch)
tree362b35157a2e8bd8de1e495ae0da67394c77d01a /libbuild2
parentd3568852ca0506666fbd1b613439a3916c76ed88 (diff)
Add $root_directory(<path>) function
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/functions-path.cxx43
1 files changed, 42 insertions, 1 deletions
diff --git a/libbuild2/functions-path.cxx b/libbuild2/functions-path.cxx
index 2953067..8362d2e 100644
--- a/libbuild2/functions-path.cxx
+++ b/libbuild2/functions-path.cxx
@@ -312,7 +312,11 @@ namespace build2
return ns;
};
- // directory
+ // $directory(<path>)
+ // $directory(<paths>)
+ //
+ // Return the directory part of the path or empty path if there is no
+ // directory. Directory of a root directory is an empty path.
//
f["directory"] += &path::directory;
@@ -346,6 +350,43 @@ namespace build2
return ns;
};
+ // $root_directory(<path>)
+ // $root_directory(<paths>)
+ //
+ // Return the root directory of the path or empty path if the directory is
+ // not absolute.
+ //
+ f["root_directory"] += &path::root_directory;
+
+ f["root_directory"] += [](paths v)
+ {
+ dir_paths r;
+ for (const path& p: v)
+ r.push_back (p.root_directory ());
+ return r;
+ };
+
+ f["root_directory"] += [](dir_paths v)
+ {
+ for (dir_path& p: v)
+ p = p.root_directory ();
+ return v;
+ };
+
+ f[".root_directory"] += [](names ns)
+ {
+ // For each path decide based on the presence of a trailing slash
+ // whether it is a directory. Return as list of directory names.
+ //
+ for (name& n: ns)
+ {
+ if (n.directory ())
+ n.dir = n.dir.root_directory ();
+ else
+ n = convert<path> (move (n)).root_directory ();
+ }
+ return ns;
+ };
// $leaf(<path>)
//