From ce3fc52c7e79c0bf182dad12ed6ba3a0203c59ce Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 13 Apr 2012 19:47:23 +0300 Subject: [PATCH] Rewrite ObjectFile dependency finding so it doesn't depend on includes --- source/objectfile.cpp | 46 +++++++++++++++++++++++++++++-------------- source/objectfile.h | 2 +- 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 52c8a81..8068bc6 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -27,7 +27,7 @@ void ObjectFile::find_depends() if(tgt->get_depends_ready()) { i = new_deps.erase(i); - find_depends(tgt); + find_depends(dynamic_cast(tgt)); } else ++i; @@ -37,23 +37,39 @@ void ObjectFile::find_depends() } -void ObjectFile::find_depends(Target *tgt) +void ObjectFile::find_depends(FileTarget *tgt) { - SourceFile *src = dynamic_cast(tgt->get_real_target()); - FileTarget *file = dynamic_cast(tgt); - if(!src || !file) - return; - - FS::Path spath = FS::dirname(file->get_path()); - const StringList &incpath = comp.get_build_info().incpath; - - const list &includes = src->get_includes(); - for(list::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(rtgt->get_package()); + for(Dependencies::const_iterator i=tdeps.begin(); i!=tdeps.end(); ++i) + { + FileTarget *file = dynamic_cast(*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) diff --git a/source/objectfile.h b/source/objectfile.h index 1065981..f21fd31 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -29,7 +29,7 @@ public: private: /** Recursively looks for header targets and adds them as dependencies. */ - void find_depends(Target *); + void find_depends(FileTarget *); /** Adds a target to the dependency list as well as the new dependencies list. */ -- 2.45.2