]> git.tdb.fi Git - builder.git/commitdiff
Do dependency discovery in a single pass
authorMikko Rasa <tdb@tdb.fi>
Wed, 9 May 2012 15:43:47 +0000 (18:43 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 8 Jul 2012 21:08:51 +0000 (00:08 +0300)
source/binary.cpp
source/builder.cpp
source/csourcefile.cpp
source/objectfile.cpp
source/objectfile.h
source/target.cpp
source/target.h

index 17ec7353998f7fc7078c70d56bbb99762dfb7fa2..81124b9465fef1102c5bddd4e66494139e4f47f6 100644 (file)
@@ -27,10 +27,7 @@ Binary::Binary(Builder &b, const Component &c, const std::string &p, const list<
 void Binary::find_depends()
 {
        if(!component)
-       {
-               deps_ready = true;
                return;
-       }
 
        const SourcePackage &spkg = component->get_package();
        LibMode libmode = spkg.get_library_mode();
@@ -74,6 +71,4 @@ void Binary::find_depends()
                if(last)
                        add_depend(*i);
        }
-
-       deps_ready = true;
 }
index 0c39f6d48befd871ff7883ac7d53d72755723c47..504fc7d8ea565139fdda95eb731f61ea103fd60e 100644 (file)
@@ -509,17 +509,8 @@ int Builder::create_targets()
                }
        }
 
-       // Find dependencies until no new targets are created
-       while(!new_tgts.empty())
-       {
-               Target *tgt = new_tgts.front();
-               new_tgts.erase(new_tgts.begin());
-               tgt->find_depends();
-               if(!tgt->get_depends_ready())
-                       new_tgts.push_back(tgt);
-       }
-
        // Apply what-ifs
+       // XXX This does not currently work with targets found during dependency discovery
        for(StringList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
        {
                FileTarget *tgt = vfs.get_target(cwd/ *i);
index 2162cf0873ee1f7b9fd9a43a82649c2b47a4ba05..c231784753796466a9e9e33d60201c17531bac92 100644 (file)
@@ -25,10 +25,7 @@ CSourceFile::CSourceFile(Builder &b, const Component &c, const FS::Path &p):
 void CSourceFile::find_depends()
 {
        if(!comp)
-       {
-               deps_ready = true;
                return;
-       }
 
        const SourcePackage &spkg = comp->get_package();
        string relname = FS::relative(path, spkg.get_source()).str();
@@ -67,7 +64,6 @@ void CSourceFile::find_depends()
                {
                        if(builder.get_verbose()>=4)
                                IO::print("Failed to read includes from %s\n", path.str());
-                       deps_ready = true;
                        return;
                }
        }
@@ -81,6 +77,4 @@ void CSourceFile::find_depends()
                if(hdr)
                        add_depend(hdr);
        }
-
-       deps_ready = true;
 }
index f24d028d62e56ce25078f8d35e85eb75c9335ca9..39372a415c0e67350d0a4862282a74e489dd213e 100644 (file)
@@ -19,19 +19,11 @@ ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s):
 
 void ObjectFile::find_depends()
 {
-       for(Dependencies::iterator i=new_deps.begin(); i!=new_deps.end();)
+       for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
        {
-               Target *tgt = *i;
-               if(tgt->get_depends_ready())
-               {
-                       i = new_deps.erase(i);
-                       find_depends(dynamic_cast<FileTarget *>(tgt));
-               }
-               else
-                       ++i;
+               (*i)->prepare();
+               find_depends(dynamic_cast<FileTarget *>(*i));
        }
-
-       deps_ready = new_deps.empty();
 }
 
 
@@ -70,12 +62,6 @@ void ObjectFile::find_depends(FileTarget *tgt)
                        add_depend(*i);
 }
 
-void ObjectFile::add_depend(Target *tgt)
-{
-       Target::add_depend(tgt);
-       new_deps.push_back(tgt);
-}
-
 FS::Path ObjectFile::generate_target_path(const Component &comp, const string &src)
 {
        const SourcePackage &pkg = comp.get_package();
index f21fd31160c65b264bf17a7b74ca99341a1bac2b..af47c66863088ae2448f718e932338d42957ca99 100644 (file)
@@ -14,7 +14,6 @@ class ObjectFile: public FileTarget
 private:
        const Component &comp;
        SourceFile &source;
-       Dependencies new_deps;
        
 public:
        ObjectFile(Builder &, const Component &, SourceFile &);
@@ -31,10 +30,6 @@ private:
        /** Recursively looks for header targets and adds them as dependencies. */
        void find_depends(FileTarget *);
 
-       /** Adds a target to the dependency list as well as the new dependencies
-       list. */
-       void add_depend(Target *);
-
        static Msp::FS::Path generate_target_path(const Component &, const std::string &);
 };
 
index c43ad99ea8361cb71934f3fb57a5f4dce27e23ff..44a758f888d152e543b9c489904760d3dd070dd3 100644 (file)
@@ -16,8 +16,7 @@ Target::Target(Builder &b, const string &n):
        component(0),
        name(n),
        tool(0),
-       state(INIT),
-       deps_ready(false)
+       state(INIT)
 {
        builder.add_target(this);
 }
@@ -66,6 +65,8 @@ void Target::prepare()
        }
 
        state = PREPARING;
+       find_depends();
+
        for(Dependencies::iterator i=depends.begin(); i!=depends.end(); ++i)
                (*i)->prepare();
 
index d0e68f50588da69decb51b556dd633be63529c05..d6ed43860315b1508356d66024d8852258f70af7 100644 (file)
@@ -45,7 +45,6 @@ protected:
        std::string install_location;
 
        Dependencies depends;
-       bool deps_ready;
 
        Target(Builder &, const std::string &);
 public:
@@ -81,13 +80,9 @@ public:
        const std::string &get_install_location() const { return install_location; }
        void add_depend(Target *);
        const Dependencies &get_depends() const { return depends; }
-       bool get_depends_ready() const { return deps_ready; }
 
-       /**
-       Finds dependencies for the target.  When all dependencies have been found,
-       the function should set deps_ready to true.
-       */
-       virtual void find_depends() { deps_ready = true; }
+       /** Finds dependencies for the target. */
+       virtual void find_depends() { }
 
        /**
        Prepares the target by recursively preparing dependencies, then checking