]> git.tdb.fi Git - builder.git/commitdiff
Process ObjectFile dependencies correctly even when it's processed before some header...
authorMikko Rasa <tdb@tdb.fi>
Sat, 2 Sep 2006 14:29:09 +0000 (14:29 +0000)
committerMikko Rasa <tdb@tdb.fi>
Sat, 2 Sep 2006 14:29:09 +0000 (14:29 +0000)
Show all dependencies with -a alldeps

12 files changed:
source/analyzer.cpp
source/builder.cpp
source/executable.cpp
source/header.h
source/install.h
source/objectfile.cpp
source/objectfile.h
source/sourcefile.cpp
source/systemlibrary.h
source/target.cpp
source/target.h
source/virtualtarget.h

index a4780fd697dd451fae6afa5ddc6efce020f9be9a..7dceac720eb7e4f5d969b3d3c381776adfd0bdca 100644 (file)
@@ -34,14 +34,14 @@ void Analyzer::analyze()
 
 void Analyzer::build_depend_table(Target &tgt, unsigned depth)
 {
-       if(mode!=REBUILD)
+       if(mode!=REBUILD && mode!=ALLDEPS)
        {
                if(dynamic_cast<ObjectFile *>(&tgt))
                        return build_depend_table(*tgt.get_depends().front(), depth);
                else if(dynamic_cast<Install *>(&tgt))
                        return build_depend_table(*tgt.get_depends().front(), depth);
        }
-       else if(!tgt.get_rebuild())
+       else if(mode==REBUILD && !tgt.get_rebuild())
                return;
        
        TableRow row;
index 1de726bcb2b3393f267e363741525da20d6c72e6..e6f036b7028f409ec0851615d068152dd1547966 100644 (file)
@@ -137,6 +137,9 @@ Package *Builder::get_package(const string &n)
        return pkg;
 }
 
+/**
+Returns the target with the given name, or 0 if no such target exists.
+*/
 Target *Builder::get_target(const string &n)
 {
        TargetMap::iterator i=targets.find(n);
@@ -385,6 +388,8 @@ int Builder::create_targets()
                Target *tgt=new_tgts.front();
                new_tgts.erase(new_tgts.begin());
                tgt->find_depends();
+               if(!tgt->get_depends_ready())
+                       new_tgts.push_back(tgt);
        }
 
        Target *cmdline=new VirtualTarget(*this, "cmdline");
index 4e7b1f4382c3b7224661bd72f83e0ec5e2c65e42..630ac71f717e639173cc47ea3b74a7df28b84ffb 100644 (file)
@@ -25,6 +25,8 @@ void Executable::find_depends()
                if(lib)
                        add_depend(lib);
        }
+
+       deps_ready=true;
 }
 
 Action *Executable::build()
index 6541cd4cb707664aa5053c85d901c385d4b5fdf1..56e563408ca622030f10cb842a795aac772b939a 100644 (file)
@@ -15,7 +15,7 @@ class SystemHeader: public Header
 public:
        SystemHeader(Builder &b, const std::string &f): Header(b,0,f) { }
        const char *get_type() const { return "SystemHeader"; }
-       void find_depends() { }
+       void find_depends() { deps_ready=true; }
 };
 
 #endif
index b81ac9ba4f482be92cca29c399d130476a5a1424..2aa3280a75778494e664c0a8562c43e17dd12098 100644 (file)
@@ -8,7 +8,6 @@ class Install: public Target
 public:
        Install(Builder &, const Package &, Target &, const std::string &);
        const char *get_type() const { return "Install"; }
-       void find_depends() { }
        void check_rebuild();
        Action *build();
 private:
index 3e531f7ae8a09d2b8fb3def6265ee5e5659cc552..bba701d23bc48ca87d03f42790a78f4640a5f907 100644 (file)
@@ -1,3 +1,4 @@
+#include <msp/algo.h>
 #include <msp/path/utils.h>
 #include "builder.h"
 #include "compile.h"
@@ -20,7 +21,19 @@ ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &src):
 
 void ObjectFile::find_depends()
 {
-       find_depends(depends.front());
+       for(list<Target *>::iterator i=new_deps.begin(); i!=new_deps.end();)
+       {
+               Target *tgt=*i;
+               if(tgt->get_depends_ready())
+               {
+                       i=new_deps.erase(i);
+                       find_depends(tgt);
+               }
+               else
+                       ++i;
+       }
+
+       deps_ready=new_deps.empty();
 }
 
 Action *ObjectFile::build()
@@ -30,6 +43,9 @@ Action *ObjectFile::build()
 
 void ObjectFile::find_depends(Target *tgt)
 {
+       const string &tname=tgt->get_name();
+       string path=tname.substr(0, tname.rfind('/'));
+
        SourceFile *src=dynamic_cast<SourceFile *>(tgt);
        if(!src)
        {
@@ -40,18 +56,21 @@ void ObjectFile::find_depends(Target *tgt)
        if(!src)
                return;
 
-       const string &sname=src->get_name();
-       string path=sname.substr(0, sname.rfind('/'));
-
        const list<string> &includes=src->get_includes();
        for(list<string>::const_iterator i=includes.begin(); i!=includes.end(); ++i)
        {
                Target *hdr2=builder.get_header(*i, path, package->get_build_info().incpath);
-               if(hdr2)
+               if(hdr2 && !contains(depends, hdr2))
                        add_depend(hdr2);
        }
 }
 
+void ObjectFile::add_depend(Target *tgt)
+{
+       Target::add_depend(tgt);
+       new_deps.push_back(tgt);
+}
+
 string ObjectFile::generate_target_name(const Component &comp, const string &src)
 {
        return (comp.get_package().get_source()/"temp"/comp.get_name()/(Path::splitext(src.substr(src.rfind('/')+1)).base+".o")).str();
index 962151c5e412f1923d873ec23504851f5ddd0d4e..d3315f7f10f1bea8f4111d78ee62cc92311f8b3f 100644 (file)
@@ -15,8 +15,10 @@ public:
        Action *build();
 private:
        const Component &comp;
+       std::list<Target *> new_deps;
        
        void find_depends(Target *);
+       void add_depend(Target *);
 
        static std::string generate_target_name(const Component &, const std::string &);
 };
index ea76efd28a6fd6435e6d9c2a4f74c50a40c83a31..ba37f3f59dc5d11653fe5f5a5dfe4282d6134b17 100644 (file)
@@ -33,4 +33,6 @@ void SourceFile::find_depends()
                if(hdr)
                        add_depend(hdr);
        }
+
+       deps_ready=true;
 }
index 97512702dbbd21cc166694636e21a82519052785..bd554296b8b8cda181fc480dad907342306b2850 100644 (file)
@@ -8,7 +8,6 @@ class SystemLibrary: public Target
 public:
        SystemLibrary(Builder &b, const std::string &n): Target(b,0,n) { }
        const char *get_type() const { return "SystemLibrary"; }
-       void find_depends() { }
        Action *build() { return 0; }
 };
 
index d4c243120bbeb693f54abd6ff9674543f640b84b..04d9260514a8de701e2dd1380313c3215a6b7151 100644 (file)
@@ -66,6 +66,7 @@ Target::Target(Builder &b, const Package *p, const string &n):
        name(n),
        building(false),
        rebuild(false),
+       deps_ready(false),
        prepared(false),
        buildable(false),
        counted(false)
index f0ec0f264916c56da0e32af9b1aa6f003ab175d6..ab9134aff85c2b4e34ab4c9eacd719c4e8ccc06d 100644 (file)
@@ -20,8 +20,9 @@ public:
        virtual const char *get_type() const=0;
        const std::list<Target *> &get_depends() const { return depends; }
        const Package     *get_package() const         { return package; }
+       bool              get_depends_ready() const       { return deps_ready; }
        void              add_depend(Target *);
-       virtual void      find_depends()=0;
+       virtual void      find_depends()               { deps_ready=true; }
        virtual void      prepare();
        virtual Action    *build()=0;
        void              reset_count()                { counted=false; }
@@ -38,6 +39,7 @@ protected:
        Msp::Time::TimeStamp mtime;
        std::list<Target *> depends;
        std::list<Target *> rdepends;
+       bool        deps_ready;
        bool        prepared;
        bool        buildable;
        bool        counted;
index 83ac8f93ceca649fbffba945e01327b662465736..5cd62f2266f11a082b739334d19df72068dec8e6 100644 (file)
@@ -8,7 +8,6 @@ class VirtualTarget: public Target
 public:
        VirtualTarget(Builder &b, const std::string &n): Target(b,0,n) { }
        const char *get_type() const { return "VirtualTarget"; }
-       void find_depends() { }
        Action *build() { rebuild=false; return 0; }
 private:
        void check_rebuild();