From 64661ac00a3a7eaa2295b85be642b6c96276cf97 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 25 Sep 2013 20:06:57 +0300 Subject: [PATCH] Properly support multiple choice features --- source/buildercli.cpp | 19 +++++++++++++++---- source/feature.cpp | 17 +++++++++++++++++ source/feature.h | 6 +++++- source/sourcepackage.cpp | 11 ++++++++--- 4 files changed, 45 insertions(+), 8 deletions(-) diff --git a/source/buildercli.cpp b/source/buildercli.cpp index 7f6ee68..c0a4f06 100644 --- a/source/buildercli.cpp +++ b/source/buildercli.cpp @@ -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::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); } } } diff --git a/source/feature.cpp b/source/feature.cpp index a483482..712004f 100644 --- a/source/feature.cpp +++ b/source/feature.cpp @@ -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(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); +} diff --git a/source/feature.h b/source/feature.h index 3c13a5a..5bcaa4d 100644 --- a/source/feature.h +++ b/source/feature.h @@ -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 choices; - Feature(const std::string &n): name(n) { } + Feature(const std::string &); }; #endif diff --git a/source/sourcepackage.cpp b/source/sourcepackage.cpp index 515841d..dbb7592 100644 --- a/source/sourcepackage.cpp +++ b/source/sourcepackage.cpp @@ -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(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(value)) + build_info.defines[ident] = "1"; + } bool export_paths = false; for(list::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); -- 2.45.2