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 void Component::prepare()
16 for(Package *r: requires)
19 broken |= r->is_broken();
26 void Component::create_build_info()
28 BuildInfo final_build_info;
30 const Package::Requirements &pkg_reqs = package.get_required_packages();
31 Package::Requirements direct_reqs = requires;
32 direct_reqs.insert(direct_reqs.end(), pkg_reqs.begin(), pkg_reqs.end());
33 for(Package *r: direct_reqs)
34 final_build_info.update_from(r->get_exported_build_info(), BuildInfo::DEPENDENCY);
36 Package::Requirements all_reqs = direct_reqs;
37 deque<Package *> queue(direct_reqs.begin(), direct_reqs.end());
40 Package *req = queue.front();
43 for(Package *r: req->get_required_packages())
44 if(!any_equals(all_reqs, r))
46 final_build_info.update_from(r->get_exported_build_info(), BuildInfo::CHAINED);
47 all_reqs.push_back(r);
52 final_build_info.update_from(package.get_build_info());
53 final_build_info.update_from(build_info);
54 build_info = final_build_info;
56 for(FS::Path &p: build_info.incpath)
57 p = (package.get_source_directory()/p).str();
58 for(FS::Path &p: build_info.libpath)
59 p = (package.get_source_directory()/p).str();
62 BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
64 // XXX Cache these and check that the directories actually exist before adding them
65 BuildInfo binfo = build_info;
67 FS::Path gen_dir = package.get_temp_directory()/"generated";
68 if(FS::descendant_depth(path, gen_dir)>=0)
70 FS::Path subdir = FS::dirname(FS::relative(path, gen_dir));
71 binfo.local_incpath.push_back(package.get_source_directory()/subdir);
75 FS::Path subdir = FS::dirname(FS::relative(path, package.get_source_directory()));
76 binfo.local_incpath.push_back(gen_dir/subdir);
81 FS::Path dir = FS::dirname(path);
82 string last = FS::basename(dir);
83 if(any_equals(overlays, last))
84 dir = FS::dirname(dir);
86 if(any_equals(sources, dir))
88 binfo.local_incpath.push_back(dir);
89 for(const string &o: overlays)
90 binfo.local_incpath.push_back(dir/o);
96 vector<FS::Path> Component::collect_source_files() const
98 vector<FS::Path> files;
99 for(const FS::Path &p: sources)
103 vector<FS::Path> dirs;
104 dirs.reserve(1+overlays.size());
106 for(const string &o: overlays)
108 FS::Path opath = p/o;
109 if(FS::is_dir(opath))
110 dirs.push_back(opath);
112 set<string> overlay_files;
113 for(auto j=dirs.begin(); j!=dirs.end(); ++j)
115 package.get_builder().get_logger().log("files", "Traversing %s", *j);
116 for(const string &f: list_files(*j))
120 if(overlay_files.count(f))
122 overlay_files.insert(f);
133 for(const string &o: overlays)
135 FS::Path opath = FS::dirname(p)/o/FS::basename(p);
136 if(FS::is_reg(opath))
137 files.push_back(opath);
146 Component::Loader::Loader(Component &c):
147 DataFile::ObjectLoader<Component>(c),
148 ConditionalLoader(c.package, format("%s/%s", c.package.get_name(), c.name))
150 add("overlay", &Loader::overlay);
151 add("source", &Loader::source);
152 add("install", &Component::install);
153 add("install_map", &Loader::install_map);
154 add("build_info", &Loader::build_info);
155 add("require", &Loader::require);
156 add("default", &Component::deflt);
159 void Component::Loader::build_info()
161 load_sub(obj.build_info);
164 void Component::Loader::install_map()
166 load_sub(obj.install_map, obj.package.get_source_directory());
169 void Component::Loader::overlay(const string &o)
171 obj.overlays.push_back(o);
174 void Component::Loader::require(const string &n)
176 Package *req = obj.package.get_builder().get_package_manager().find_package(n);
178 obj.requires.push_back(req);
180 obj.problems.push_back(format("Required package %s not found", n));
183 void Component::Loader::source(const string &s)
185 FS::Path src_path = obj.package.get_source_directory()/s;
186 if(!FS::exists(src_path))
187 throw IO::file_not_found(src_path.str());
188 obj.sources.push_back(src_path);