1 #include <msp/core/algorithm.h>
2 #include <msp/fs/dir.h>
3 #include <msp/fs/stat.h>
4 #include <msp/fs/utils.h>
5 #include <msp/strings/format.h>
8 #include "sourcepackage.h"
13 Component::Component(SourcePackage &p, const string &n):
20 void Component::prepare()
22 for(Package *r: requires)
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());
34 Package::Requirements all_reqs = direct_reqs;
35 for(Package *r: all_reqs)
37 BuildInfo::UpdateLevel level = BuildInfo::CHAINED;
38 if(any_equals(direct_reqs, r))
39 level = BuildInfo::DEPENDENCY;
40 final_build_info.update_from(r->get_exported_build_info(), level);
42 for(Package *q: r->get_required_packages())
43 if(!any_equals(all_reqs, q))
44 all_reqs.push_back(q);
47 final_build_info.update_from(package.get_build_info());
48 final_build_info.update_from(build_info);
49 build_info = final_build_info;
51 for(FS::Path &p: build_info.incpath)
52 p = (package.get_source_directory()/p).str();
53 for(FS::Path &p: build_info.libpath)
54 p = (package.get_source_directory()/p).str();
57 BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
59 // XXX Cache these and check that the directories actually exist before adding them
60 BuildInfo binfo = build_info;
62 FS::Path gen_dir = package.get_temp_directory()/"generated";
63 if(FS::descendant_depth(path, gen_dir)>=0)
65 FS::Path subdir = FS::dirname(FS::relative(path, gen_dir));
66 binfo.local_incpath.push_back(package.get_source_directory()/subdir);
70 FS::Path subdir = FS::dirname(FS::relative(path, package.get_source_directory()));
71 binfo.local_incpath.push_back(gen_dir/subdir);
76 FS::Path dir = FS::dirname(path);
77 string last = FS::basename(dir);
78 if(any_equals(overlays, last))
79 dir = FS::dirname(dir);
81 if(any_equals(sources, dir))
83 binfo.local_incpath.push_back(dir);
84 for(const string &o: overlays)
85 binfo.local_incpath.push_back(dir/o);
91 list<FS::Path> Component::collect_source_files() const
94 for(const FS::Path &p: sources)
100 for(const string &o: overlays)
102 FS::Path opath = p/o;
103 if(FS::is_dir(opath))
104 dirs.push_back(opath);
106 set<string> overlay_files;
107 for(auto j=dirs.begin(); j!=dirs.end(); ++j)
109 package.get_builder().get_logger().log("files", format("Traversing %s", *j));
110 for(const string &f: list_files(*j))
114 if(overlay_files.count(f))
116 overlay_files.insert(f);
127 for(const string &o: overlays)
129 FS::Path opath = FS::dirname(p)/o/FS::basename(p);
130 if(FS::is_reg(opath))
131 files.push_back(opath);
140 Component::Loader::Loader(Component &c):
141 DataFile::ObjectLoader<Component>(c),
142 ConditionalLoader(c.package, format("%s/%s", c.package.get_name(), c.name))
144 add("overlay", &Loader::overlay);
145 add("source", &Loader::source);
146 add("install", &Component::install);
147 add("install_map", &Loader::install_map);
148 add("build_info", &Loader::build_info);
149 add("require", &Loader::require);
150 add("default", &Component::deflt);
153 void Component::Loader::build_info()
155 load_sub(obj.build_info);
158 void Component::Loader::install_map()
160 load_sub(obj.install_map, obj.package.get_source_directory());
163 void Component::Loader::overlay(const string &o)
165 obj.overlays.push_back(o);
168 void Component::Loader::require(const string &n)
170 Package *req = obj.package.get_builder().get_package_manager().find_package(n);
172 obj.requires.push_back(req);
174 obj.problems.push_back(format("Required package %s not found", n));
177 void Component::Loader::source(const string &s)
179 obj.sources.push_back((obj.package.get_source_directory()/s).str());