]> git.tdb.fi Git - builder.git/blobdiff - source/sourcepackage.cpp
Support conditionals inside components
[builder.git] / source / sourcepackage.cpp
index 6eaba739586881eac93f183eeb66ad49ce13c00a..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;
@@ -116,7 +137,7 @@ void SourcePackage::do_prepare()
        if(pc_needed)
        {
                PkgConfigFile *pc = new PkgConfigFile(builder, *this);
-               builder.get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc));
+               builder.get_build_graph().get_target("install")->add_dependency(*builder.get_toolchain().get_tool("CP").create_target(*pc));
        }
 }
 
@@ -142,7 +163,6 @@ SourcePackage::Loader::Loader(SourcePackage &p, const Config::InputOptions &o):
 void SourcePackage::Loader::init(const Config::InputOptions *o)
 {
        options = o;
-       add("version",     &SourcePackage::version);
        add("description", &SourcePackage::description);
        add("build_info",  &Loader::build_info);
        add("feature",     &Loader::feature);
@@ -153,10 +173,12 @@ void SourcePackage::Loader::init(const Config::InputOptions *o)
        add("module",      &Loader::component<Component::MODULE>);
        add("headers",     &Loader::headers);
        add("install",     &Loader::component<Component::INSTALL>);
+       add("interface_version", &Loader::interface_version);
        add("datafile",    &Loader::component<Component::DATAFILE>);
        add("source_tarball", &Loader::source_tarball);
        add("tarball",     &Loader::tarball);
        add("tar_file",    &Loader::tar_file);
+       add("version",     &Loader::version);
 }
 
 void SourcePackage::Loader::finish()
@@ -230,30 +252,19 @@ 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)
-                       error("No feature name specified");
-               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);
 }
 
+void SourcePackage::Loader::interface_version(const string &v)
+{
+       obj.interface_version = v;
+       if(obj.version.empty())
+               obj.version = v;
+}
+
 void SourcePackage::Loader::source_tarball()
 {
        load_sub(*obj.source_tarball);
@@ -280,3 +291,14 @@ void SourcePackage::Loader::tar_file(const string &f)
                if(i->get_type()==Component::TARBALL && i->get_name()=="@src")
                        const_cast<Component::SourceList &>(i->get_sources()).push_back((obj.source_dir/f).str());
 }
+
+void SourcePackage::Loader::version(const string &v)
+{
+       obj.version = v;
+
+       string::size_type i = 0;
+       for(unsigned dots=0; i<obj.version.size(); ++i)
+               if(obj.version[i]=='.' && ++dots>=2)
+                       break;
+       obj.interface_version = obj.version.substr(0, i);
+}