]> git.tdb.fi Git - builder.git/blob - source/installmap.cpp
Flexible way to specify install locations for components
[builder.git] / source / installmap.cpp
1 #include <msp/fs/utils.h>
2 #include "filetarget.h"
3 #include "installmap.h"
4
5 using namespace std;
6 using namespace Msp;
7
8 void InstallMap::add_mapping(const FS::Path &src, const FS::Path &inst)
9 {
10         Entry e;
11         e.source = src;
12         e.install = inst;
13         entries.push_back(e);
14 }
15
16 FS::Path InstallMap::get_install_location(const FileTarget &target) const
17 {
18         const FS::Path &source = target.get_path();
19         FS::Path install = target.get_install_location();
20         for(list<Entry>::const_iterator i=entries.begin(); i!=entries.end(); ++i)
21         {
22                 int source_depth = FS::descendant_depth(source, i->source);
23                 if(source_depth>=0)
24                 {
25                         FS::Path install_base = FS::common_ancestor(install, i->install);
26                         if(install_base.size()>1)
27                         {
28                                 install = i->install/FS::dirname(source).subpath(i->source.size());
29                                 break;
30                         }
31                 }
32         }
33
34         return install;
35 }
36
37
38 InstallMap::Loader::Loader(InstallMap &m, const FS::Path &s):
39         DataFile::ObjectLoader<InstallMap>(m),
40         source_base(s)
41 {
42         add("map", &Loader::map);
43 }
44
45 void InstallMap::Loader::map(const string &src, const string &inst)
46 {
47         obj.add_mapping(source_base/src, inst);
48 }