From a56c7a5d4e707e51fea407d44bd751426bfdc8f5 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Sat, 5 Dec 2020 14:16:26 +0300 Subject: Redo $normalize(true) as separate $actualize() --- libbuild2/functions-path.cxx | 75 +++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 26 deletions(-) (limited to 'libbuild2') 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 a) - { - p.normalize (a && convert (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 a) + f["normalize"] += [](paths v) { - p.normalize (a && convert (move (*a))); - return p; + for (auto& p: v) + p.normalize (); + return v; }; - f["normalize"] += [](paths v, optional a) + f["normalize"] += [](dir_paths v) { - bool act (a && convert (move (*a))); - for (auto& p: v) - p.normalize (act); - + p.normalize (); return v; }; - f["normalize"] += [](dir_paths v, optional a) - { - bool act (a && convert (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 (move (n)).normalize ().string (); + } + return ns; }; - f[".normalize"] += [](names ns, optional a) + // actualize + // + // Note that this function is not pure. + // { - bool act (a && convert (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 (move (n)).normalize (act).string (); + n.value = convert (move (n)).normalize (true).string (); } return ns; }; -- cgit v1.1