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 set<string> overlay_files;
103 for(SourceList::const_iterator j=dirs.begin(); j!=dirs.end(); ++j)
105 package.get_builder().get_logger().log("files", format("Traversing %s", *j));
106 list<string> sfiles = list_files(*j);
107 for(list<string>::iterator k=sfiles.begin(); k!=sfiles.end(); ++k)
111 if(overlay_files.count(*k))
113 overlay_files.insert(*k);
115 files.push_back(*j / *k);
121 files.push_back(path);
122 for(OverlayList::const_iterator j=overlays.begin(); j!=overlays.end(); ++j)
124 FS::Path opath = FS::dirname(path)/ *j/FS::basename(path);
125 if(FS::is_reg(opath))
126 files.push_back(opath);
135 Component::Loader::Loader(Component &c):
136 DataFile::ObjectLoader<Component>(c)
138 add("if_arch", &Loader::if_arch);
139 add("if_feature", &Loader::if_feature);
140 add("overlay", &Loader::overlay);
141 add("source", &Loader::source);
142 add("install", &Component::install);
143 add("install_map", &Loader::install_map);
144 add("build_info", &Loader::build_info);
145 add("require", &Loader::require);
146 add("default", &Component::deflt);
149 void Component::Loader::build_info()
151 load_sub(obj.build_info);
154 void Component::Loader::if_arch(const string &cond)
156 BooleanEvaluator eval(sigc::hide<1>(sigc::mem_fun(&obj.package.get_builder().get_current_arch(), &Architecture::match_name)), false);
157 bool match = eval.evaluate(cond);
158 obj.package.get_builder().get_logger().log("configure",
159 format("%s/%s: arch %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
161 load_sub_with(*this);
164 void Component::Loader::if_feature(const string &cond)
166 BooleanEvaluator eval(sigc::mem_fun(&obj.package, &SourcePackage::match_feature));
167 bool match = eval.evaluate(cond);
168 obj.package.get_builder().get_logger().log("configure",
169 format("%s/%s: feature %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
171 load_sub_with(*this);
174 void Component::Loader::install_map()
176 load_sub(obj.install_map, obj.package.get_source_directory());
179 void Component::Loader::overlay(const string &o)
181 obj.overlays.push_back(o);
184 void Component::Loader::require(const string &n)
186 Package *req = obj.package.get_builder().get_package_manager().find_package(n);
188 obj.requires.push_back(req);
190 obj.problems.push_back(format("Required package %s not found", n));
193 void Component::Loader::source(const string &s)
195 obj.sources.push_back((obj.package.get_source_directory()/s).str());