]> git.tdb.fi Git - builder.git/blob - source/installedfile.cpp
Evaluate conditions at load time to allow more flexibility
[builder.git] / source / installedfile.cpp
1 #include <msp/fs/utils.h>
2 #include "builder.h"
3 #include "installedfile.h"
4 #include "sharedlibrary.h"
5
6 using namespace std;
7 using namespace Msp;
8
9 InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, const string &loc):
10         FileTarget(b, p, generate_target_path(b.get_prefix(), s, loc)),
11         source(s)
12 {
13         add_depend(source);
14
15         if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&source))
16                 if(!shlib->get_soname().empty())
17                         link = FS::dirname(path)/FS::basename(shlib->get_path());
18
19         if(!link.empty())
20                 builder.get_vfs().register_path(link, this);
21 }
22
23 FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const string &loc)
24 {
25         if(!tgt.is_installable() && loc.empty())
26                 throw invalid_argument(tgt.get_name()+" is not installable");
27
28         FS::Path mid;
29         if(!loc.empty())
30                 mid = loc;
31         else if(const Component *comp = tgt.get_component())
32                 mid = comp->get_install_map().get_install_location(tgt);
33         else
34                 mid = tgt.get_install_location();
35
36         string fn = FS::basename(tgt.get_path());
37         if(const SharedLibrary *shlib = dynamic_cast<const SharedLibrary *>(&tgt))
38                 if(!shlib->get_soname().empty())
39                         fn = shlib->get_soname();
40
41         return prefix/mid/fn;
42 }
43
44 Target *InstalledFile::get_real_target()
45 {
46         return source.get_real_target();
47 }
48
49 void InstalledFile::check_rebuild()
50 {
51         if(!mtime)
52                 mark_rebuild("Does not exist");
53         else if(source.get_mtime()>mtime || source.get_size()!=size)
54                 mark_rebuild(source.get_name()+" has changed");
55         else if(source.needs_rebuild())
56                 mark_rebuild(source.get_name()+" needs rebuilding");
57 }