aboutsummaryrefslogtreecommitdiff
path: root/build2/functions-path.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-11-18 17:28:46 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-18 17:30:47 +0200
commit6b7075adc71104c5f6ad652b99fb753565eb67d8 (patch)
tree1f4d91b7cd9ee7cca793f0ecc504ccc4d8dde0d2 /build2/functions-path.cxx
parentdd008d6e48b0bb66e1b9fdc489d9d1d9b4cb8d25 (diff)
Add function machinery, implement path.normalize()
Note that multi-argument functions are not yet "callable" since there is no support for value packs.
Diffstat (limited to 'build2/functions-path.cxx')
-rw-r--r--build2/functions-path.cxx53
1 files changed, 53 insertions, 0 deletions
diff --git a/build2/functions-path.cxx b/build2/functions-path.cxx
new file mode 100644
index 0000000..b76b277
--- /dev/null
+++ b/build2/functions-path.cxx
@@ -0,0 +1,53 @@
+// file : build2/functions-path.cxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
+// license : MIT; see accompanying LICENSE file
+
+#include <build2/function>
+#include <build2/variable>
+
+using namespace std;
+
+namespace build2
+{
+ static value
+ path_thunk (vector_view<value> args, const function_overload& f)
+ try
+ {
+ return function_family::default_thunk (move (args), f);
+ }
+ catch (const invalid_path& e)
+ {
+ error << "invalid path: '" << e.path << "'";
+ throw failed ();
+ }
+
+ void
+ path_functions ()
+ {
+ function_family f ("path", &path_thunk);
+
+ // normalize
+ //
+ f["normalize"] = [](path p) {p.normalize (); return p;};
+ f["normalize"] = [](paths v) {for (auto& p: v) p.normalize (); return v;};
+
+ f["normalize"] = [](dir_path p) {p.normalize (); return p;};
+ f["normalize"] = [](dir_paths v) {for (auto& p: v) p.normalize (); 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;
+ };
+ }
+}