blob: 6ff61c95aabac72342a0ad58898f20ba9e3b1654 (
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
|
// file : build2/context.txx -*- C++ -*-
// copyright : Copyright (c) 2014-2016 Code Synthesis Ltd
// license : MIT; see accompanying LICENSE file
namespace build2
{
template <typename K>
basic_path<char, K>
relative (const basic_path<char, K>& p)
{
typedef basic_path<char, K> path;
const dir_path& b (*relative_base);
if (b.empty ())
return p;
if (p.sub (b))
return p.leaf (b);
// If base is a sub-path of {src,out}_root and this path is also a
// sub-path of it, then use '..' to form a relative path.
//
// Don't think this is a good heuristic. For example, why shouldn't
// we display paths from imported projects as relative if they are
// more readable than absolute?
//
/*
if ((work.sub (src_root) && p.sub (src_root)) ||
(work.sub (out_root) && p.sub (out_root)))
return p.relative (work);
*/
if (p.root_directory () == b.root_directory ())
{
path r (p.relative (b));
if (r.string ().size () < p.string ().size ())
return r;
}
return p;
}
}
|