From ab4421747146aa7995f0cfb1a639c9121c82c915 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 8 Jan 2015 13:27:15 +0200 Subject: Implement tracing support Also use to-relative path translation in diagnostics. --- build/path.txx | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'build/path.txx') diff --git a/build/path.txx b/build/path.txx index 6a01547..3e952d8 100644 --- a/build/path.txx +++ b/build/path.txx @@ -117,8 +117,12 @@ namespace build if (m < n || path_.compare (0, n, d.path_) != 0) throw invalid_basic_path (path_); - if (n != m) - n++; // Skip the directory separator. + if (n != m +#ifndef _WIN32 + && !d.root () +#endif + ) + n++; // Skip the directory separator (unless it is POSIX root). return basic_path (path_.c_str () + n, m - n); } @@ -144,6 +148,28 @@ namespace build } template + basic_path basic_path:: + relative (basic_path d) const + { + basic_path r; + + for (;; d = d.directory ()) + { + if (sub (d)) + break; + + r /= path (".."); + + // Roots of the paths do not match. + // + if (d.root ()) + throw invalid_basic_path (path_); + } + + return r / leaf (d); + } + + template basic_path& basic_path:: normalize () { -- cgit v1.1