]> git.tdb.fi Git - builder.git/blobdiff - source/filetarget.cpp
Move file-to-target mapping to a separate class
[builder.git] / source / filetarget.cpp
index e7cfc6c10ce638fcd643a3158ab7d4fcff3eb72e..bc4e110d8700002f822bca478d0e6aa6fde6a8be 100644 (file)
@@ -1,12 +1,6 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2009  Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
 #include <msp/fs/stat.h>
 #include <msp/fs/utils.h>
+#include <msp/strings/format.h>
 #include <msp/time/utils.h>
 #include "builder.h"
 #include "filetarget.h"
@@ -16,17 +10,16 @@ using namespace std;
 using namespace Msp;
 
 FileTarget::FileTarget(Builder &b, const Package *p, const FS::Path &a):
-       Target(b, p, FS::basename(a.str())),
+       Target(b, p, make_name(p, a)),
        path(a),
        size(0)
 {
-       builder.add_target(this);
+       builder.get_vfs().register_path(path, this);
 
-       struct stat st;
-       if(!FS::stat(path, st))
+       if(FS::Stat st = FS::lstat(path))
        {
-               mtime = Time::TimeStamp::from_unixtime(st.st_mtime);
-               size = st.st_size;
+               mtime = st.get_modify_time();
+               size = st.get_size();
        }
 }
 
@@ -53,6 +46,12 @@ void FileTarget::check_rebuild()
                                mark_rebuild((*i)->get_name()+" has changed");
                        else if((*i)->get_rebuild())
                                mark_rebuild((*i)->get_name()+" needs rebuilding");
+                       else
+                       {
+                               Target *real = ft->get_real_target();
+                               if(real->get_rebuild())
+                                       mark_rebuild(real->get_name()+" needs rebuilding");
+                       }
                }
        }
 
@@ -60,3 +59,22 @@ void FileTarget::check_rebuild()
        if(!rebuild && spkg && spkg->get_config().get_mtime()>mtime)
                mark_rebuild("Package options changed");
 }
+
+string FileTarget::make_name(const Package *pkg, const FS::Path &pth)
+{
+       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);
+               }
+       }
+
+       return pth.str();
+}