X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffiletarget.cpp;h=9908c0d4d2836c36c5e05e1eda9aa221bab067b2;hb=b0b8e35336104f6e17fb128d794ab1655eb6fee0;hp=1c61810498937199f3ba35c6d5374febff18d151;hpb=ad88e1ba08cf798e5f87796021c947cf500a02e1;p=builder.git diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 1c61810..9908c0d 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -9,11 +9,23 @@ 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); @@ -25,6 +37,23 @@ 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())>=0) + { + FS::Path relpath = FS::relative(path, pkg->get_source()); + 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()); + builder.get_logger().log("debug", format("%s %s %s", path, builder.get_prefix(), relpath)); + return ""+relpath.str().substr(1); + } + + return path.str(); +} + void FileTarget::touch() { mtime = Time::now(); @@ -54,21 +83,10 @@ void FileTarget::check_rebuild() mark_rebuild("Package options changed"); } -string FileTarget::generate_name(const SourcePackage *pkg, const FS::Path &pth) +Task *FileTarget::build() { - if(pkg) - { - if(FS::descendant_depth(pth, pkg->get_source())>=0) - { - FS::Path relpath = FS::relative(pth, pkg->get_source()); - return format("<%s>%s", pkg->get_name(), relpath.str().substr(1)); - } - else if(FS::descendant_depth(pth, pkg->get_builder().get_prefix())>=0) - { - FS::Path relpath = FS::relative(pth, pkg->get_builder().get_prefix()); - return ""+relpath.str().substr(1); - } - } + if(tool && !builder.get_dry_run() && mtime) + FS::unlink(path); - return pth.str(); + return Target::build(); }