]> git.tdb.fi Git - builder.git/blobdiff - source/conditionalloader.cpp
Move conditionals into helper classes
[builder.git] / source / conditionalloader.cpp
diff --git a/source/conditionalloader.cpp b/source/conditionalloader.cpp
new file mode 100644 (file)
index 0000000..43e613b
--- /dev/null
@@ -0,0 +1,47 @@
+#include <msp/strings/format.h>
+#include "booleanevaluator.h"
+#include "builder.h"
+#include "conditionalloader.h"
+#include "sourcepackage.h"
+
+using namespace std;
+using namespace Msp;
+
+ArchitectureConditional::ArchitectureConditional(const Builder &b, const string &l):
+       builder(b),
+       log_prefix(l)
+{
+       add("if_arch", &ArchitectureConditional::if_arch);
+}
+
+void ArchitectureConditional::if_arch(const string &cond)
+{
+       BooleanEvaluator eval(sigc::hide<1>(sigc::mem_fun(&builder.get_current_arch(), &Architecture::match_name)), false);
+       bool match = eval.evaluate(cond);
+       builder.get_logger().log("configure", format("%s: arch %s %smatched", log_prefix, cond, (match ? "" : "not ")));
+       if(match)
+               load_sub_with(*this);
+}
+
+
+FeatureConditional::FeatureConditional(const SourcePackage &p, const string &l):
+       package(p),
+       log_prefix(l)
+{
+       add("if_feature", &FeatureConditional::if_feature);
+}
+
+void FeatureConditional::if_feature(const string &cond)
+{
+       BooleanEvaluator eval(sigc::mem_fun(&package, &SourcePackage::match_feature));
+       bool match = eval.evaluate(cond);
+       package.get_builder().get_logger().log("configure", format("%s: feature %s %smatched", log_prefix, cond, (match ? "" : "not ")));
+       if(match)
+               load_sub_with(*this);
+}
+
+
+ConditionalLoader::ConditionalLoader(const SourcePackage &p, const string &l):
+       ArchitectureConditional(p.get_builder(), l),
+       FeatureConditional(p, l)
+{ }