2 #include <msp/fs/dir.h>
3 #include <msp/fs/stat.h>
4 #include <msp/fs/utils.h>
5 #include <msp/io/print.h>
6 #include <msp/strings/lexicalcast.h>
7 #include "booleanevaluator.h"
10 #include "sourcepackage.h"
15 Component::Component(SourcePackage &p, const string &n):
22 void Component::prepare()
24 for(Package::Requirements::const_iterator i=requires.begin(); i!=requires.end(); ++i)
28 void Component::create_build_info()
30 BuildInfo final_build_info;
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());
36 Package::Requirements all_reqs = direct_reqs;
37 for(Package::Requirements::iterator i=all_reqs.begin(); i!=all_reqs.end(); ++i)
39 BuildInfo::UpdateLevel level = BuildInfo::CHAINED;
40 if(find(direct_reqs.begin(), direct_reqs.end(), *i)!=direct_reqs.end())
41 level = BuildInfo::DEPENDENCY;
42 final_build_info.update_from((*i)->get_exported_build_info(), level);
44 const Package::Requirements &reqs = (*i)->get_required_packages();
45 for(Package::Requirements::const_iterator j=reqs.begin(); j!=reqs.end(); ++j)
46 if(find(all_reqs.begin(), all_reqs.end(), *j)==all_reqs.end())
47 all_reqs.push_back(*j);
50 final_build_info.update_from(package.get_build_info());
51 final_build_info.update_from(build_info);
52 build_info = final_build_info;
54 for(BuildInfo::PathList::iterator i=build_info.incpath.begin(); i!=build_info.incpath.end(); ++i)
55 *i = (package.get_source_directory() / *i).str();
56 for(BuildInfo::PathList::iterator i=build_info.libpath.begin(); i!=build_info.libpath.end(); ++i)
57 *i = (package.get_source_directory() / *i).str();
60 BuildInfo Component::get_build_info_for_path(const FS::Path &path) const
62 // XXX Cache these and check that the directories actually exist before adding them
63 BuildInfo binfo = build_info;
66 FS::Path dir = FS::dirname(path);
67 string last = FS::basename(dir);
68 for(OverlayList::const_iterator i=overlays.begin(); i!=overlays.end(); ++i)
71 dir = FS::dirname(dir);
75 for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
78 binfo.local_incpath.push_back(dir);
79 for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
80 binfo.local_incpath.push_back(*i/ *j);
86 Component::SourceList Component::collect_source_files() const
89 for(SourceList::const_iterator i=sources.begin(); i!=sources.end(); ++i)
96 for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
98 FS::Path opath = path / *j;
100 dirs.push_back(opath);
102 for(SourceList::const_iterator j=dirs.begin(); j!=dirs.end(); ++j)
104 package.get_builder().get_logger().log("files", format("Traversing %s", *j));
105 list<string> sfiles = list_files(*j);
106 for(list<string>::iterator k=sfiles.begin(); k!=sfiles.end(); ++k)
107 files.push_back(*j / *k);
112 files.push_back(path);
113 for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
115 FS::Path opath = FS::dirname(path)/ *j/FS::basename(path);
116 if(FS::is_reg(opath))
117 files.push_back(opath);
126 Component::Loader::Loader(Component &c):
127 DataFile::ObjectLoader<Component>(c)
129 add("if_arch", &Loader::if_arch);
130 add("if_feature", &Loader::if_feature);
131 add("overlay", &Loader::overlay);
132 add("source", &Loader::source);
133 add("install", &Component::install);
134 add("install_map", &Loader::install_map);
135 add("build_info", &Loader::build_info);
136 add("require", &Loader::require);
137 add("default", &Component::deflt);
140 void Component::Loader::build_info()
142 load_sub(obj.build_info);
145 void Component::Loader::if_arch(const string &cond)
147 BooleanEvaluator eval(sigc::hide<1>(sigc::mem_fun(&obj.package.get_builder().get_current_arch(), &Architecture::match_name)), false);
148 bool match = eval.evaluate(cond);
149 obj.package.get_builder().get_logger().log("configure",
150 format("%s/%s: arch %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
152 load_sub_with(*this);
155 void Component::Loader::if_feature(const string &cond)
157 BooleanEvaluator eval(sigc::mem_fun(&obj.package, &SourcePackage::match_feature));
158 bool match = eval.evaluate(cond);
159 obj.package.get_builder().get_logger().log("configure",
160 format("%s/%s: feature %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
162 load_sub_with(*this);
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());