1 #include <msp/fs/stat.h>
2 #include <msp/fs/utils.h>
4 #include "installedfile.h"
5 #include "sharedlibrary.h"
10 InstalledFile::InstalledFile(Builder &b, const SourcePackage &p, FileTarget &s, const string &loc):
11 FileTarget(b, p, generate_target_path(b.get_prefix(), s, loc)),
14 add_dependency(source);
16 /* XXX Ideally, the tool should handle this (symlinks are not necessary for
17 windows dlls). However, the tool that created the target being installed
18 knows nothing about the InstalledFile. */
19 string base_fn = FS::basename(source.get_path());
20 const string &inst_fn = source.get_install_filename();
21 if(!inst_fn.empty() && inst_fn!=base_fn)
23 link = FS::dirname(path)/base_fn;
24 builder.get_vfs().register_path(link, this);
28 FS::Path InstalledFile::generate_target_path(const FS::Path &prefix, const FileTarget &tgt, const string &loc)
30 if(!tgt.is_installable() && loc.empty())
31 throw invalid_argument(tgt.get_name()+" is not installable");
36 else if(const Component *comp = tgt.get_component())
37 mid = comp->get_install_map().get_install_location(tgt);
39 mid = tgt.get_install_location();
41 string fn = tgt.get_install_filename();
43 fn = FS::basename(tgt.get_path());
48 Target *InstalledFile::get_real_target()
50 return source.get_real_target();
53 void InstalledFile::check_rebuild()
56 mark_rebuild("Does not exist");
57 else if(source.get_mtime()>mtime || source.get_size()!=size)
58 mark_rebuild(source.get_name()+" has changed");
59 else if(source.needs_rebuild())
60 mark_rebuild(source.get_name()+" needs rebuilding");
61 if(!needs_rebuild() && !link.empty())
64 mark_rebuild("Symlink does not exist");
67 FS::Path rel_path = FS::relative(path, FS::dirname(link));
68 if(FS::readlink(link)!=rel_path)
69 mark_rebuild("Symlink needs updating");
74 void InstalledFile::clean()
76 if(!link.empty() && mtime)