aboutsummaryrefslogtreecommitdiff
path: root/build/context.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2015-01-08 13:27:15 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2015-01-08 13:27:15 +0200
commitab4421747146aa7995f0cfb1a639c9121c82c915 (patch)
treedeb08893c02ed0238f73becbbe80ede5568b946e /build/context.cxx
parentd3e624ef7c0fb274e62b81c4c7bd59640770520a (diff)
Implement tracing support
Also use to-relative path translation in diagnostics.
Diffstat (limited to 'build/context.cxx')
-rw-r--r--build/context.cxx36
1 files changed, 36 insertions, 0 deletions
diff --git a/build/context.cxx b/build/context.cxx
index ce80324..fc4ec1c 100644
--- a/build/context.cxx
+++ b/build/context.cxx
@@ -2,6 +2,8 @@
// copyright : Copyright (c) 2014-2015 Code Synthesis Tools CC
// license : MIT; see accompanying LICENSE file
+#include <ostream>
+
#include <build/context>
using namespace std;
@@ -16,4 +18,38 @@ namespace build
path src_base;
path out_base;
+
+ path
+ translate (const path& p)
+ {
+ if (p.sub (work))
+ return p.leaf (work);
+
+ // If work is a sub-path of {src,out}_root and this path is also a
+ // sub-bath of it, then use '..' to form a relative path.
+ //
+ if (work.sub (src_root) && p.sub (src_root) ||
+ work.sub (out_root) && p.sub (out_root)) // @@ cache
+ return p.relative (work);
+
+ return p;
+ }
+
+ std::string
+ diagnostic_string (const path& p)
+ {
+ if (p.absolute ())
+ {
+ path rp (translate (p));
+
+#ifndef _WIN32
+ if (rp.absolute () && rp.sub (home))
+ return "~/" + rp.leaf (home).string ();
+#endif
+
+ return rp.string ();
+ }
+
+ return p.string ();
+ }
}