From b0eb979b0dc79269cb3bb5bb2e67ef4e80689cfe Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sat, 2 Sep 2006 14:29:09 +0000 Subject: [PATCH] Process ObjectFile dependencies correctly even when it's processed before some headers it depends on Show all dependencies with -a alldeps --- source/analyzer.cpp | 4 ++-- source/builder.cpp | 5 +++++ source/executable.cpp | 2 ++ source/header.h | 2 +- source/install.h | 1 - source/objectfile.cpp | 29 ++++++++++++++++++++++++----- source/objectfile.h | 2 ++ source/sourcefile.cpp | 2 ++ source/systemlibrary.h | 1 - source/target.cpp | 1 + source/target.h | 4 +++- source/virtualtarget.h | 1 - 12 files changed, 42 insertions(+), 12 deletions(-) diff --git a/source/analyzer.cpp b/source/analyzer.cpp index a4780fd..7dceac7 100644 --- a/source/analyzer.cpp +++ b/source/analyzer.cpp @@ -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(&tgt)) return build_depend_table(*tgt.get_depends().front(), depth); else if(dynamic_cast(&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; diff --git a/source/builder.cpp b/source/builder.cpp index 1de726b..e6f036b 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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"); diff --git a/source/executable.cpp b/source/executable.cpp index 4e7b1f4..630ac71 100644 --- a/source/executable.cpp +++ b/source/executable.cpp @@ -25,6 +25,8 @@ void Executable::find_depends() if(lib) add_depend(lib); } + + deps_ready=true; } Action *Executable::build() diff --git a/source/header.h b/source/header.h index 6541cd4..56e5634 100644 --- a/source/header.h +++ b/source/header.h @@ -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 diff --git a/source/install.h b/source/install.h index b81ac9b..2aa3280 100644 --- a/source/install.h +++ b/source/install.h @@ -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: diff --git a/source/objectfile.cpp b/source/objectfile.cpp index 3e531f7..bba701d 100644 --- a/source/objectfile.cpp +++ b/source/objectfile.cpp @@ -1,3 +1,4 @@ +#include #include #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::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(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 &includes=src->get_includes(); for(list::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(); diff --git a/source/objectfile.h b/source/objectfile.h index 962151c..d3315f7 100644 --- a/source/objectfile.h +++ b/source/objectfile.h @@ -15,8 +15,10 @@ public: Action *build(); private: const Component ∁ + std::list new_deps; void find_depends(Target *); + void add_depend(Target *); static std::string generate_target_name(const Component &, const std::string &); }; diff --git a/source/sourcefile.cpp b/source/sourcefile.cpp index ea76efd..ba37f3f 100644 --- a/source/sourcefile.cpp +++ b/source/sourcefile.cpp @@ -33,4 +33,6 @@ void SourceFile::find_depends() if(hdr) add_depend(hdr); } + + deps_ready=true; } diff --git a/source/systemlibrary.h b/source/systemlibrary.h index 9751270..bd55429 100644 --- a/source/systemlibrary.h +++ b/source/systemlibrary.h @@ -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; } }; diff --git a/source/target.cpp b/source/target.cpp index d4c2431..04d9260 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -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) diff --git a/source/target.h b/source/target.h index f0ec0f2..ab9134a 100644 --- a/source/target.h +++ b/source/target.h @@ -20,8 +20,9 @@ public: virtual const char *get_type() const=0; const std::list &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 depends; std::list rdepends; + bool deps_ready; bool prepared; bool buildable; bool counted; diff --git a/source/virtualtarget.h b/source/virtualtarget.h index 83ac8f9..5cd62f2 100644 --- a/source/virtualtarget.h +++ b/source/virtualtarget.h @@ -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(); -- 2.45.2