aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-12-05 15:57:49 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-12-05 15:57:49 +0200
commit8c7987abed3acd873613327cb40facbfec2997f4 (patch)
treef9a32ffb176f76defaa913093f0b20c4ec1956e3
parent54870fb76b5f59cc2e6d69a8c7a8ef17853a0029 (diff)
Add optional actualize argument to $path.normalize()
-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