X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffiletarget.cpp;h=7de9b797761717ce968649931e29ea6a32b8920c;hb=0cf7bb122ef4c0fc46fbb2aaaf1a9d6d5ccec0f1;hp=634b297b996070e45ed9a98ee736c6e9f4826718;hpb=f0c501af5d99233efd3a45076ffbe69a71294863;p=builder.git diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 634b297..7de9b79 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -9,15 +9,32 @@ 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,23 +42,21 @@ FileTarget::FileTarget(Builder &b, const SourcePackage *p, const FS::Path &a): } } -string FileTarget::generate_name(const SourcePackage *pkg, const FS::Path &pth) +string FileTarget::generate_name(Builder &builder, const SourcePackage *pkg, const FS::Path &path) { - if(pkg) + if(pkg && FS::descendant_depth(path, pkg->get_source_directory())>=0) { - 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); - } + 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()); + builder.get_logger().log("debug", format("%s %s %s", path, builder.get_prefix(), relpath)); + return ""+relpath.str().substr(1); } - return pth.str(); + return path.str(); } void FileTarget::touch() @@ -72,3 +87,19 @@ void FileTarget::check_rebuild() if(!needs_rebuild() && package && package->get_config().get_mtime()>mtime) mark_rebuild("Package options changed"); } + +Task *FileTarget::build() +{ + if(tool && !builder.get_dry_run() && mtime) + FS::unlink(path); + + return Target::build(); +} + +void FileTarget::build_finished(bool success) +{ + if(success) + stat(); + + Target::build_finished(success); +}