aboutsummaryrefslogtreecommitdiff
path: root/build2/utility.cxx
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-10-13 18:20:35 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-11-04 08:12:47 +0200
commitae579402c8c64ea8ceea2e9fcee5097b3c53e353 (patch)
tree5933a00f434adab5583e81c147754d5d4dc69f12 /build2/utility.cxx
parent8d2e541ab1aa24140eb680fb046e49a4a3f0bbd2 (diff)
Minor dependency cleanup
Diffstat (limited to 'build2/utility.cxx')
-rw-r--r--build2/utility.cxx55
1 files changed, 54 insertions, 1 deletions
diff --git a/build2/utility.cxx b/build2/utility.cxx
index 1383729..43a5370 100644
--- a/build2/utility.cxx
+++ b/build2/utility.cxx
@@ -8,7 +8,6 @@
#include <cstdlib> // strtol()
#include <iostream> // cerr
-#include <build2/context>
#include <build2/variable>
#include <build2/diagnostics>
@@ -85,6 +84,60 @@ namespace build2
return l;
}
+ dir_path work;
+ dir_path home;
+ const dir_path* relative_base = &work;
+
+ string
+ diag_relative (const path& p, bool cur)
+ {
+ if (p.string () == "-")
+ return "<stdin>";
+
+ const path& b (*relative_base);
+
+ if (p.absolute ())
+ {
+ if (p == b)
+ return cur ? "." + p.separator_string () : string ();
+
+#ifndef _WIN32
+ if (!home.empty ())
+ {
+ if (p == home)
+ return "~" + p.separator_string ();
+ }
+#endif
+
+ path rb (relative (p));
+
+#ifndef _WIN32
+ if (!home.empty ())
+ {
+ if (rb.relative ())
+ {
+ // See if the original path with the ~/ shortcut is better that the
+ // relative to base.
+ //
+ if (p.sub (home))
+ {
+ path rh (p.leaf (home));
+ if (rb.size () > rh.size () + 2) // 2 for '~/'
+ return "~/" + move (rh).representation ();
+ }
+ }
+ else if (rb.sub (home))
+ return "~/" + rb.leaf (home).representation ();
+ }
+
+#endif
+
+ return move (rb).representation ();
+ }
+
+ return p.representation ();
+ }
+
process_path
run_search (const char*& args0)
try