X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Ffiletarget.cpp;h=adbb058dc3d192483bbfa7c03f9d042f1e8dcfdb;hb=e0c863681c8a5fad5918bb7730ecbc65fbdfbc64;hp=6626db8ded177b79ed8ecd1f0b8bd5a81f3bf456;hpb=5eab9f87fc3203d7c2d16be312be74a63a8c8980;p=builder.git diff --git a/source/filetarget.cpp b/source/filetarget.cpp index 6626db8..adbb058 100644 --- a/source/filetarget.cpp +++ b/source/filetarget.cpp @@ -9,11 +9,23 @@ 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); @@ -25,6 +37,23 @@ 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())>=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(); @@ -50,26 +79,6 @@ void FileTarget::check_rebuild() } } - const SourcePackage *spkg = dynamic_cast(package); - if(!needs_rebuild() && spkg && spkg->get_config().get_mtime()>mtime) + if(!needs_rebuild() && package && package->get_config().get_mtime()>mtime) mark_rebuild("Package options changed"); } - -string FileTarget::generate_name(const Package *pkg, const FS::Path &pth) -{ - if(const SourcePackage *spkg = dynamic_cast(pkg)) - { - if(FS::descendant_depth(pth, spkg->get_source())>=0) - { - FS::Path relpath = FS::relative(pth, spkg->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); - } - } - - return pth.str(); -}