blob: c97518c913772f62bd27cbd00059c7230c52e809 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
// 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)
{
fail << "invalid path: '" << e.path << "'" << endf;
}
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;
};
}
}
|