1 #include <msp/strings/utils.h>
4 #include "sourcepackage.h"
9 Condition::Condition(SourcePackage &p, const string &expr):
12 vector<string> parts = split(expr);
14 for(vector<string>::iterator i=parts.begin(); i!=parts.end(); ++i)
19 string::size_type token = i->find_first_of("=!");
20 if(token==string::npos)
21 expression.insert(StringMap::value_type(*i, "="));
22 else if(token==0 && (*i)[0]=='!')
23 expression.insert(StringMap::value_type(i->substr(1), "!"));
25 expression.insert(StringMap::value_type(i->substr(0, token), i->substr(token)));
29 bool Condition::eval()
31 const Config &conf = pkg.get_config();
34 for(StringMap::iterator i=expression.begin(); i!=expression.end(); ++i)
36 bool neg = (i->second[0]=='!');
40 string value = i->second.substr(start);
43 if(conf.is_option(i->first))
46 match = lexical_cast<bool>(conf.get_option(i->first).value);
48 match = (conf.get_option(i->first).value==value);
50 else if(i->first=="arch")
51 match = pkg.get_builder().get_current_arch().match_name(value);
61 Condition::Loader::Loader(Condition &c):
64 add("require", &Loader::require);
65 add("build_info", &Loader::build_info);
68 void Condition::Loader::require(const string &pkg)
70 cond.requires.push_back(pkg);
73 void Condition::Loader::build_info()
75 load_sub(cond.build_info);