#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"
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);
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());
#include <msp/datafile/objectloader.h>
#include <msp/fs/path.h>
#include "buildinfo.h"
+#include "conditionalloader.h"
#include "installmap.h"
#include "package.h"
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 &);
--- /dev/null
+#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)
+{ }
--- /dev/null
+#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
#include <msp/io/print.h>
#include <msp/strings/lexicalcast.h>
#include <msp/strings/utils.h>
-#include "booleanevaluator.h"
#include "builder.h"
#include "package.h"
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);
#include <string>
#include <msp/datafile/objectloader.h>
#include "buildinfo.h"
+#include "conditionalloader.h"
#include "config.h"
class Builder;
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 &);
};
#include "androidapplicationcomponent.h"
#include "binarycomponent.h"
#include "binarypackage.h"
-#include "booleanevaluator.h"
#include "builder.h"
#include "datapackcomponent.h"
#include "file.h"
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);
}
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>);
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;
#include "buildinfo.h"
#include "cache.h"
#include "component.h"
+#include "conditionalloader.h"
#include "config.h"
#include "feature.h"
#include "package.h"
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;
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 &);