]> git.tdb.fi Git - builder.git/commitdiff
Properly support multiple choice features
authorMikko Rasa <tdb@tdb.fi>
Wed, 25 Sep 2013 17:06:57 +0000 (20:06 +0300)
committerMikko Rasa <tdb@tdb.fi>
Wed, 25 Sep 2013 17:06:57 +0000 (20:06 +0300)
source/buildercli.cpp
source/feature.cpp
source/feature.h
source/sourcepackage.cpp

index 7f6ee687728fbaeecc7ef526d0fb16bdb0b84f41..c0a4f06c8f10c1b692b39c7a79798cf361a362e6 100644 (file)
@@ -354,10 +354,21 @@ void BuilderCLI::package_help()
                for(Config::OptionMap::const_iterator i=options.begin(); i!=options.end(); ++i)
                {
                        const Config::Option &opt = i->second;
-                       IO::print("  %s: %s (%s)", opt.name, opt.description, opt.value);
-                       if(opt.value!=opt.default_value)
-                               IO::print(" [%s]", opt.default_value);
-                       IO::print("\n");
+                       string line = format("  %s: %s (%s)", opt.name, opt.description, opt.value);
+                       if(!opt.choices.empty())
+                       {
+                               line += " {";
+                               for(list<string>::const_iterator j=opt.choices.begin(); j!=opt.choices.end(); ++j)
+                               {
+                                       if(j!=opt.choices.begin())
+                                               line += ' ';
+                                       line += *j;
+                               }
+                               line += '}';
+                       }
+                       else if(opt.value!=opt.default_value)
+                               line += format(" [%s]", opt.default_value);
+                       IO::print("%s\n", line);
                }
        }
 }
index a483482c55e0a330c36a188a534f037d74fc08bf..712004fc6125a9b5f3fb616b6464bb91d70d80c1 100644 (file)
@@ -1,8 +1,25 @@
 #include "feature.h"
 
+using namespace std;
+using namespace Msp;
+
+Feature::Feature(const string &n):
+       name(n),
+       default_value("no")
+{ }
+
+
 Feature::Loader::Loader(Feature &f):
        Msp::DataFile::ObjectLoader<Feature>(f)
 {
+       add("choice",      &Loader::choice);
        add("description", &Feature::description);
        add("default",     &Feature::default_value);
 }
+
+void Feature::Loader::choice(const string &c)
+{
+       if(obj.choices.empty())
+               obj.default_value = c;
+       obj.choices.push_back(c);
+}
index 3c13a5a01c5fdb3990a9d81eb85b623e25f2686c..5bcaa4df53a3be6a91d538883c1a51701786e85c 100644 (file)
@@ -9,13 +9,17 @@ struct Feature
        {
        public:
                Loader(Feature &);
+
+       private:
+               void choice(const std::string &);
        };
 
        std::string name;
        std::string description;
        std::string default_value;
+       std::list<std::string> choices;
 
-       Feature(const std::string &n): name(n) { }
+       Feature(const std::string &);
 };
 
 #endif
index 515841dd2ee7f5257851c6af5d9ca00305d3a749..dbb759205fe0eef45f3b0b1ded50cfe5ba80a077 100644 (file)
@@ -103,8 +103,14 @@ void SourcePackage::do_prepare()
        build_info.libpath.push_back((builder.get_prefix()/"lib").str());
 
        for(FeatureList::iterator i=features.begin(); i!=features.end(); ++i)
-               if(lexical_cast<bool>(config.get_option("with_"+i->name).value))
-                       build_info.defines["WITH_"+toupper(i->name)] = "1";
+       {
+               string ident = "WITH_"+toupper(i->name);
+               string value = config.get_option("with_"+i->name).value;
+               if(!i->choices.empty())
+                       build_info.defines[ident] = value;
+               else if(lexical_cast<bool>(value))
+                       build_info.defines[ident] = "1";
+       }
 
        bool export_paths = false;
        for(list<Component>::iterator i=components.begin(); i!=components.end(); ++i)
@@ -189,7 +195,6 @@ void SourcePackage::Loader::feature(const string &n, const string &d)
 {
        Feature feat(n);
        feat.description = d;
-       feat.default_value = "no";
        load_sub(feat);
        obj.features.push_back(feat);