]> git.tdb.fi Git - builder.git/commitdiff
Move some file-related things from Target to FileTarget
authorMikko Rasa <tdb@tdb.fi>
Fri, 5 Feb 2010 12:00:29 +0000 (12:00 +0000)
committerMikko Rasa <tdb@tdb.fi>
Fri, 5 Feb 2010 12:00:29 +0000 (12:00 +0000)
source/builder.cpp
source/filetarget.cpp
source/filetarget.h
source/target.cpp
source/target.h

index 208e7d5b389aec8524f75922e5d2df828848bdbc..f08b27aec69d667ac2eef6d1fdcfa09bf83292c5 100644 (file)
@@ -626,7 +626,7 @@ int Builder::create_targets()
        // Apply what-ifs
        for(StringList::iterator i=what_if.begin(); i!=what_if.end(); ++i)
        {
-               Target *tgt = get_target((cwd/ *i).str());
+               FileTarget *tgt = dynamic_cast<FileTarget *>(get_target((cwd/ *i).str()));
                if(!tgt)
                {
                        IO::print(IO::cerr, "Unknown what-if target %s\n", *i);
index 8f35cfc9ed3b54f776f30159ab7e909fb5ed4843..e7cfc6c10ce638fcd643a3158ab7d4fcff3eb72e 100644 (file)
@@ -7,8 +7,10 @@ Distributed under the LGPL
 
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
+#include <msp/time/utils.h>
 #include "builder.h"
 #include "filetarget.h"
+#include "sourcepackage.h"
 
 using namespace std;
 using namespace Msp;
@@ -27,3 +29,34 @@ FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a):
                size = st.st_size;
        }
 }
+
+void FileTarget::touch()
+{
+       mtime = Time::now();
+}
+
+void FileTarget::check_rebuild()
+{
+       if(!buildable)
+               return;
+
+       if(builder.get_build_all())
+               mark_rebuild("Rebuilding everything");
+       else if(!mtime)
+               mark_rebuild("Does not exist");
+       else
+       {
+               for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
+               {
+                       FileTarget *ft = dynamic_cast<FileTarget *>(*i);
+                       if(ft && ft->get_mtime()>mtime)
+                               mark_rebuild((*i)->get_name()+" has changed");
+                       else if((*i)->get_rebuild())
+                               mark_rebuild((*i)->get_name()+" needs rebuilding");
+               }
+       }
+
+       const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
+       if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
+               mark_rebuild("Package options changed");
+}
index 982b8cb6abce166751d05cd4f5c4b82021503d56..3d4d004d9611c6e39316a39c1175bec8a3a9afa8 100644 (file)
@@ -19,12 +19,22 @@ class FileTarget: public Target
 {
 protected:
        Msp::FS::Path path;
+       Msp::Time::TimeStamp mtime;
        unsigned size;
 
        FileTarget(Builder &, const Package *, const Msp::FS::Path &);
 public:
        const Msp::FS::Path &get_path() const { return path; }
+       const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
        unsigned get_size() const { return size; }
+
+       /**
+       Changes the mtime of the target to the current time.
+       */
+       void touch();
+
+protected:
+       virtual void check_rebuild();
 };
 
 #endif
index c0c3c18051bbfcd4d8c76250b59f1c081c694b85..0760f531d8a91af342d6e4cc13c3e20bc0eab2f8 100644 (file)
@@ -7,12 +7,10 @@ Distributed under the LGPL
 
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
-#include <msp/time/utils.h>
 #include "action.h"
 #include "builder.h"
 #include "filetarget.h"
 #include "package.h"
-#include "sourcepackage.h"
 #include "target.h"
 
 using namespace std;
@@ -85,6 +83,7 @@ Action *Target::build()
                return 0;
        }
 
+       // XXX Minor breach of OO here
        if(FileTarget *ft = dynamic_cast<FileTarget *>(this))
                if(!builder.get_dry_run() && FS::exists(ft->get_path()))
                        FS::unlink(ft->get_path());
@@ -100,42 +99,12 @@ Action *Target::build()
        return action;
 }
 
-void Target::touch()
-{
-       mtime = Time::now();
-}
-
 void Target::mark_rebuild(const std::string &reason)
 {
        rebuild = true;
        rebuild_reason = reason;
 }
 
-void Target::check_rebuild()
-{
-       if(!buildable)
-               return;
-
-       if(builder.get_build_all())
-               mark_rebuild("Rebuilding everything");
-       else if(!mtime)
-               mark_rebuild("Does not exist");
-       else
-       {
-               for(TargetList::iterator i=depends.begin(); (i!=depends.end() && !rebuild); ++i)
-               {
-                       if((*i)->get_mtime()>mtime)
-                               mark_rebuild((*i)->get_name()+" has changed");
-                       else if((*i)->get_rebuild())
-                               mark_rebuild((*i)->get_name()+" needs rebuilding");
-               }
-       }
-
-       const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(package);
-       if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
-               mark_rebuild("Package options changed");
-}
-
 void Target::build_done()
 {
        building = false;
index ec23df6dfe01a03d2b0b419870d4ec503bc91ae4..01b115a7a6b5ddf2e008f39299c7c392ae84bcd2 100644 (file)
@@ -23,7 +23,7 @@ typedef std::list<Target *> TargetList;
 
 /**
 Targets make up the build graph.  This class is a base for all target types and
-handles many common tasks.  Most targets are associated with a file.
+handles many common tasks.  See also FileTarget and VirtualTarget.
 */
 class Target
 {
@@ -31,7 +31,6 @@ protected:
        Builder &builder;
        const Package *package;
        std::string name;
-       Msp::Time::TimeStamp mtime;
 
        bool buildable;
        bool building;
@@ -51,7 +50,6 @@ public:
        virtual const char *get_type() const = 0;
        const std::string &get_name() const { return name; }
        const Package *get_package() const { return package; }
-       const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
 
        /**
        Tries to locate a target that will help getting this target built.  If all
@@ -84,18 +82,13 @@ public:
        Starts building the target.  Returns the Action used for building.
        */
        Action *build();
-
-       /**
-       Changes the mtime of the target to the current time.
-       */
-       void touch();
 protected:
        void mark_rebuild(const std::string &);
 
        /**
        Checks if the target needs to be rebuilt and why.
        */
-       virtual void check_rebuild();
+       virtual void check_rebuild() = 0;
 
        /**
        Creates and returns an Action suitable for building this target.