From 4629d189a531c962cf15a511df787f30c3adcb02 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 26 Aug 2009 11:16:55 +0000 Subject: [PATCH] Always prepare cmdline to avoid some dependency hassle Get rid of Target::count_rebuild function Detect cyclic dependencies Re-enable the tarball target which accidentally got commented out earlier --- Build | 4 ++-- source/builder.cpp | 30 ++++++++++++------------------ source/target.cpp | 26 ++++++++++---------------- source/target.h | 13 +++---------- source/virtualtarget.cpp | 6 ------ source/virtualtarget.h | 1 - 6 files changed, 27 insertions(+), 53 deletions(-) diff --git a/Build b/Build index c2d976f..2754b9e 100644 --- a/Build +++ b/Build @@ -17,10 +17,10 @@ package "builder" install true; }; - /*tarball "@src" + tarball "@src" { source "bootstrap.sh"; source "Readme.txt"; source "License.txt"; - };*/ + }; }; diff --git a/source/builder.cpp b/source/builder.cpp index 7135a8d..0905bb6 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -258,19 +258,19 @@ int Builder::main() if(dynamic_cast(*i)) IO::print("*"); unsigned count=0; - unsigned ood_count=0; + unsigned to_be_built=0; for(TargetMap::iterator j=targets.begin(); j!=targets.end(); ++j) if(j->second->get_package()==*i) { ++count; if(j->second->get_rebuild()) - ++ood_count; + ++to_be_built; } if(count) { IO::print(" (%d targets", count); - if(ood_count) - IO::print(", %d out-of-date", ood_count); + if(to_be_built) + IO::print(", %d to be built", to_be_built); IO::print(")"); } IO::print("\n"); @@ -285,7 +285,8 @@ int Builder::main() IO::print(IO::cerr, "The following problems were detected:\n"); for(ProblemList::iterator i=problems.begin(); i!=problems.end(); ++i) IO::print(IO::cerr, " %s: %s\n", i->package, i->descr); - IO::print(IO::cerr, "Please fix them and try again.\n"); + if(!analyzer) + IO::print(IO::cerr, "Please fix them and try again.\n"); return 1; } @@ -640,18 +641,7 @@ int Builder::create_targets() cmdline->add_depend(tgt); } - /* If world is to be built, prepare cmdline. If not, add cmdline to world - and prepare world. I don't really like this, but it keeps the graph - acyclic. - - XXX Could we skip preparing targets we are not interested in? */ - if(build_world) - cmdline->prepare(); - else - { - world->add_depend(cmdline); - world->prepare(); - } + cmdline->prepare(); for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i) if(SourcePackage *spkg=dynamic_cast(i->second)) @@ -727,7 +717,11 @@ int Builder::do_build() { Target *cmdline=get_target("cmdline"); - unsigned total=cmdline->count_rebuild(); + unsigned total=0; + for(map::const_iterator i=targets.begin(); i!=targets.end(); ++i) + if(i->second->is_buildable() && i->second->get_rebuild()) + ++total; + if(!total) { IO::print("Already up to date\n"); diff --git a/source/target.cpp b/source/target.cpp index 38eaab5..2005d25 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -26,8 +26,8 @@ Target::Target(Builder &b, const Package *p, const string &n): building(false), rebuild(false), deps_ready(false), - prepared(false), - counted(false) + preparing(false), + prepared(false) { builder.add_target(this); } @@ -65,13 +65,19 @@ void Target::prepare() { if(prepared) return; + if(preparing) + { + builder.problem((package ? package->get_name() : string()), "Dependency cycle detected at "+name); + return; + } - prepared=true; + preparing=true; for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i) (*i)->prepare(); check_rebuild(); - + preparing=false; + prepared=true; } Action *Target::build() @@ -97,18 +103,6 @@ Action *Target::build() return action; } -unsigned Target::count_rebuild() -{ - if(counted) - return 0; - - counted=true; - unsigned count=rebuild; - for(TargetList::iterator i=depends.begin(); i!=depends.end(); ++i) - count+=(*i)->count_rebuild(); - return count; -} - void Target::touch() { mtime=Time::now(); diff --git a/source/target.h b/source/target.h index 263a404..805b64a 100644 --- a/source/target.h +++ b/source/target.h @@ -10,6 +10,7 @@ Distributed under the LGPL #include #include +#include #include #include @@ -41,8 +42,8 @@ protected: TargetList rdepends; bool deps_ready; + bool preparing; bool prepared; - bool counted; Target(Builder &, const Package *, const std::string &); public: @@ -85,14 +86,6 @@ public: */ Action *build(); - void reset_count() { counted=false; } - - /** - Returns the number of targets that need to be rebuilt in order to get this - target up-to-date. - */ - virtual unsigned count_rebuild(); - /** Changes the mtime of the target to the current time. */ @@ -111,7 +104,7 @@ protected: virtual Action *create_action() =0; /** - Handles for the build_done signal of Action. + Handler for the build_done signal of Action. */ virtual void build_done(); }; diff --git a/source/virtualtarget.cpp b/source/virtualtarget.cpp index b2a0d1c..72d369b 100644 --- a/source/virtualtarget.cpp +++ b/source/virtualtarget.cpp @@ -19,9 +19,3 @@ void VirtualTarget::check_rebuild() if((*i)->get_rebuild()) mark_rebuild(FS::basename((*i)->get_name())+" needs rebuilding"); } - -unsigned VirtualTarget::count_rebuild() -{ - // Don't count virtual targets since "building" them causes no action. - return Target::count_rebuild()-rebuild; -} diff --git a/source/virtualtarget.h b/source/virtualtarget.h index ecc237b..252c68f 100644 --- a/source/virtualtarget.h +++ b/source/virtualtarget.h @@ -18,7 +18,6 @@ class VirtualTarget: public Target public: VirtualTarget(Builder &b, const std::string &n): Target(b, 0, n) { } virtual const char *get_type() const { return "VirtualTarget"; } - virtual unsigned count_rebuild(); private: virtual void check_rebuild(); virtual Action *create_action() { return 0; } -- 2.43.0