aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build2/functions-path.cxx55
-rw-r--r--tests/function/path/testscript20
2 files changed, 56 insertions, 19 deletions
diff --git a/build2/functions-path.cxx b/build2/functions-path.cxx
index 243f0d7..fe6b421 100644
--- a/build2/functions-path.cxx
+++ b/build2/functions-path.cxx
@@ -98,8 +98,19 @@ namespace build2
f["canonicalize"] = [](path p) {p.canonicalize (); return p;};
f["canonicalize"] = [](dir_path p) {p.canonicalize (); return p;};
- f["canonicalize"] = [](paths v) {for (auto& p: v) p.canonicalize (); return v;};
- f["canonicalize"] = [](dir_paths v) {for (auto& p: v) p.canonicalize (); return v;};
+ f["canonicalize"] = [](paths v)
+ {
+ for (auto& p: v)
+ p.canonicalize ();
+ return v;
+ };
+
+ f["canonicalize"] = [](dir_paths v)
+ {
+ for (auto& p: v)
+ p.canonicalize ();
+ return v;
+ };
f[".canonicalize"] = [](names ns)
{
@@ -119,14 +130,40 @@ namespace build2
// normalize
//
- f["normalize"] = [](path p) {p.normalize (); return p;};
- f["normalize"] = [](dir_path p) {p.normalize (); return p;};
+ f["normalize"] = [](path p, optional<value> a)
+ {
+ p.normalize (a && convert<bool> (move (*a)));
+ return p;
+ };
+
+ f["normalize"] = [](dir_path p, optional<value> a)
+ {
+ p.normalize (a && convert<bool> (move (*a)));
+ return p;
+ };
+
+ f["normalize"] = [](paths v, optional<value> a)
+ {
+ bool act (a && convert<bool> (move (*a)));
- f["normalize"] = [](paths v) {for (auto& p: v) p.normalize (); return v;};
- f["normalize"] = [](dir_paths v) {for (auto& p: v) p.normalize (); return v;};
+ for (auto& p: v)
+ p.normalize (act);
- f[".normalize"] = [](names ns)
+ return v;
+ };
+ f["normalize"] = [](dir_paths v, optional<value> a)
{
+ bool act (a && convert<bool> (move (*a)));
+
+ for (auto& p: v)
+ p.normalize (act);
+ return v;
+ };
+
+ f[".normalize"] = [](names ns, optional<value> a)
+ {
+ bool act (a && convert<bool> (move (*a)));
+
// For each path decide based on the presence of a trailing slash
// whether it is a directory. Return as untyped list of (potentially
// mixed) paths.
@@ -134,9 +171,9 @@ namespace build2
for (name& n: ns)
{
if (n.directory ())
- n.dir.normalize ();
+ n.dir.normalize (act);
else
- n.value = convert<path> (move (n)).normalize ().string ();
+ n.value = convert<path> (move (n)).normalize (act).string ();
}
return ns;
};
diff --git a/tests/function/path/testscript b/tests/function/path/testscript
index 066a6c8..8467bce 100644
--- a/tests/function/path/testscript
+++ b/tests/function/path/testscript
@@ -4,11 +4,7 @@
.include ../../common.test
-if ($cxx.target.class != windows) # @@ TMP ternarry
- s = '/'
-else
- s = '\'
-end
+s = ($cxx.target.class != windows ? '/' : '\')
: canonicalize
:
@@ -30,15 +26,19 @@ end
$* <'print $normalize([dir_paths] a/../b a/../c/)' >"b$s c$s" : dir-paths
$* <'print $path.normalize(a/../b)' >"b" : untyped
$* <'print $path.normalize(a/../b/ a/../c)' >"b$s c" : mixed
+
+ : actualize
+ :
+ if ($cxx.target.class == windows)
+ {
+ mkdir Foo;
+ $* <"print \$path.normalize\('$~/foo', true)" >"$~\\Foo"
+ }
}
: invalid-path
:
-if ($cxx.target.class != windows) # @@ TMP ternarry
- p = /../foo
-else
- p = c:/../foo
-end;
+p = ($cxx.target.class != windows ? /../foo : 'c:/../foo');
$* <"\$path.normalize\('$p')" 2>>"EOE" != 0
error: invalid path: '$p'
EOE