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>
7 #include <msp/strings/utils.h>
10 #include "sourcepackage.h"
15 void Component::prepare()
17 for(Package *r: requires)
20 broken |= r->is_broken();
27 void Component::create_build_info()
29 BuildInfo final_build_info;
30 final_build_info.defines[toupper(name)+"_BUILD"] = "1";
32 const Package::Requirements &pkg_reqs = package.get_required_packages();
33 Package::Requirements direct_reqs = requires;
34 direct_reqs.insert(direct_reqs.end(), pkg_reqs.begin(), pkg_reqs.end());
35 for(Package *r: direct_reqs)
36 final_build_info.update_from(r->get_exported_build_info(), BuildInfo::DEPENDENCY);
38 Package::Requirements all_reqs = direct_reqs;
39 deque<Package *> queue(direct_reqs.begin(), direct_reqs.end());
42 Package *req = queue.front();
45 for(Package *r: req->get_required_packages())
46 if(!any_equals(all_reqs, r))
48 final_build_info.update_from(r->get_exported_build_info(), BuildInfo::CHAINED);
49 all_reqs.push_back(r);
54 final_build_info.update_from(package.get_build_info());
55 final_build_info.update_from(build_info);
56 build_info = final_build_info;
58 for(FS::Path &p: build_info.incpath)
59 p = (package.get_source_directory()/p).str();
60 for(FS::Path &p: build_info.libpath)
61 p = (package.get_source_directory()/p).str();
64 BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
66 // XXX Cache these and check that the directories actually exist before adding them
67 BuildInfo binfo = build_info;
69 FS::Path gen_dir = package.get_temp_directory()/"generated";
70 if(FS::descendant_depth(path, gen_dir)>=0)
72 FS::Path subdir = FS::dirname(FS::relative(path, gen_dir));
73 binfo.local_incpath.push_back(package.get_source_directory()/subdir);
77 FS::Path subdir = FS::dirname(FS::relative(path, package.get_source_directory()));
78 binfo.local_incpath.push_back(gen_dir/subdir);
83 FS::Path dir = FS::dirname(path);
84 string last = FS::basename(dir);
85 if(any_equals(overlays, last))
86 dir = FS::dirname(dir);
88 if(any_equals(sources, dir))
90 binfo.local_incpath.push_back(dir);
91 for(const string &o: overlays)
92 binfo.local_incpath.push_back(dir/o);
98 vector<FS::Path> Component::collect_source_files() const
100 vector<FS::Path> files;
101 for(const FS::Path &p: sources)
105 vector<FS::Path> dirs;
106 dirs.reserve(1+overlays.size());
108 for(const string &o: overlays)
110 FS::Path opath = p/o;
111 if(FS::is_dir(opath))
112 dirs.push_back(opath);
114 set<string> overlay_files;
115 for(auto j=dirs.begin(); j!=dirs.end(); ++j)
117 package.get_builder().get_logger().log("files", "Traversing %s", *j);
118 for(const string &f: list_files(*j))
122 if(overlay_files.count(f))
124 overlay_files.insert(f);
135 for(const string &o: overlays)
137 FS::Path opath = FS::dirname(p)/o/FS::basename(p);
138 if(FS::is_reg(opath))
139 files.push_back(opath);
148 Component::Loader::Loader(Component &c):
149 DataFile::ObjectLoader<Component>(c),
150 ConditionalLoader(c.package, format("%s/%s", c.package.get_name(), c.name))
152 add("overlay", &Loader::overlay);
153 add("source", &Loader::source);
154 add("install", &Component::install);
155 add("install_map", &Loader::install_map);
156 add("build_info", &Loader::build_info);
157 add("require", &Loader::require);
158 add("default", &Component::deflt);
161 void Component::Loader::build_info()
163 load_sub(obj.build_info);
166 void Component::Loader::install_map()
168 load_sub(obj.install_map, obj.package.get_source_directory());
171 void Component::Loader::overlay(const string &o)
173 obj.overlays.push_back(o);
176 void Component::Loader::require(const string &n)
178 Package *req = obj.package.get_builder().get_package_manager().find_package(n);
180 obj.requires.push_back(req);
182 obj.problems.push_back(format("Required package %s not found", n));
185 void Component::Loader::source(const string &s)
187 FS::Path src_path = obj.package.get_source_directory()/s;
188 if(!FS::exists(src_path))
189 throw IO::file_not_found(src_path.str());
190 obj.sources.push_back(src_path);