]> git.tdb.fi Git - builder.git/blobdiff - source/filetarget.cpp
Add a separate set of functions for registering and looking up targets by path
[builder.git] / source / filetarget.cpp
index d6dcd1681c4d589cdb7976279e7acfdc032dd46c..88672317dc35cab7afa7c5fdef65a8d65edc7e57 100644 (file)
@@ -1,5 +1,6 @@
 #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"
@@ -9,11 +10,11 @@ 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.register_path(path, this);
 
        if(FS::Stat st = FS::lstat(path))
        {
@@ -58,3 +59,14 @@ 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))
+       {
+               FS::Path relpath = FS::relative(pth, spkg->get_source());
+               return format("<%s>%s", pkg->get_name(), relpath.str().substr(1));
+       }
+       else
+               return pth.str();
+}