]> git.tdb.fi Git - builder.git/commitdiff
Rewrite ObjectFile dependency finding so it doesn't depend on includes
authorMikko Rasa <tdb@tdb.fi>
Fri, 13 Apr 2012 16:47:23 +0000 (19:47 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:49 +0000 (00:08 +0300)
source/objectfile.cpp
source/objectfile.h

index 52c8a81e8de302efe936802fc87d084e8eba4260..8068bc6ed02f62277984215dd74c5b07d52b5d62 100644 (file)
@@ -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<FileTarget *>(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<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)
index 10659814cd66d59f5abfa0902deaf2b35c5e85dc..f21fd31160c65b264bf17a7b74ca99341a1bac2b 100644 (file)
@@ -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. */