From 670393b5708e0262757da5052da9a61270c907b7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Mon, 20 May 2024 12:27:06 +0200 Subject: Add $path.absolute(), $path.simple(), $path.sub_path(), $path.super_path() --- libbuild2/functions-path.cxx | 74 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'libbuild2/functions-path.cxx') diff --git a/libbuild2/functions-path.cxx b/libbuild2/functions-path.cxx index 4b114f5..7dfbd67 100644 --- a/libbuild2/functions-path.cxx +++ b/libbuild2/functions-path.cxx @@ -344,6 +344,78 @@ namespace build2 return ns; }; + // $absolute() + // $path.absolute() + // + // Return true if the path is absolute and false otherwise. + // + f["absolute"] += [](path p) + { + return p.absolute (); + }; + + f[".absolute"] += [](names ns) + { + return convert (move (ns)).absolute (); + }; + + // $simple() + // $path.simple() + // + // Return true if the path is simple, that is, has no direcrory component, + // and false otherwise. + // + // Note that on POSIX `/foo` is not a simple path (it is `foo` in the root + // directory) while `/` is (it is the root directory). + // + f["simple"] += [](path p) + { + return p.simple (); + }; + + f[".simple"] += [](names ns) + { + return convert (move (ns)).simple (); + }; + + // $sub_path(, ) + // $path.sub_path(, ) + // + // Return true if the path specified as the first argument is a sub-path + // of the one specified as the second argument (in other words, the second + // argument is a prefix of the first) and false otherwise. Both paths are + // expected to be normalized. Note that this function returns true if the + // paths are equal. Empty path is considered a prefix of any path. + // + f["sub_path"] += [](path p, value v) + { + return p.sub (convert_to_base (move (v))); + }; + + f[".sub_path"] += [](names ns, value v) + { + return convert (move (ns)).sub (convert_to_base (move (v))); + }; + + // $super_path(, ) + // $path.super_path(, ) + // + // Return true if the path specified as the first argument is a super-path + // of the one specified as the second argument (in other words, the second + // argument is a suffix of the first) and false otherwise. Both paths are + // expected to be normalized. Note that this function returns true if the + // paths are equal. Empty path is considered a suffix of any path. + // + f["super_path"] += [](path p, value v) + { + return p.sup (convert_to_base (move (v))); + }; + + f[".super_path"] += [](names ns, value v) + { + return convert (move (ns)).sup (convert_to_base (move (v))); + }; + // $canonicalize() // $path.canonicalize() // @@ -615,6 +687,8 @@ namespace build2 // specified paths). Issue diagnostics and fail if a relative path cannot // be derived (for example, paths are on different drives on Windows). // + // Note: to check if a path if relative, use `$path.absolute()`. + // f["relative"] += [](path p, dir_path d) { return relative (p, d); -- cgit v1.1