]> git.tdb.fi Git - builder.git/commitdiff
Move conditionals into helper classes
authorMikko Rasa <tdb@tdb.fi>
Wed, 15 Oct 2014 18:23:22 +0000 (21:23 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 15 Oct 2014 18:23:22 +0000 (21:23 +0300)
source/component.cpp
source/component.h
source/conditionalloader.cpp [new file with mode: 0644]
source/conditionalloader.h [new file with mode: 0644]
source/package.cpp
source/package.h
source/sourcepackage.cpp
source/sourcepackage.h

index a42b81cded44229d877882c535b11c2982ecfb77..2bfa736e14ea2dc7663fcae75b5f6f8c3329395a 100644 (file)
@@ -4,7 +4,6 @@
 #include <msp/fs/utils.h>
 #include <msp/io/print.h>
 #include <msp/strings/lexicalcast.h>
-#include "booleanevaluator.h"
 #include "builder.h"
 #include "component.h"
 #include "sourcepackage.h"
@@ -133,10 +132,9 @@ Component::SourceList Component::collect_source_files() const
 
 
 Component::Loader::Loader(Component &c):
-       DataFile::ObjectLoader<Component>(c)
+       DataFile::ObjectLoader<Component>(c),
+       ConditionalLoader(c.package, format("%s/%s", c.package.get_name(), c.name))
 {
-       add("if_arch",         &Loader::if_arch);
-       add("if_feature",      &Loader::if_feature);
        add("overlay",         &Loader::overlay);
        add("source",          &Loader::source);
        add("install",         &Component::install);
@@ -151,26 +149,6 @@ void Component::Loader::build_info()
        load_sub(obj.build_info);
 }
 
-void Component::Loader::if_arch(const string &cond)
-{
-       BooleanEvaluator eval(sigc::hide<1>(sigc::mem_fun(&obj.package.get_builder().get_current_arch(), &Architecture::match_name)), false);
-       bool match = eval.evaluate(cond);
-       obj.package.get_builder().get_logger().log("configure",
-               format("%s/%s: arch %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
-       if(match)
-               load_sub_with(*this);
-}
-
-void Component::Loader::if_feature(const string &cond)
-{
-       BooleanEvaluator eval(sigc::mem_fun(&obj.package, &SourcePackage::match_feature));
-       bool match = eval.evaluate(cond);
-       obj.package.get_builder().get_logger().log("configure",
-               format("%s/%s: feature %s %smatched", obj.package.get_name(), obj.name, cond, (match ? "" : "not ")));
-       if(match)
-               load_sub_with(*this);
-}
-
 void Component::Loader::install_map()
 {
        load_sub(obj.install_map, obj.package.get_source_directory());
index 1fbe3def1ae54bcc5aaf48c23c60f81595a9ac04..0e1efad028d5d627b69e6e59f32c5b4d60ce7d34 100644 (file)
@@ -5,6 +5,7 @@
 #include <msp/datafile/objectloader.h>
 #include <msp/fs/path.h>
 #include "buildinfo.h"
+#include "conditionalloader.h"
 #include "installmap.h"
 #include "package.h"
 
@@ -19,14 +20,12 @@ their own.
 class Component
 {
 public:
-       class Loader: public Msp::DataFile::ObjectLoader<Component>
+       class Loader: public Msp::DataFile::ObjectLoader<Component>, public ConditionalLoader
        {
        public:
                Loader(Component &);
        private:
                void build_info();
-               void if_arch(const std::string &);
-               void if_feature(const std::string &);
                void install_map();
                void overlay(const std::string &);
                void require(const std::string &);
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)
+{ }
diff --git a/source/conditionalloader.h b/source/conditionalloader.h
new file mode 100644 (file)
index 0000000..5184fac
--- /dev/null
@@ -0,0 +1,43 @@
+#ifndef CONDITIONALLOADER_H_
+#define CONDITIONALLOADER_H_
+
+#include <string>
+#include <msp/datafile/loader.h>
+
+class Builder;
+class SourcePackage;
+
+class ArchitectureConditional: virtual public Msp::DataFile::Loader
+{
+private:
+       const Builder &builder;
+       std::string log_prefix;
+
+protected:
+       ArchitectureConditional(const Builder &, const std::string &);
+
+private:
+       void if_arch(const std::string &);
+};
+
+
+class FeatureConditional: virtual public Msp::DataFile::Loader
+{
+private:
+       const SourcePackage &package;
+       std::string log_prefix;
+
+protected:
+       FeatureConditional(const SourcePackage &, const std::string &);
+
+       void if_feature(const std::string &);
+};
+
+
+class ConditionalLoader: public ArchitectureConditional, FeatureConditional
+{
+protected:
+       ConditionalLoader(const SourcePackage &, const std::string &);
+};
+
+#endif
index 5f25f1a90eb053705092d75b13f565109ffbf2a4..64cec87f15e48803e349ab2b5a242470d7cc4f56 100644 (file)
@@ -1,7 +1,6 @@
 #include <msp/io/print.h>
 #include <msp/strings/lexicalcast.h>
 #include <msp/strings/utils.h>
-#include "booleanevaluator.h"
 #include "builder.h"
 #include "package.h"
 
@@ -32,22 +31,13 @@ void Package::prepare()
 
 
 Package::Loader::Loader(Package &p):
-       DataFile::ObjectLoader<Package>(p)
+       DataFile::ObjectLoader<Package>(p),
+       ArchitectureConditional(p.builder, p.name)
 {
-       add("if_arch", &Loader::if_arch);
        add("label",   &Package::label);
        add("require", &Loader::require);
 }
 
-void Package::Loader::if_arch(const string &cond)
-{
-       BooleanEvaluator eval(sigc::hide<1>(sigc::mem_fun(&obj.builder.get_current_arch(), &Architecture::match_name)), false);
-       bool match = eval.evaluate(cond);
-       obj.builder.get_logger().log("configure", format("%s: arch %s %smatched", obj.name, cond, (match ? "" : "not ")));
-       if(match)
-               load_sub_with(*this);
-}
-
 void Package::Loader::require(const string &n)
 {
        Package *req = obj.builder.get_package_manager().find_package(n);
index 01a43a0fb8453c0fbd1eedfae560b745717a9d7c..34049d0ce9129ec4de87a3f35a367e22c7d72cee 100644 (file)
@@ -5,6 +5,7 @@
 #include <string>
 #include <msp/datafile/objectloader.h>
 #include "buildinfo.h"
+#include "conditionalloader.h"
 #include "config.h"
 
 class Builder;
@@ -18,12 +19,11 @@ packages and the builderrc file for binary packages with no pkg-config support.
 class Package
 {
 public:
-       class Loader: public Msp::DataFile::ObjectLoader<Package>
+       class Loader: public Msp::DataFile::ObjectLoader<Package>, public ArchitectureConditional
        {
        public:
                Loader(Package &);
        private:
-               void if_arch(const std::string &);
                void require(const std::string &);
        };
 
index 942e5a3bcca4c6250a2564a6ca9aedf00a623e83..9e1b68dd43d60b4b81d61f2c65051412d7286fa6 100644 (file)
@@ -8,7 +8,6 @@
 #include "androidapplicationcomponent.h"
 #include "binarycomponent.h"
 #include "binarypackage.h"
-#include "booleanevaluator.h"
 #include "builder.h"
 #include "datapackcomponent.h"
 #include "file.h"
@@ -145,13 +144,15 @@ void SourcePackage::save_caches()
 
 
 SourcePackage::Loader::Loader(SourcePackage &p):
-       DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>(p)
+       DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>(p),
+       FeatureConditional(p, p.name)
 {
        init(0);
 }
 
 SourcePackage::Loader::Loader(SourcePackage &p, const Config::InputOptions &o):
-       DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>(p)
+       DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>(p),
+       FeatureConditional(p, p.name)
 {
        init(&o);
 }
@@ -165,7 +166,6 @@ void SourcePackage::Loader::init(const Config::InputOptions *o)
        add("description", &SourcePackage::description);
        add("feature",     &Loader::feature);
        add("generate",    &Loader::generate);
-       add("if_feature",  &Loader::if_feature);
        add("install",     &Loader::component<InstallComponent>);
        add("interface_version", &Loader::interface_version);
        add("library",     &Loader::component_arg<BinaryComponent, BinaryComponent::Type, BinaryComponent::LIBRARY>);
@@ -230,15 +230,6 @@ void SourcePackage::Loader::generate(const string &tag)
        obj.local_tools.add_tool(gen);
 }
 
-void SourcePackage::Loader::if_feature(const string &cond)
-{
-       BooleanEvaluator eval(sigc::mem_fun(&obj, &SourcePackage::match_feature));
-       bool match = eval.evaluate(cond);
-       obj.builder.get_logger().log("configure", format("%s: feature %s %smatched", obj.name, cond, (match ? "" : "not ")));
-       if(match)
-               load_sub_with(*this);
-}
-
 void SourcePackage::Loader::interface_version(const string &v)
 {
        obj.interface_version = v;
index ed8ad40f7275f9d5ac364a3f7971cf805b31b050..5a1eddde5bd1b2793cf9b8e03b90ec9544434725 100644 (file)
@@ -6,6 +6,7 @@
 #include "buildinfo.h"
 #include "cache.h"
 #include "component.h"
+#include "conditionalloader.h"
 #include "config.h"
 #include "feature.h"
 #include "package.h"
@@ -22,7 +23,7 @@ A package that can be built by Builder.
 class SourcePackage: public Package
 {
 public:
-       class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>
+       class Loader: public Msp::DataFile::DerivedObjectLoader<SourcePackage, Package::Loader>, public FeatureConditional
        {
        private:
                const Config::InputOptions *options;
@@ -40,7 +41,6 @@ public:
                void component_arg(const std::string &);
                void build_info();
                void generate(const std::string &);
-               void if_feature(const std::string &);
                void interface_version(const std::string &);
                void source_archive();
                void tarball(const std::string &);