From 270b1483bd668a2001652093479a6617d8f20bc2 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 17 May 2017 08:07:00 +0200 Subject: Tighten quoted include handling in dependency extraction --- build2/cc/compile.cxx | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'build2') diff --git a/build2/cc/compile.cxx b/build2/cc/compile.cxx index cae96da..cd5cc56 100644 --- a/build2/cc/compile.cxx +++ b/build2/cc/compile.cxx @@ -1283,15 +1283,31 @@ namespace build2 const path_target* pt (nullptr); // If it's not absolute then it either does not (yet) exist or is - // a relative ""-include (see init_args() for details). Check the - // second case first. + // a relative ""-include (see init_args() for details). Reduce the + // second case to absolute. // if (f.relative () && rels.relative ()) { - path t (work / f); // The rels path is relative to work. + // If the relative source path has a directory component, make sure + // it matches since ""-include will always start with that (none of + // the compilers we support try to normalize this path). Failed that + // we may end up searching for a generated header in a random + // (working) directory. + // + const string& fs (f.string ()); + const string& ss (rels.string ()); + + size_t p (path::traits::rfind_separator (ss)); - if (exists (t)) - f = move (t); + if (p == string::npos || // No directory. + (fs.size () > p + 1 && + path::traits::compare (fs.c_str (), p, ss.c_str (), p) == 0)) + { + path t (work / f); // The rels path is relative to work. + + if (exists (t)) + f = move (t); + } } // If still relative then it does not exist. -- cgit v1.1