diff options
author | Boris Kolpackov <boris@codesynthesis.com> | 2015-03-04 16:33:51 +0200 |
---|---|---|
committer | Boris Kolpackov <boris@codesynthesis.com> | 2015-03-04 16:33:51 +0200 |
commit | 7eed858cac7e8ff78626bdc5d63a7f36ca8f8010 (patch) | |
tree | 225dd25e354c4f6234dbf2c02608ec6545dcd688 /build/context.cxx | |
parent | c76fe316122969986103d243706dc7fa7ab6ddc1 (diff) |
Move roots and bases to appropriate scopes
Diffstat (limited to 'build/context.cxx')
-rw-r--r-- | build/context.cxx | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/build/context.cxx b/build/context.cxx index f7c9650..6c37e38 100644 --- a/build/context.cxx +++ b/build/context.cxx @@ -7,6 +7,8 @@ #include <ostream> #include <cassert> +#include <build/scope> + using namespace std; namespace build @@ -14,21 +16,31 @@ namespace build path work; path home; - path src_root; - path out_root; + path + src_out (const path& out, scope& s) + { + return src_out (out, + s["out_root"].as<const path&> (), + s["src_root"].as<const path&> ()); + } - path src_base; - path out_base; + path + out_src (const path& src, scope& s) + { + return out_src (src, + s["out_root"].as<const path&> (), + s["src_root"].as<const path&> ()); + } path - src_out (const path& o) + src_out (const path& o, const path& out_root, const path& src_root) { assert (o.sub (out_root)); return src_root / o.leaf (out_root); } path - out_src (const path& s) + out_src (const path& s, const path& out_root, const path& src_root) { assert (s.sub (src_root)); return out_root / s.leaf (src_root); @@ -41,11 +53,25 @@ namespace build 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. + // 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))) // @@ cache + (work.sub (out_root) && p.sub (out_root))) return p.relative (work); + */ + + if (p.root_directory () == work.root_directory ()) + { + path r (p.relative (work)); + + if (r.string ().size () < p.string ().size ()) + return r; + } return p; } |