]> git.tdb.fi Git - builder.git/commitdiff
Support conditionals inside components
authorMikko Rasa <tdb@tdb.fi>
Sun, 14 Apr 2013 11:50:52 +0000 (14:50 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 14 Apr 2013 11:50:52 +0000 (14:50 +0300)
source/architecture.cpp
source/component.cpp
source/component.h
source/package.cpp
source/sourcepackage.cpp
source/sourcepackage.h

index fd31bcdbfd942a9ad05146d73e7dbb73fcecc38b..7faefeb456f3953548084782c63079fc466a59fc 100644 (file)
@@ -124,16 +124,17 @@ Architecture::Architecture(Builder &b, const string &spec):
 
 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
index d1849f4027ead3b480af4db82294537fe0d7d124..5104cdf3e92b04c8567304baae993bf974f9952c 100644 (file)
@@ -243,6 +243,8 @@ Component::SourceList Component::collect_source_files() 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);
@@ -252,6 +254,24 @@ Component::Loader::Loader(Component &c):
        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());
index 2e9e534c0ca0973d2638a8902446c926bdfe0b67..83a8baa20f124fb84849bc0f4235d5d3665c0a91 100644 (file)
@@ -24,6 +24,8 @@ public:
        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();
index 6cbc9328a43ba7a4556d28e7a55e43762256c969..05bebcc55f929971cb5d1780ba98200b6730bcca 100644 (file)
@@ -38,9 +38,7 @@ Package::Loader::Loader(Package &p):
 
 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);
index 8ad12d37c7f78ccc533e4366df613709c637902e..cb4f978aedba7c6e61c5fb4f8719e67e05f0123f 100644 (file)
@@ -67,6 +67,27 @@ FS::Path SourcePackage::get_out_dir() const
                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;
@@ -231,25 +252,7 @@ void SourcePackage::Loader::headers(const string &n)
 
 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);
index f0a58b74dc9619ed1a6fe5abfb865e61ab34d9b9..0254cb960e18e1088bf14f9a908faddd8b617c64 100644 (file)
@@ -85,6 +85,7 @@ public:
        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; }