diff options
author | 2011-04-14 22:10:18 +0100 | |
---|---|---|
committer | 2011-04-14 22:10:18 +0100 | |
commit | 32b30e632c1513656b74243893e8508d0ced6b8a (patch) | |
tree | 7d4a35083028f8ccdb451ccf2c26ff6fae599f66 | |
parent | 15a7c5731bb389c53cca09d4389c34f887524ba2 (diff) | |
download | paludis-32b30e632c1513656b74243893e8508d0ced6b8a.tar.gz paludis-32b30e632c1513656b74243893e8508d0ced6b8a.tar.xz |
Do match_package via requirements()
-rw-r--r-- | paludis/match_package.cc | 240 |
1 files changed, 134 insertions, 106 deletions
diff --git a/paludis/match_package.cc b/paludis/match_package.cc index da30f295d..74d2dedd8 100644 --- a/paludis/match_package.cc +++ b/paludis/match_package.cc @@ -49,145 +49,173 @@ using namespace paludis; #include <paludis/match_package-se.cc> -bool -paludis::match_package_with_maybe_changes( - const Environment & env, - const PackageDepSpec & spec, - const ChangedChoices * const maybe_changes_to_owner, - const std::shared_ptr<const PackageID> & id, - const std::shared_ptr<const PackageID> & from_id, - const ChangedChoices * const maybe_changes_to_target, - const MatchPackageOptions & options) +namespace { - if (spec.package_name_requirement() && spec.package_name_requirement()->name() != id->name()) - return false; + struct RequirementChecker + { + const Environment & env; + const ChangedChoices * const maybe_changes_to_owner; + const std::shared_ptr<const PackageID> & id; + const std::shared_ptr<const PackageID> & from_id; + const ChangedChoices * const maybe_changes_to_target; + const MatchPackageOptions & options; + + bool version_requirements_ok; - if (spec.package_name_part_requirement() && spec.package_name_part_requirement()->name_part() != id->name().package()) - return false; + bool visit(const NameRequirement & r) + { + return r.name() == id->name(); + } - if (spec.category_name_part_requirement() && spec.category_name_part_requirement()->name_part() != id->name().category()) - return false; + bool visit(const PackageNamePartRequirement & r) + { + return r.name_part() == id->name().package(); + } - if (spec.all_version_requirements()) - { - bool ok(true); + bool visit(const CategoryNamePartRequirement & r) + { + return r.name_part() == id->name().category(); + } - for (auto r(spec.all_version_requirements()->begin()), r_end(spec.all_version_requirements()->end()) ; - r != r_end ; ++r) + bool visit(const VersionRequirement & r) { - bool one((*r)->version_operator().as_version_spec_comparator()(id->version(), (*r)->version_spec())); + bool one(r.version_operator().as_version_spec_comparator()(id->version(), r.version_spec())); - switch ((*r)->combiner()) + switch (r.combiner()) { - case vrc_and: ok &= one; break; - case vrc_or: ok |= one; break; + case vrc_and: version_requirements_ok &= one; break; + case vrc_or: version_requirements_ok |= one; break; case last_vrc: throw InternalError(PALUDIS_HERE, "Bad vrc"); } + + return true; } - if (! ok) - return false; - } + bool visit(const InRepositoryRequirement & r) + { + return r.name() == id->repository_name(); + } - if (spec.in_repository_requirement()) - if (spec.in_repository_requirement()->name() != id->repository_name()) - return false; + bool visit(const FromRepositoryRequirement & r) + { + if (! id->from_repositories_key()) + return false; - if (spec.from_repository_requirement()) - { - if (! id->from_repositories_key()) - return false; + auto v(id->from_repositories_key()->parse_value()); + return v->end() != v->find(stringify(r.name())); + } - auto v(id->from_repositories_key()->parse_value()); - if (v->end() == v->find(stringify(spec.from_repository_requirement()->name()))) - return false; - } + bool visit(const InstalledAtPathRequirement & r) + { + auto repo(env.fetch_repository(id->repository_name())); + if (! repo->installed_root_key()) + return false; + if (repo->installed_root_key()->parse_value() != r.path()) + return false; + return true; + } - if (spec.installed_at_path_requirement()) - { - auto repo(env.fetch_repository(id->repository_name())); - if (! repo->installed_root_key()) - return false; - if (repo->installed_root_key()->parse_value() != spec.installed_at_path_requirement()->path()) - return false; - } + bool visit(const InstallableToRepositoryRequirement & r) + { + if (! id->supports_action(SupportsActionTest<InstallAction>())) + return false; + if (! r.include_masked()) + if (id->masked()) + return false; - if (spec.installable_to_repository_requirement()) - { - if (! id->supports_action(SupportsActionTest<InstallAction>())) - return false; - if (! spec.installable_to_repository_requirement()->include_masked()) - if (id->masked()) + const std::shared_ptr<const Repository> dest(env.fetch_repository(r.name())); + if (! dest->destination_interface()) + return false; + if (! dest->destination_interface()->is_suitable_destination_for(id)) return false; - const std::shared_ptr<const Repository> dest(env.fetch_repository( - spec.installable_to_repository_requirement()->name())); - if (! dest->destination_interface()) - return false; - if (! dest->destination_interface()->is_suitable_destination_for(id)) - return false; - } + return true; + } + + bool visit(const InstallableToPathRequirement & r) + { + if (! id->supports_action(SupportsActionTest<InstallAction>())) + return false; + if (! r.include_masked()) + if (id->masked()) + return false; + + bool ok(false); + for (auto d(env.begin_repositories()), d_end(env.end_repositories()) ; + d != d_end ; ++d) + { + if (! (*d)->destination_interface()) + continue; + if (! (*d)->installed_root_key()) + continue; + if ((*d)->installed_root_key()->parse_value() != r.path()) + continue; + if (! (*d)->destination_interface()->is_suitable_destination_for(id)) + continue; + + ok = true; + break; + } + + if (! ok) + return false; - if (spec.installable_to_path_requirement()) - { - if (! id->supports_action(SupportsActionTest<InstallAction>())) return false; - if (! spec.installable_to_path_requirement()->include_masked()) - if (id->masked()) + } + + bool visit(const ExactSlotRequirement & r) + { + if ((! id->slot_key()) || (id->slot_key()->parse_value() != r.name())) return false; - bool ok(false); - for (auto d(env.begin_repositories()), d_end(env.end_repositories()) ; - d != d_end ; ++d) + return true; + } + + bool visit(const AnySlotRequirement &) { - if (! (*d)->destination_interface()) - continue; - if (! (*d)->installed_root_key()) - continue; - if ((*d)->installed_root_key()->parse_value() != spec.installable_to_path_requirement()->path()) - continue; - if (! (*d)->destination_interface()->is_suitable_destination_for(id)) - continue; - - ok = true; - break; + /* don't care */ + return true; } - if (! ok) - return false; - } + bool visit(const ChoiceRequirement & r) + { + if (options[mpo_ignore_choice_requirements]) + return true; - if (spec.exact_slot_requirement()) - { - if ((! id->slot_key()) || (id->slot_key()->parse_value() != spec.exact_slot_requirement()->name())) - return false; - } + if (! r.requirement_met(&env, maybe_changes_to_owner, id, from_id, maybe_changes_to_target).first) + return false; - if (spec.any_slot_requirement()) - { - /* don't care */ - } + return true; + } - if (! options[mpo_ignore_choice_requirements]) - { - if (spec.all_choice_requirements()) + bool visit(const KeyRequirement & r) { - for (auto u(spec.all_choice_requirements()->begin()), u_end(spec.all_choice_requirements()->end()) ; - u != u_end ; ++u) - if (! (*u)->requirement_met(&env, maybe_changes_to_owner, id, from_id, maybe_changes_to_target).first) - return false; + if (! r.matches(&env, id)) + return false; + + return true; } - } + }; +} - if (spec.all_key_requirements()) - { - for (auto c(spec.all_key_requirements()->begin()), c_end(spec.all_key_requirements()->end()) ; - c != c_end ; ++c) - if (! (*c)->matches(&env, id)) - return false; - } +bool +paludis::match_package_with_maybe_changes( + const Environment & env, + const PackageDepSpec & spec, + const ChangedChoices * const maybe_changes_to_owner, + const std::shared_ptr<const PackageID> & id, + const std::shared_ptr<const PackageID> & from_id, + const ChangedChoices * const maybe_changes_to_target, + const MatchPackageOptions & options) +{ + RequirementChecker c{env, maybe_changes_to_owner, id, from_id, maybe_changes_to_target, options, true}; + + for (auto r(spec.requirements()->begin()), r_end(spec.requirements()->end()) ; + r != r_end ; ++r) + if (! (*r)->accept_returning<bool>(c)) + return false; - return true; + return c.version_requirements_ok; } bool |