3 This file is part of builder
4 Copyright © 2007-2009 Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
8 #include <msp/strings/utils.h>
10 #include "condition.h"
11 #include "sourcepackage.h"
16 Condition::Condition(SourcePackage &p, const string &expr):
19 vector<string> parts = split(expr);
21 for(vector<string>::iterator i=parts.begin(); i!=parts.end(); ++i)
26 string::size_type token = i->find_first_of("=!");
27 if(token==string::npos)
28 expression.insert(StringMap::value_type(*i, "!0"));
29 else if(token==0 && (*i)[0]=='!')
30 expression.insert(StringMap::value_type(*i, "=0"));
32 expression.insert(StringMap::value_type(i->substr(0, token), i->substr(token)));
36 bool Condition::eval()
38 const Config &conf = pkg.get_config();
41 for(StringMap::iterator i=expression.begin(); i!=expression.end(); ++i)
43 bool neg = (i->second[0]=='!');
49 if(conf.is_option(i->first))
50 value = conf.get_option(i->first).value;
51 else if(i->first=="arch")
52 value = pkg.get_builder().get_current_arch().get_name();
54 if((value==i->second.substr(start))==neg)
62 Condition::Loader::Loader(Condition &c):
65 add("require", &Loader::require);
66 add("build_info", &Loader::build_info);
69 void Condition::Loader::require(const string &pkg)
71 cond.requires.push_back(pkg);
74 void Condition::Loader::build_info()
76 load_sub(cond.build_info);