From c01dc113eca278100ad0b4572082da619d52662e Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 9 May 2012 18:43:47 +0300 Subject: [PATCH] Do dependency discovery in a single pass --- source/binary.cpp | 5 ----- source/builder.cpp | 11 +---------- source/csourcefile.cpp | 6 ------ source/objectfile.cpp | 20 +++----------------- source/objectfile.h | 5 ----- source/target.cpp | 5 +++-- source/target.h | 9 ++------- 7 files changed, 9 insertions(+), 52 deletions(-) diff --git a/source/binary.cpp b/source/binary.cpp index 17ec735..81124b9 100644 --- a/source/binary.cpp +++ b/source/binary.cpp @@ -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; } diff --git a/source/builder.cpp b/source/builder.cpp index 0c39f6d..504fc7d 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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); diff --git a/source/csourcefile.cpp b/source/csourcefile.cpp index 2162cf0..c231784 100644 --- a/source/csourcefile.cpp +++ b/source/csourcefile.cpp @@ -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; } diff --git a/source/objectfile.cpp b/source/objectfile.cpp index f24d028..39372a4 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -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(tgt)); - } - else - ++i; + (*i)->prepare(); + find_depends(dynamic_cast(*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(); diff --git a/source/objectfile.h b/source/objectfile.h index f21fd31..af47c66 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -14,7 +14,6 @@ class ObjectFile: public FileTarget private: const Component ∁ 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 &); }; diff --git a/source/target.cpp b/source/target.cpp index c43ad99..44a758f 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -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(); diff --git a/source/target.h b/source/target.h index d0e68f5..d6ed438 100644 --- a/source/target.h +++ b/source/target.h @@ -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 -- 2.45.2