aboutsummaryrefslogtreecommitdiff
path: root/build/context.txx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-04-13 15:50:17 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-04-13 15:50:17 +0200
commitace1743f7f78bb13f99553d6e97ad1beecf1ba99 (patch)
tree595bc9dad989e44f4be9a67e351219f3248dc5f0 /build/context.txx
parent534f9d8db025d58c9ce23f3b81a37e8c34386a27 (diff)
Add separate type to represent directory paths
Diffstat (limited to 'build/context.txx')
-rw-r--r--build/context.txx40
1 files changed, 39 insertions, 1 deletions
diff --git a/build/context.txx b/build/context.txx
index 53081b1..218c65e 100644
--- a/build/context.txx
+++ b/build/context.txx
@@ -46,7 +46,7 @@ namespace build
template <typename T>
fs_status<rmdir_status>
- rmdir (const path& d, const T& t)
+ rmdir (const dir_path& d, const T& t)
{
bool w (d == work); // Don't try to remove working directory.
rmdir_status rs;
@@ -97,4 +97,42 @@ namespace build
return rs;
}
+
+ 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;
+ }
}