if(tgt->get_depends_ready())
{
i = new_deps.erase(i);
- find_depends(tgt);
+ find_depends(dynamic_cast<FileTarget *>(tgt));
}
else
++i;
}
-void ObjectFile::find_depends(Target *tgt)
+void ObjectFile::find_depends(FileTarget *tgt)
{
- SourceFile *src = dynamic_cast<SourceFile *>(tgt->get_real_target());
- FileTarget *file = dynamic_cast<FileTarget *>(tgt);
- if(!src || !file)
- return;
-
- FS::Path spath = FS::dirname(file->get_path());
- const StringList &incpath = comp.get_build_info().incpath;
-
- const list<string> &includes = src->get_includes();
- for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
+ Target *rtgt = tgt->get_real_target();
+ const Dependencies &tdeps = rtgt->get_depends();
+ Dependencies deps_to_add;
+ if(rtgt==tgt)
{
- Target *hdr = builder.get_vfs().find_header(*i, spath, incpath);
- if(hdr && find(depends.begin(), depends.end(), hdr)==depends.end())
- add_depend(hdr);
+ /* We are using the target from its original location, so dependencies
+ apply directly */
+ deps_to_add = tdeps;
}
+ else
+ {
+ /* The target has been displaced by installing it. Displace any
+ dependencies that come from the same package as well. */
+ const SourcePackage *tpkg = dynamic_cast<const SourcePackage *>(rtgt->get_package());
+ for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i)
+ {
+ FileTarget *file = dynamic_cast<FileTarget *>(*i);
+ if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source())>=0)
+ {
+ 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);
+ }
+ else
+ deps_to_add.push_back(*i);
+ }
+ }
+
+ for(Dependencies::const_iterator i=deps_to_add.begin(); i!=deps_to_add.end(); ++i)
+ if(find(depends.begin(), depends.end(), *i)==depends.end())
+ add_depend(*i);
}
void ObjectFile::add_depend(Target *tgt)