]> git.tdb.fi Git - builder.git/blobdiff - source/filetarget.cpp
Call prepare_build before returning to save package configuration
[builder.git] / source / filetarget.cpp
index dd20a0e8554d8cb5795af04e1e09b33fa279c2cb..9908c0d4d2836c36c5e05e1eda9aa221bab067b2 100644 (file)
@@ -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,9 +37,27 @@ 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 "<prefix>"+relpath.str().substr(1);
+       }
+
+       return path.str();
+}
+
 void FileTarget::touch()
 {
        mtime = Time::now();
+       signal_bubble_rebuild.emit();
 }
 
 void FileTarget::check_rebuild()
@@ -35,9 +65,7 @@ void FileTarget::check_rebuild()
        if(!tool)
                return;
 
-       if(builder.get_build_all())
-               mark_rebuild("Rebuilding everything");
-       else if(!mtime)
+       if(!mtime)
                mark_rebuild("Does not exist");
        else
        {
@@ -48,35 +76,17 @@ void FileTarget::check_rebuild()
                                mark_rebuild((*i)->get_name()+" has changed");
                        else if((*i)->needs_rebuild())
                                mark_rebuild((*i)->get_name()+" needs rebuilding");
-                       else
-                       {
-                               Target *real = ft->get_real_target();
-                               if(real->needs_rebuild())
-                                       mark_rebuild(real->get_name()+" needs rebuilding");
-                       }
                }
        }
 
-       const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(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)
+Task *FileTarget::build()
 {
-       if(const SourcePackage *spkg = dynamic_cast<const SourcePackage *>(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 "<prefix>"+relpath.str().substr(1);
-               }
-       }
+       if(tool && !builder.get_dry_run() && mtime)
+               FS::unlink(path);
 
-       return pth.str();
+       return Target::build();
 }