diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2024-05-20 12:27:06 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2024-05-20 12:27:06 +0200 |
commit | 670393b5708e0262757da5052da9a61270c907b7 (patch) | |
tree | df4051b52e25c0086e6c71405fa5febf0aee08b2 /libbuild2 | |
parent | fd94c6f239d2436b6152935b4c99217129953a5d (diff) |
Add $path.absolute(), $path.simple(), $path.sub_path(), $path.super_path()
Diffstat (limited to 'libbuild2')
-rw-r--r-- | libbuild2/functions-path.cxx | 74 |
1 files changed, 74 insertions, 0 deletions
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>) + // $path.absolute(<untyped>) + // + // Return true if the path is absolute and false otherwise. + // + f["absolute"] += [](path p) + { + return p.absolute (); + }; + + f[".absolute"] += [](names ns) + { + return convert<path> (move (ns)).absolute (); + }; + + // $simple(<path>) + // $path.simple(<untyped>) + // + // 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<path> (move (ns)).simple (); + }; + + // $sub_path(<path>, <path>) + // $path.sub_path(<untyped>, <untyped>) + // + // 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<path> (move (v))); + }; + + f[".sub_path"] += [](names ns, value v) + { + return convert<path> (move (ns)).sub (convert_to_base<path> (move (v))); + }; + + // $super_path(<path>, <path>) + // $path.super_path(<untyped>, <untyped>) + // + // 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<path> (move (v))); + }; + + f[".super_path"] += [](names ns, value v) + { + return convert<path> (move (ns)).sup (convert_to_base<path> (move (v))); + }; + // $canonicalize(<paths>) // $path.canonicalize(<untyped>) // @@ -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); |