From 9c02d307d69faa6e3c7056d8e07f16c75c189f92 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 25 Mar 2015 15:14:06 +0200 Subject: Recognize common cases (., .., and dir{}) when deriving out_base --- build/b.cxx | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'build') diff --git a/build/b.cxx b/build/b.cxx index 3a37b68..0443b4b 100644 --- a/build/b.cxx +++ b/build/b.cxx @@ -318,14 +318,25 @@ main (int argc, char* argv[]) path out_base (tn.dir); if (out_base.empty ()) { - // See if there is a directory part in value. We cannot - // assume it is a valid filesystem name so we will have - // to do the splitting manually. + const string& v (tn.value); + + // Handle a few common cases as special: empty name, '.', + // '..', as well as dir{foo/bar} (without trailing '/'). + // This code must be consistent with target_type_map::find(). // - path::size_type i (path::traits::rfind_separator (tn.value)); + if (v.empty () || v == "." || v == ".." || tn.type == "dir") + out_base = path (v); + else + { + // See if there is a directory part in value. We cannot + // assume it is a valid filesystem name so we will have + // to do the splitting manually. + // + path::size_type i (path::traits::rfind_separator (v)); - if (i != string::npos) - out_base = path (tn.value, i != 0 ? i : 1); // Special case: "/". + if (i != string::npos) + out_base = path (v, i != 0 ? i : 1); // Special case: "/". + } } if (out_base.relative ()) -- cgit v1.1