aboutsummaryrefslogtreecommitdiff
path: root/libbuild2
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2022-10-21 08:50:07 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2022-10-21 08:50:07 +0200
commit51068e16c6486a60fa54591972fcca3821341c05 (patch)
treebaa86fa72f1658ea62341184fb18232311b50c09 /libbuild2
parent02d5d7693c79de278cbc1fe4bb4b1bf957a7895a (diff)
Pass correct base scope to search() in dyndep::enter_file()
Diffstat (limited to 'libbuild2')
-rw-r--r--libbuild2/dyndep.cxx37
1 files changed, 31 insertions, 6 deletions
diff --git a/libbuild2/dyndep.cxx b/libbuild2/dyndep.cxx
index 9816ad6..ace901b 100644
--- a/libbuild2/dyndep.cxx
+++ b/libbuild2/dyndep.cxx
@@ -474,7 +474,7 @@ namespace build2
dir_path out;
// It's possible the extension-to-target type mapping is ambiguous (for
- // example, because both C and X-language headers use the same .h
+ // example, because both C and C++-language headers use the same .h
// extension). In this case we will first try to find one that matches
// an explicit target (similar logic to when insert is false).
//
@@ -487,15 +487,40 @@ namespace build2
// pick the first one (it's highly unlikely the source file extension
// mapping will differ based on the configuration).
//
+ // Note that we also need to remember the base scope for search() below
+ // (failed that, search_existing_file() will refuse to look).
+ //
+ const scope* s (nullptr);
{
- const scope& bs (**t.ctx.scopes.find (d).first);
- if (const scope* rs = bs.root_scope ())
+ // While we cannot accurately associate in the general case, we can do
+ // so if the path belongs to this project.
+ //
+ const scope& rs (*bs.root_scope ());
+ bool src (false);
+ if (d.sub (rs.out_path ()) ||
+ (src = (!rs.out_eq_src () && d.sub (rs.src_path ()))))
{
if (map_extension != nullptr)
tts = map_extension (bs, n, e);
- if (!bs.out_eq_src () && d.sub (bs.src_path ()))
- out = out_src (d, *rs);
+ if (src)
+ out = out_src (d, rs);
+
+ s = &bs;
+ }
+ else
+ {
+ const scope& bs (**t.ctx.scopes.find (d).first);
+ if (const scope* rs = bs.root_scope ())
+ {
+ if (map_extension != nullptr)
+ tts = map_extension (bs, n, e);
+
+ if (!rs->out_eq_src () && d.sub (rs->src_path ()))
+ out = out_src (d, *rs);
+
+ s = &bs;
+ }
}
}
@@ -603,7 +628,7 @@ namespace build2
// @@ OPT: move d, out, n
//
if (r == nullptr && insert)
- r = &search (t, *tts[0], d, out, n, &e, &bs);
+ r = &search (t, *tts[0], d, out, n, &e, s);
return static_cast<const file*> (r);
};