X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffiletarget.cpp;h=862ddbe5836197c500ae99cf05f324c419bacbe5;hb=8a2579d4b8e510405402ec316d53a509152aa6ea;hp=1c61810498937199f3ba35c6d5374febff18d151;hpb=ad88e1ba08cf798e5f87796021c947cf500a02e1;p=builder.git diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 1c61810..862ddbe 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -1,23 +1,43 @@ #include #include #include +#include #include #include "builder.h" #include "filetarget.h" #include "sourcepackage.h" +#include "task.h" +#include "tool.h" using namespace std; using namespace Msp; -FileTarget::FileTarget(Builder &b, const SourcePackage *p, const FS::Path &a): - Target(b, generate_name(p, a)), - path(a), - size(0) +FileTarget::FileTarget(Builder &b, const FS::Path &a): + Target(b, generate_name(b, 0, a)), + path(a) { + init(0); +} + +FileTarget::FileTarget(Builder &b, const SourcePackage &p, const FS::Path &a): + Target(b, generate_name(b, &p, a)), + path(a) +{ + init(&p); +} + +void FileTarget::init(const SourcePackage *p) +{ + size = 0; package = p; builder.get_vfs().register_path(path, this); + stat(); +} + +void FileTarget::stat() +{ if(FS::Stat st = FS::lstat(path)) { mtime = st.get_modify_time(); @@ -25,15 +45,32 @@ FileTarget::FileTarget(Builder &b, const SourcePackage *p, const FS::Path &a): } } +string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, const FS::Path &path) +{ + if(pkg && FS::descendant_depth(path, pkg->get_source_directory())>=0) + { + FS::Path relpath = FS::relative(path, pkg->get_source_directory()); + return format("<%s>%s", pkg->get_name(), relpath.str().substr(1)); + } + else if(FS::descendant_depth(path, builder.get_prefix())>=0) + { + FS::Path relpath = FS::relative(path, builder.get_prefix()); + return ""+relpath.str().substr(1); + } + + return path.str(); +} + void FileTarget::touch() { mtime = Time::now(); + modified(); signal_bubble_rebuild.emit(); } void FileTarget::check_rebuild() { - if(!tool) + if(!tool || needs_rebuild()) return; if(!mtime) @@ -50,25 +87,69 @@ void FileTarget::check_rebuild() } } - if(!needs_rebuild() && package && package->get_config().get_mtime()>mtime) - mark_rebuild("Package options changed"); -} + if(!needs_rebuild()) + { + // Some side effects might not exist + for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i) + if((*i)->needs_rebuild()) + mark_rebuild((*i)->get_name()+" needs rebuilding"); + } -string FileTarget::generate_name(const SourcePackage *pkg, const FS::Path &pth) -{ - if(pkg) + if(!needs_rebuild() && package) { - if(FS::descendant_depth(pth, pkg->get_source())>=0) + if(package->get_config().get_mtime()>mtime) + mark_rebuild("Package options changed"); + + if(tool->get_executable()) { - FS::Path relpath = FS::relative(pth, pkg->get_source()); - return format("<%s>%s", pkg->get_name(), relpath.str().substr(1)); + string build_sig = create_build_signature(); + if(package->get_cache().has_key(this, "build_sig")) + { + if(package->get_cache().get_value(this, "build_sig")!=build_sig) + mark_rebuild("Build signature changed"); + } } - else if(FS::descendant_depth(pth, pkg->get_builder().get_prefix())>=0) + } +} + +string FileTarget::create_build_signature() const +{ + if(!package) + return string(); + + const BuildInfo &binfo = (component ? component->get_build_info() : package->get_build_info()); + return tool->create_build_signature(binfo); +} + +void FileTarget::build(Task &task) +{ + task.add_file(path); + task.set_unlink(true); +} + +void FileTarget::build_finished(bool success) +{ + if(success) + { + stat(); + if(package) { - FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix()); - return ""+relpath.str().substr(1); + string build_sig = create_build_signature(); + if(!build_sig.empty()) + package->get_cache().set_value(this, "build_sig", build_sig); } } - return pth.str(); + Target::build_finished(success); +} + +void FileTarget::clean() +{ + if(mtime) + { + FS::unlink(path); + mtime = Time::TimeStamp(); + size = 0; + check_rebuild(); + } }