]> git.tdb.fi Git - builder.git/commitdiff
Always prepare cmdline to avoid some dependency hassle
authorMikko Rasa <tdb@tdb.fi>
Wed, 26 Aug 2009 11:16:55 +0000 (11:16 +0000)
committerMikko Rasa <tdb@tdb.fi>
Wed, 26 Aug 2009 11:16:55 +0000 (11:16 +0000)
Get rid of Target::count_rebuild function
Detect cyclic dependencies
Re-enable the tarball target which accidentally got commented out earlier

Build
source/builder.cpp
source/target.cpp
source/target.h
source/virtualtarget.cpp
source/virtualtarget.h

diff --git a/Build b/Build
index c2d976f6c66891c4dacc74261a506d995726a401..2754b9ef5aa7ba257a45ecb848a3a3503c5f09bd 100644 (file)
--- 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";
-       };*/
+       };
 };
index 7135a8d97b1a42a4e6aa24860ade31c32fa4f9b4..0905bb6779530af63a6fd2f25151cf4248609715 100644 (file)
@@ -258,19 +258,19 @@ int Builder::main()
                        if(dynamic_cast<SourcePackage *>(*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<SourcePackage *>(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<string, Target *>::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");
index 38eaab59708440fb3d70bd3761ac4e793e53f321..2005d25cfc55817792d47289a2c1c2dabb58ce9d 100644 (file)
@@ -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();
index 263a404af6b8549b1aa2582fbd860fba634fdbf7..805b64a09a891ecbea2c2039c1a7c60379b672fd 100644 (file)
@@ -10,6 +10,7 @@ Distributed under the LGPL
 
 #include <list>
 #include <map>
+#include <set>
 #include <string>
 #include <msp/time/timestamp.h>
 
@@ -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();
 };
index b2a0d1cfd4a0f90a58e7eb29b0c97aefa63c2233..72d369b402ca641fdd021fc3bd1b23849a0b3710 100644 (file)
@@ -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;
-}
index ecc237b7f6ee37e74d47eca5d2c0c72f509efb09..252c68f3cb3aa7ebd6f187f349954463a22399f4 100644 (file)
@@ -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; }