aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-05-17 08:07:00 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-05-17 08:07:00 +0200
commit270b1483bd668a2001652093479a6617d8f20bc2 (patch)
tree8d06583ae13eadfd60187244495aa3e4881b8293
parent2140a1c2817eacf013fe3ce559fb23cedb02febb (diff)
Tighten quoted include handling in dependency extraction
-rw-r--r--build2/cc/compile.cxx26
1 files changed, 21 insertions, 5 deletions
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.