1 #include <msp/core/algorithm.h>
2 #include <msp/fs/utils.h>
5 #include "objectfile.h"
6 #include "sourcefile.h"
7 #include "sourcepackage.h"
12 ObjectFile::ObjectFile(Builder &b, const Component &c, SourceFile &s):
13 FileTarget(b, c.get_package(), generate_target_path(c, s.get_path())),
17 add_dependency(source);
20 FS::Path ObjectFile::generate_target_path(const Component &comp, const FS::Path &src)
22 const SourcePackage &pkg = comp.get_package();
23 FS::Path temp_dir = pkg.get_temp_directory();
25 if(FS::descendant_depth(src, temp_dir)>=0)
26 rel_src = FS::relative(src, temp_dir);
28 rel_src = FS::relative(src, pkg.get_source_directory());
30 for(const string &c: rel_src)
37 const Architecture &arch = comp.get_package().get_builder().get_current_arch();
38 return temp_dir/comp.get_name()/arch.create_filename<ObjectFile>(FS::basepart(fn));
41 void ObjectFile::set_used_in_shared_library(bool u)
46 void ObjectFile::collect_build_info(BuildInfo &binfo) const
48 Target::collect_build_info(binfo);
49 binfo.update_from(component->get_build_info_for_path(source.get_path()));
52 void ObjectFile::find_dependencies()
54 vector<FileTarget *> headers;
55 find_dependencies(source, headers);
56 for(FileTarget *h: headers)
59 if(h->get_real_target()->is_buildable())
60 h->signal_modified.connect(sigc::mem_fun(this, static_cast<void (ObjectFile::*)()>(&ObjectFile::find_dependencies)));
64 void ObjectFile::find_dependencies(FileTarget &tgt, vector<FileTarget *> &headers)
68 FileTarget *rtgt = dynamic_cast<FileTarget *>(tgt.get_real_target());
69 Dependencies deps_to_add = rtgt->get_transitive_dependencies();
72 FS::Path inst_dir = rtgt->get_component()->get_install_map().get_install_location(*rtgt);
73 /* The target has been displaced by installing it. Displace any
74 dependencies that come from the same package as well. */
75 const SourcePackage *tpkg = rtgt->get_package();
76 for(Target *&d: deps_to_add)
78 FileTarget *file = dynamic_cast<FileTarget *>(d);
79 if(file && file->get_package()==tpkg && FS::descendant_depth(file->get_path(), tpkg->get_source_directory())>=0)
81 const Component *tcomp = file->get_component();
82 FS::Path dep_inst = tcomp->get_install_map().get_install_location(*file);
83 FS::Path displaced = FS::dirname(tgt.get_path())/FS::relative(dep_inst, inst_dir)/FS::basename(file->get_path());
84 d = builder.get_vfs().get_target(displaced);
87 /* If the target was in an overlay directory and the displaced
88 dependency is not found, try removing the overlay from the path. */
89 string last_dir = FS::basename(FS::dirname(displaced));
90 if(any_equals(tcomp->get_overlays(), last_dir))
92 displaced = displaced.subpath(0, displaced.size()-2)/FS::basename(file->get_path());
93 d = builder.get_vfs().get_target(displaced);
100 for(Target *d: deps_to_add)
101 if(FileTarget *file = dynamic_cast<FileTarget *>(d))
103 auto i = lower_bound(headers, file);
104 if(i==headers.end() || *i!=file)
106 headers.insert(i, file);
107 find_dependencies(*file, headers);