// 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);
#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;
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");
+}
{
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
#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;
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());
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;
/**
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
{
Builder &builder;
const Package *package;
std::string name;
- Msp::Time::TimeStamp mtime;
bool buildable;
bool building;
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
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.