]> git.tdb.fi Git - builder.git/blobdiff - source/condition.cpp
Change arch and prefix to global options
[builder.git] / source / condition.cpp
index 97e93f1b1c6d5d3780df328a0dfc3925e1e44923..5cce44462d3e984b9f61e85f2152e9c994a70d07 100644 (file)
@@ -1,13 +1,19 @@
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
 #include <msp/strings/utils.h>
+#include "builder.h"
 #include "condition.h"
-#include "package.h"
+#include "sourcepackage.h"
 
 using namespace std;
 using namespace Msp;
 
-#include <iostream>
-
-Condition::Condition(Package &p, const string &expr):
+Condition::Condition(SourcePackage &p, const string &expr):
        pkg(p)
 {
        vector<string> parts=split(expr);
@@ -16,7 +22,7 @@ Condition::Condition(Package &p, const string &expr):
        {
                if(*i=="and")
                        continue;
-               
+
                unsigned token=i->find_first_of("=!");
                if(token==string::npos)
                        expression.insert(StringMap::value_type(*i, "!0"));
@@ -27,12 +33,6 @@ Condition::Condition(Package &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();
@@ -45,7 +45,13 @@ bool Condition::eval()
                if(i->second[1]=='=')
                        ++start;
 
-               if((conf.get_option(i->first).value==i->second.substr(start))==neg)
+               string value;
+               if(conf.is_option(i->first))
+                       value=conf.get_option(i->first).value;
+               else if(i->first=="arch")
+                       value=pkg.get_builder().get_current_arch().get_name();
+
+               if((value==i->second.substr(start))==neg)
                        result=false;
        }
 
@@ -62,7 +68,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()