From e3407687a61bce56912b89818a9d9f006e9da41f Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 15 Oct 2014 21:23:22 +0300 Subject: [PATCH] Move conditionals into helper classes --- source/component.cpp | 26 ++------------------ source/component.h | 5 ++-- source/conditionalloader.cpp | 47 ++++++++++++++++++++++++++++++++++++ source/conditionalloader.h | 43 +++++++++++++++++++++++++++++++++ source/package.cpp | 14 ++--------- source/package.h | 4 +-- source/sourcepackage.cpp | 17 +++---------- source/sourcepackage.h | 4 +-- 8 files changed, 104 insertions(+), 56 deletions(-) create mode 100644 source/conditionalloader.cpp create mode 100644 source/conditionalloader.h diff --git a/source/component.cpp b/source/component.cpp index a42b81c..2bfa736 100644 --- a/source/component.cpp +++ b/source/component.cpp @@ -4,7 +4,6 @@ #include #include #include -#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(c) + DataFile::ObjectLoader(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()); diff --git a/source/component.h b/source/component.h index 1fbe3de..0e1efad 100644 --- a/source/component.h +++ b/source/component.h @@ -5,6 +5,7 @@ #include #include #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 + class Loader: public Msp::DataFile::ObjectLoader, 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 index 0000000..43e613b --- /dev/null +++ b/source/conditionalloader.cpp @@ -0,0 +1,47 @@ +#include +#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 index 0000000..5184fac --- /dev/null +++ b/source/conditionalloader.h @@ -0,0 +1,43 @@ +#ifndef CONDITIONALLOADER_H_ +#define CONDITIONALLOADER_H_ + +#include +#include + +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 diff --git a/source/package.cpp b/source/package.cpp index 5f25f1a..64cec87 100644 --- a/source/package.cpp +++ b/source/package.cpp @@ -1,7 +1,6 @@ #include #include #include -#include "booleanevaluator.h" #include "builder.h" #include "package.h" @@ -32,22 +31,13 @@ void Package::prepare() Package::Loader::Loader(Package &p): - DataFile::ObjectLoader(p) + DataFile::ObjectLoader(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); diff --git a/source/package.h b/source/package.h index 01a43a0..34049d0 100644 --- a/source/package.h +++ b/source/package.h @@ -5,6 +5,7 @@ #include #include #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 + class Loader: public Msp::DataFile::ObjectLoader, public ArchitectureConditional { public: Loader(Package &); private: - void if_arch(const std::string &); void require(const std::string &); }; diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 942e5a3..9e1b68d 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -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(p) + DataFile::DerivedObjectLoader(p), + FeatureConditional(p, p.name) { init(0); } SourcePackage::Loader::Loader(SourcePackage &p, const Config::InputOptions &o): - DataFile::DerivedObjectLoader(p) + DataFile::DerivedObjectLoader(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); add("interface_version", &Loader::interface_version); add("library", &Loader::component_arg); @@ -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; diff --git a/source/sourcepackage.h b/source/sourcepackage.h index ed8ad40..5a1eddd 100644 --- a/source/sourcepackage.h +++ b/source/sourcepackage.h @@ -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 + class Loader: public Msp::DataFile::DerivedObjectLoader, 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 &); -- 2.45.2