aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libbuild2/functions-path.cxx75
-rw-r--r--tests/function/path/testscript21
2 files changed, 61 insertions, 35 deletions
diff --git a/libbuild2/functions-path.cxx b/libbuild2/functions-path.cxx
index fdf712c..b0acc63 100644
--- a/libbuild2/functions-path.cxx
+++ b/libbuild2/functions-path.cxx
@@ -221,43 +221,66 @@ namespace build2
// normalize
//
- // @@ TODO: normalize(true) is not pure, redo as a separate actualize()
- // function.
- //
- f["normalize"] += [](path p, optional<value> a)
- {
- p.normalize (a && convert<bool> (move (*a)));
- return p;
- };
+ f["normalize"] += [](path p) {p.normalize (); return p;};
+ f["normalize"] += [](dir_path p) {p.normalize (); return p;};
- f["normalize"] += [](dir_path p, optional<value> a)
+ f["normalize"] += [](paths v)
{
- p.normalize (a && convert<bool> (move (*a)));
- return p;
+ for (auto& p: v)
+ p.normalize ();
+ return v;
};
- f["normalize"] += [](paths v, optional<value> a)
+ f["normalize"] += [](dir_paths v)
{
- bool act (a && convert<bool> (move (*a)));
-
for (auto& p: v)
- p.normalize (act);
-
+ p.normalize ();
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)
+ {
+ // 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.
+ //
+ for (name& n: ns)
+ {
+ if (n.directory ())
+ n.dir.normalize ();
+ else
+ n.value = convert<path> (move (n)).normalize ().string ();
+ }
+ return ns;
};
- f[".normalize"] += [](names ns, optional<value> a)
+ // actualize
+ //
+ // Note that this function is not pure.
+ //
{
- bool act (a && convert<bool> (move (*a)));
+ auto e (f.insert ("actualize", false));
+
+ e += [](path p) {p.normalize (true); return p;};
+ e += [](dir_path p) {p.normalize (true); return p;};
+ e += [](paths v)
+ {
+ for (auto& p: v)
+ p.normalize (true);
+ return v;
+ };
+
+ e += [](dir_paths v)
+ {
+ for (auto& p: v)
+ p.normalize (true);
+ return v;
+ };
+ }
+
+ f.insert (".actualize", false) += [](names ns)
+ {
// 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.
@@ -265,9 +288,9 @@ namespace build2
for (name& n: ns)
{
if (n.directory ())
- n.dir.normalize (act);
+ n.dir.normalize (true);
else
- n.value = convert<path> (move (n)).normalize (act).string ();
+ n.value = convert<path> (move (n)).normalize (true).string ();
}
return ns;
};
diff --git a/tests/function/path/testscript b/tests/function/path/testscript
index 52b4138..ad76513 100644
--- a/tests/function/path/testscript
+++ b/tests/function/path/testscript
@@ -3,7 +3,9 @@
.include ../../common.testscript
-s = ($cxx.target.class != 'windows' ? '/' : '\')
+posix = ($cxx.target.class != 'windows')
+
+s = ($posix ? '/' : '\')
: canonicalize
:
@@ -25,16 +27,17 @@ s = ($cxx.target.class != 'windows' ? '/' : '\')
$* <'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($out_base/foo, true)' >~'/.+\\Foo/'
- }
+: actualize
+:
+if! $posix
+{
+ mkdir Foo;
+ $* <'print $path.actualize($out_base/foo)' >~'/.+\\Foo/'
}
+
: directory
:
{
@@ -103,7 +106,7 @@ s = ($cxx.target.class != 'windows' ? '/' : '\')
: invalid-path
:
-p = ($cxx.target.class != 'windows' ? /../foo : 'c:/../foo');
+p = ($posix ? /../foo : 'c:/../foo');
$* <"\$path.normalize\('$p')" 2>>"EOE" != 0
error: invalid path: '$p'
<stdin>:1:2: info: while calling path.normalize\(<untyped>\)