From ae579402c8c64ea8ceea2e9fcee5097b3c53e353 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 13 Oct 2016 18:20:35 +0200 Subject: Minor dependency cleanup --- build2/utility.cxx | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) (limited to 'build2/utility.cxx') 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 // strtol() #include // cerr -#include #include #include @@ -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 ""; + + 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 -- cgit v1.1