From 20994a6f4802f2dbcf01888d0e1996edf554ade5 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Fri, 5 Feb 2010 12:00:29 +0000 Subject: [PATCH] Move some file-related things from Target to FileTarget --- source/builder.cpp | 2 +- source/filetarget.cpp | 33 +++++++++++++++++++++++++++++++++ source/filetarget.h | 10 ++++++++++ source/target.cpp | 33 +-------------------------------- source/target.h | 11 ++--------- 5 files changed, 47 insertions(+), 42 deletions(-) diff --git a/source/builder.cpp b/source/builder.cpp index 208e7d5..f08b27a 100644 --- a/source/builder.cpp +++ b/source/builder.cpp @@ -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(get_target((cwd/ *i).str())); if(!tgt) { IO::print(IO::cerr, "Unknown what-if target %s\n", *i); diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 8f35cfc..e7cfc6c 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -7,8 +7,10 @@ Distributed under the LGPL #include #include +#include #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(*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(package); + if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime) + mark_rebuild("Package options changed"); +} diff --git a/source/filetarget.h b/source/filetarget.h index 982b8cb..3d4d004 100644 --- a/source/filetarget.h +++ b/source/filetarget.h @@ -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 diff --git a/source/target.cpp b/source/target.cpp index c0c3c18..0760f53 100644 --- a/source/target.cpp +++ b/source/target.cpp @@ -7,12 +7,10 @@ Distributed under the LGPL #include #include -#include #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(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(package); - if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime) - mark_rebuild("Package options changed"); -} - void Target::build_done() { building = false; diff --git a/source/target.h b/source/target.h index ec23df6..01b115a 100644 --- a/source/target.h +++ b/source/target.h @@ -23,7 +23,7 @@ typedef std::list 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. -- 2.43.0