diff options
author | 2011-02-21 19:54:57 +0000 | |
---|---|---|
committer | 2011-02-26 15:25:00 +0000 | |
commit | d465cb3a77b010a7c0ab791e69012143ad5405b7 (patch) | |
tree | 7b64a6d88356296a19219f89789d28322fe3a419 /paludis/environments/paludis | |
parent | 393adbc779c4bf332e9bb966a14f73fea002ae41 (diff) | |
download | paludis-d465cb3a77b010a7c0ab791e69012143ad5405b7.tar.gz paludis-d465cb3a77b010a7c0ab791e69012143ad5405b7.tar.xz |
Allow unmasking by token kind in Paludis configs
Diffstat (limited to 'paludis/environments/paludis')
-rw-r--r-- | paludis/environments/paludis/package_mask_conf.cc | 83 | ||||
-rw-r--r-- | paludis/environments/paludis/package_mask_conf.hh | 2 | ||||
-rw-r--r-- | paludis/environments/paludis/paludis_config.cc | 4 |
3 files changed, 64 insertions, 25 deletions
diff --git a/paludis/environments/paludis/package_mask_conf.cc b/paludis/environments/paludis/package_mask_conf.cc index 5287fc7e1..91cd7dbf1 100644 --- a/paludis/environments/paludis/package_mask_conf.cc +++ b/paludis/environments/paludis/package_mask_conf.cc @@ -37,14 +37,16 @@ #include <paludis/util/mutex.hh> #include <paludis/util/hashes.hh> #include <paludis/util/make_null_shared_ptr.hh> +#include <vector> #include <list> +#include <set> #include <algorithm> #include <functional> using namespace paludis; using namespace paludis::paludis_environment; -typedef std::list<std::pair<SetName, std::shared_ptr<const SetSpecTree> > > Sets; +typedef std::list<std::pair<SetName, std::pair<std::shared_ptr<const SetSpecTree>, std::set<std::string> > > > Sets; namespace paludis { @@ -52,19 +54,21 @@ namespace paludis struct Imp<PackageMaskConf> { const PaludisEnvironment * const env; - std::list<std::shared_ptr<const PackageDepSpec> > masks; + const bool allow_reasons; + std::list<std::pair<std::shared_ptr<const PackageDepSpec>, std::set<std::string> > > masks; mutable Sets sets; mutable Mutex set_mutex; - Imp(const PaludisEnvironment * const e) : - env(e) + Imp(const PaludisEnvironment * const e, const bool a) : + env(e), + allow_reasons(a) { } }; } -PackageMaskConf::PackageMaskConf(const PaludisEnvironment * const e) : - _imp(e) +PackageMaskConf::PackageMaskConf(const PaludisEnvironment * const e, const bool a) : + _imp(e, a) { } @@ -84,28 +88,52 @@ PackageMaskConf::add(const FSPath & filename) for (LineConfigFile::ConstIterator line(f->begin()), line_end(f->end()) ; line != line_end ; ++line) { + std::vector<std::string> tokens; + tokenise_whitespace(*line, std::back_inserter(tokens)); + + if (tokens.empty()) + continue; + + std::string spec(tokens.at(0)); + tokens.erase(tokens.begin(), tokens.begin() + 1); + + std::set<std::string> reasons(tokens.begin(), tokens.end()); + if ((! reasons.empty()) && (! _imp->allow_reasons)) + throw ConfigurationError("Only one token per line is allowed in '" + stringify(filename) + "'"); + try { - _imp->masks.push_back(std::shared_ptr<PackageDepSpec>(std::make_shared<PackageDepSpec>(parse_user_package_dep_spec( - *line, _imp->env, - { updso_allow_wildcards, updso_no_disambiguation, updso_throw_if_set })))); + _imp->masks.push_back(std::make_pair(std::shared_ptr<PackageDepSpec>(std::make_shared<PackageDepSpec>(parse_user_package_dep_spec( + spec, _imp->env, + { updso_allow_wildcards, updso_no_disambiguation, updso_throw_if_set }))), reasons)); } catch (const GotASetNotAPackageDepSpec &) { - _imp->sets.push_back(std::make_pair(SetName(*line), make_null_shared_ptr())); + _imp->sets.push_back(std::make_pair(SetName(*line), std::make_pair(make_null_shared_ptr(), reasons))); } } } bool -PackageMaskConf::query(const std::shared_ptr<const PackageID> & e, const std::string &) const +PackageMaskConf::query(const std::shared_ptr<const PackageID> & e, const std::string & r) const { using namespace std::placeholders; - if (indirect_iterator(_imp->masks.end()) != std::find_if( - indirect_iterator(_imp->masks.begin()), - indirect_iterator(_imp->masks.end()), - std::bind(&match_package, std::ref(*_imp->env), _1, std::cref(e), make_null_shared_ptr(), MatchPackageOptions()))) - return true; + + for (auto i(_imp->masks.begin()), i_end(_imp->masks.end()) ; + i != i_end ; ++i) + if (match_package(*_imp->env, *i->first, e, make_null_shared_ptr(), MatchPackageOptions())) + { + if (r.empty()) + { + if (i->second.empty()) + return true; + } + else + { + if (i->second.empty() || (i->second.end() != i->second.find(r))) + return true; + } + } { Lock lock(_imp->set_mutex); @@ -113,19 +141,30 @@ PackageMaskConf::query(const std::shared_ptr<const PackageID> & e, const std::st for (Sets::iterator it(_imp->sets.begin()), it_end(_imp->sets.end()); it_end != it; ++it) { - if (! it->second) + if (! it->second.first) { - it->second = _imp->env->set(it->first); - if (! it->second) + it->second.first = _imp->env->set(it->first); + if (! it->second.first) { Log::get_instance()->message("paludis_environment.package_mask.unknown_set", ll_warning, lc_no_context) << "Set name '" << it->first << "' does not exist"; - it->second = std::make_shared<SetSpecTree>(std::make_shared<AllDepSpec>()); + it->second.first = std::make_shared<SetSpecTree>(std::make_shared<AllDepSpec>()); } } - if (match_package_in_set(*_imp->env, *it->second, e, { })) - return true; + if (match_package_in_set(*_imp->env, *it->second.first, e, { })) + { + if (r.empty()) + { + if (it->second.second.empty()) + return true; + } + else + { + if (it->second.second.empty() || (it->second.second.end() != it->second.second.find(r))) + return true; + } + } } } diff --git a/paludis/environments/paludis/package_mask_conf.hh b/paludis/environments/paludis/package_mask_conf.hh index cb927d073..931161386 100644 --- a/paludis/environments/paludis/package_mask_conf.hh +++ b/paludis/environments/paludis/package_mask_conf.hh @@ -47,7 +47,7 @@ namespace paludis ///\name Basic operations ///\{ - PackageMaskConf(const PaludisEnvironment * const); + PackageMaskConf(const PaludisEnvironment * const, const bool allow_reasons); ~PackageMaskConf(); PackageMaskConf(const PackageMaskConf &) = delete; diff --git a/paludis/environments/paludis/paludis_config.cc b/paludis/environments/paludis/paludis_config.cc index d69ff6ed6..1376648bb 100644 --- a/paludis/environments/paludis/paludis_config.cc +++ b/paludis/environments/paludis/paludis_config.cc @@ -218,8 +218,8 @@ namespace paludis keywords_conf(std::make_shared<KeywordsConf>(e)), use_conf(std::make_shared<UseConf>(e)), licenses_conf(std::make_shared<LicensesConf>(e)), - package_mask_conf(std::make_shared<PackageMaskConf>(e)), - package_unmask_conf(std::make_shared<PackageMaskConf>(e)), + package_mask_conf(std::make_shared<PackageMaskConf>(e, false)), + package_unmask_conf(std::make_shared<PackageMaskConf>(e, true)), mirrors_conf(std::make_shared<MirrorsConf>(e)), output_conf(std::make_shared<OutputConf>(e)), suggestions_conf(std::make_shared<SuggestionsConf>(e)), |