2 #include <msp/core/algorithm.h>
3 #include <msp/fs/dir.h>
4 #include <msp/fs/stat.h>
5 #include <msp/fs/utils.h>
6 #include <msp/strings/format.h>
9 #include "sourcepackage.h"
14 Component::Component(SourcePackage &p, const string &n):
21 void Component::prepare()
23 for(Package *r: requires)
27 void Component::create_build_info()
29 BuildInfo final_build_info;
31 const Package::Requirements &pkg_reqs = package.get_required_packages();
32 Package::Requirements direct_reqs = requires;
33 direct_reqs.insert(direct_reqs.end(), pkg_reqs.begin(), pkg_reqs.end());
34 for(Package *r: direct_reqs)
35 final_build_info.update_from(r->get_exported_build_info(), BuildInfo::DEPENDENCY);
37 Package::Requirements all_reqs = direct_reqs;
38 deque<Package *> queue(direct_reqs.begin(), direct_reqs.end());
41 Package *req = queue.front();
44 for(Package *r: req->get_required_packages())
45 if(!any_equals(all_reqs, r))
47 final_build_info.update_from(r->get_exported_build_info(), BuildInfo::CHAINED);
48 all_reqs.push_back(r);
53 final_build_info.update_from(package.get_build_info());
54 final_build_info.update_from(build_info);
55 build_info = final_build_info;
57 for(FS::Path &p: build_info.incpath)
58 p = (package.get_source_directory()/p).str();
59 for(FS::Path &p: build_info.libpath)
60 p = (package.get_source_directory()/p).str();
63 BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
65 // XXX Cache these and check that the directories actually exist before adding them
66 BuildInfo binfo = build_info;
68 FS::Path gen_dir = package.get_temp_directory()/"generated";
69 if(FS::descendant_depth(path, gen_dir)>=0)
71 FS::Path subdir = FS::dirname(FS::relative(path, gen_dir));
72 binfo.local_incpath.push_back(package.get_source_directory()/subdir);
76 FS::Path subdir = FS::dirname(FS::relative(path, package.get_source_directory()));
77 binfo.local_incpath.push_back(gen_dir/subdir);
82 FS::Path dir = FS::dirname(path);
83 string last = FS::basename(dir);
84 if(any_equals(overlays, last))
85 dir = FS::dirname(dir);
87 if(any_equals(sources, dir))
89 binfo.local_incpath.push_back(dir);
90 for(const string &o: overlays)
91 binfo.local_incpath.push_back(dir/o);
97 vector<FS::Path> Component::collect_source_files() const
99 vector<FS::Path> files;
100 for(const FS::Path &p: sources)
104 vector<FS::Path> dirs;
105 dirs.reserve(1+overlays.size());
107 for(const string &o: overlays)
109 FS::Path opath = p/o;
110 if(FS::is_dir(opath))
111 dirs.push_back(opath);
113 set<string> overlay_files;
114 for(auto j=dirs.begin(); j!=dirs.end(); ++j)
116 package.get_builder().get_logger().log("files", format("Traversing %s", *j));
117 for(const string &f: list_files(*j))
121 if(overlay_files.count(f))
123 overlay_files.insert(f);
134 for(const string &o: overlays)
136 FS::Path opath = FS::dirname(p)/o/FS::basename(p);
137 if(FS::is_reg(opath))
138 files.push_back(opath);
147 Component::Loader::Loader(Component &c):
148 DataFile::ObjectLoader<Component>(c),
149 ConditionalLoader(c.package, format("%s/%s", c.package.get_name(), c.name))
151 add("overlay", &Loader::overlay);
152 add("source", &Loader::source);
153 add("install", &Component::install);
154 add("install_map", &Loader::install_map);
155 add("build_info", &Loader::build_info);
156 add("require", &Loader::require);
157 add("default", &Component::deflt);
160 void Component::Loader::build_info()
162 load_sub(obj.build_info);
165 void Component::Loader::install_map()
167 load_sub(obj.install_map, obj.package.get_source_directory());
170 void Component::Loader::overlay(const string &o)
172 obj.overlays.push_back(o);
175 void Component::Loader::require(const string &n)
177 Package *req = obj.package.get_builder().get_package_manager().find_package(n);
179 obj.requires.push_back(req);
181 obj.problems.push_back(format("Required package %s not found", n));
184 void Component::Loader::source(const string &s)
186 obj.sources.push_back((obj.package.get_source_directory()/s).str());