X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffiletarget.cpp;h=b42580a099a0a95eb411bc34fa65345cd72a2b03;hb=1dad660f7bbda5ef3239fd6374e0f8a77e19eaaa;hp=6626db8ded177b79ed8ecd1f0b8bd5a81f3bf456;hpb=5eab9f87fc3203d7c2d16be312be74a63a8c8980;p=builder.git diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 6626db8..b42580a 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 Package *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,9 +45,26 @@ FileTarget::FileTarget(Builder &b, const Package *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(); } @@ -50,26 +87,73 @@ void FileTarget::check_rebuild() } } - const SourcePackage *spkg = dynamic_cast(package); - if(!needs_rebuild() && spkg && spkg->get_config().get_mtime()>mtime) - mark_rebuild("Package options changed"); -} + if(!needs_rebuild()) + { + for(Dependencies::iterator i=side_effects.begin(); (i!=side_effects.end() && !needs_rebuild()); ++i) + { + FileTarget *ft = dynamic_cast(*i); + if(ft && !ft->get_mtime()) + mark_rebuild((*i)->get_name()+" does not exist"); + } + } -string FileTarget::generate_name(const Package *pkg, const FS::Path &pth) -{ - if(const SourcePackage *spkg = dynamic_cast(pkg)) + if(!needs_rebuild() && package) { - if(FS::descendant_depth(pth, spkg->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, spkg->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); +} + +Task *FileTarget::build() +{ + Task *task = Target::build(); + task->set_file(path); + task->set_unlink(true); + return task; +} + +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(); + } }