X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fcondition.cpp;h=4c7b5ed5b2d923a8b308c975e470dbfdf75041b3;hb=433f9ef196b6f5af6bb38447b650f5afaa5a783a;hp=c4c01b21fbdf692fc92cb4fe147a4ad58b969a86;hpb=654de39b62a9a58fd8e1b5a557361d628345788b;p=builder.git diff --git a/source/condition.cpp b/source/condition.cpp index c4c01b2..4c7b5ed 100644 --- a/source/condition.cpp +++ b/source/condition.cpp @@ -1,11 +1,12 @@ /* $Id$ This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions +Copyright © 2007-2010 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ #include +#include "builder.h" #include "condition.h" #include "sourcepackage.h" @@ -15,14 +16,14 @@ using namespace Msp; Condition::Condition(SourcePackage &p, const string &expr): pkg(p) { - vector parts=split(expr); + vector parts = split(expr); for(vector::iterator i=parts.begin(); i!=parts.end(); ++i) { if(*i=="and") continue; - unsigned token=i->find_first_of("=!"); + string::size_type token = i->find_first_of("=!"); if(token==string::npos) expression.insert(StringMap::value_type(*i, "!0")); else if(token==0 && (*i)[0]=='!') @@ -32,26 +33,27 @@ Condition::Condition(SourcePackage &p, const string &expr): } } -void Condition::resolve_refs() -{ - for(PkgRefList::iterator i=requires.begin(); i!=requires.end(); ++i) - i->resolve(); -} - bool Condition::eval() { - const Config &conf=pkg.get_config(); + const Config &conf = pkg.get_config(); - bool result=true; + bool result = true; for(StringMap::iterator i=expression.begin(); i!=expression.end(); ++i) { - bool neg=(i->second[0]=='!'); - unsigned start=1; + bool neg = (i->second[0]=='!'); + unsigned start = 1; if(i->second[1]=='=') ++start; + string value = i->second.substr(start); + + bool match = false; + if(conf.is_option(i->first)) + match = (conf.get_option(i->first).value==value); + else if(i->first=="arch") + match = pkg.get_builder().get_current_arch().match_name(value); - if((conf.get_option(i->first).value==i->second.substr(start))==neg) - result=false; + if(match==neg) + result = false; } return result; @@ -67,7 +69,7 @@ Condition::Loader::Loader(Condition &c): void Condition::Loader::require(const string &pkg) { - cond.requires.push_back(PackageRef(cond.pkg.get_builder(), pkg)); + cond.requires.push_back(pkg); } void Condition::Loader::build_info()