bool Architecture::match_name(const string &pattern) const
{
- vector<string> parts = split(pattern, "-");
+ bool negate = (pattern[0]=='!');
+ vector<string> parts = split(pattern.substr(negate), "-");
for(vector<string>::const_iterator i=parts.begin(); i!=parts.end(); ++i)
{
string part = resolve_alias(*i);
if((part=="32" && bits==32) || (part=="64" && bits==64))
;
else if(part!=type && part!=cpu && part!=system)
- return false;
+ return negate;
}
- return true;
+ return !negate;
}
string Architecture::resolve_alias(const string &part) const
Component::Loader::Loader(Component &c):
DataFile::ObjectLoader<Component>(c)
{
+ add("if_arch", &Loader::if_arch);
+ add("if_feature", &Loader::if_feature);
add("source", &Loader::source);
add("install", &Component::install);
add("install_map", &Loader::install_map);
add("use", &Loader::use);
}
+void Component::Loader::if_arch(const string &cond)
+{
+ bool match = obj.package.get_builder().get_current_arch().match_name(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)
+{
+ bool match = obj.package.match_feature(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::source(const string &s)
{
obj.sources.push_back((obj.package.get_source_directory()/s).str());
public:
Loader(Component &);
private:
+ void if_arch(const std::string &);
+ void if_feature(const std::string &);
void source(const std::string &);
void require(const std::string &);
void build_info();
void Package::Loader::if_arch(const string &cond)
{
- const Architecture &arch = obj.builder.get_current_arch();
- bool negate = (cond[0]=='!');
- bool match = (arch.match_name(cond.substr(negate))!=negate);
+ bool match = obj.builder.get_current_arch().match_name(cond);
obj.builder.get_logger().log("configure", format("%s: arch %s %smatched", obj.name, cond, (match ? "" : "not ")));
if(match)
load_sub_with(*this);
return source_dir/arch.get_name();
}
+bool SourcePackage::match_feature(const string &cond) const
+{
+ string::size_type equals = cond.find('=');
+ if(equals!=string::npos)
+ {
+ if(equals==0)
+ throw invalid_argument("SourcePackage::match_feature");
+ bool negate = cond[equals-1]=='!';
+ string feat = cond.substr(0, equals-negate);
+ string value = config.get_option("with_"+feat).value;
+ return (value==cond.substr(equals+1))!=negate;
+ }
+ else
+ {
+ bool negate = (cond[0]=='!');
+ string feat = cond.substr(negate);
+ string value = config.get_option("with_"+feat).value;
+ return lexical_cast<bool>(value)!=negate;
+ }
+}
+
void SourcePackage::do_prepare()
{
BuildInfo final_build_info;
void SourcePackage::Loader::if_feature(const string &cond)
{
- bool match = false;
- string::size_type equals = cond.find('=');
- if(equals!=string::npos)
- {
- if(equals==0)
- throw invalid_argument("SourcePackage::Loader::if_feature");
- bool negate = cond[equals-1]=='!';
- string name = cond.substr(0, equals-negate);
- string value = obj.config.get_option("with_"+name).value;
- match = (value==cond.substr(equals+1))!=negate;
- value = cond.substr(equals+1);
- }
- else
- {
- bool negate = (cond[0]=='!');
- string name = cond.substr(negate);
- string value = obj.config.get_option("with_"+name).value;
- match = lexical_cast<bool>(value)!=negate;
- }
+ bool match = obj.match_feature(cond);
obj.builder.get_logger().log("configure", format("%s: feature %s %smatched", obj.name, cond, (match ? "" : "not ")));
if(match)
load_sub_with(*this);
Msp::FS::Path get_out_dir() const;
const ComponentList &get_components() const { return components; }
const Config &get_config() const { return config; }
+ bool match_feature(const std::string &) const;
void set_build_type(const BuildType &);
const BuildInfo &get_build_info() const { return build_info; }
Builder &get_builder() const { return builder; }