- FS::Path displaced = tgt->get_path()/FS::relative(file->get_path(), rtgt->get_path());
- if(Target *ddep = builder.get_vfs().get_target(displaced))
- deps_to_add.push_back(ddep);
+ const Component *tcomp = file->get_component();
+ FS::Path dep_inst = tcomp->get_install_map().get_install_location(*file);
+ FS::Path displaced = FS::dirname(tgt.get_path())/FS::relative(dep_inst, inst_dir)/FS::basename(file->get_path());
+ d = builder.get_vfs().get_target(displaced);
+ if(!d)
+ {
+ /* If the target was in an overlay directory and the displaced
+ dependency is not found, try removing the overlay from the path. */
+ string last_dir = FS::basename(FS::dirname(displaced));
+ if(any_equals(tcomp->get_overlays(), last_dir))
+ {
+ displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
+ d = builder.get_vfs().get_target(displaced);
+ }
+ }