diff options
author | William Pitcock <nenolod@dereferenced.org> | 2017-11-02 02:55:17 +0000 |
---|---|---|
committer | William Pitcock <nenolod@dereferenced.org> | 2017-11-02 03:08:24 +0000 |
commit | f18c708183ac735d1787ff5b450d36f6596a10b9 (patch) | |
tree | 2a8cbb76760ae075b675f15a751d207059a20b56 /src/solver.c | |
parent | ee3740fcc681b8585b3d8d363453585cae4257aa (diff) | |
download | apk-tools-f18c708183ac735d1787ff5b450d36f6596a10b9.tar.gz apk-tools-f18c708183ac735d1787ff5b450d36f6596a10b9.tar.bz2 apk-tools-f18c708183ac735d1787ff5b450d36f6596a10b9.tar.xz apk-tools-f18c708183ac735d1787ff5b450d36f6596a10b9.zip |
solver: implement support for choosing default virtuals
By introducing a new package metadata field, `provider_priority`
(index letter `k`), we can specify default packages to satisfy a
virtual.
If a user wishes to select an alternative provider for the virtual,
a changeset swapping the default provider for the selected provider
will be generated by the dependency resolver.
Diffstat (limited to 'src/solver.c')
-rw-r--r-- | src/solver.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/solver.c b/src/solver.c index 1db8a69..11ccfc9 100644 --- a/src/solver.c +++ b/src/solver.c @@ -299,6 +299,10 @@ static void apply_constraint(struct apk_solver_state *ss, struct apk_package *pp if (is_provided) inherit_pinning_and_flags(ss, pkg0, ppkg); + + /* if a world-dependency is non-virtual, then the provider is going to be selected */ + if (ppkg == NULL && dep->name == pkg0->name && pkg0->ss.pkg_selectable) + pkg0->ss.pkg_selected = 1; } } @@ -587,6 +591,16 @@ static int compare_providers(struct apk_solver_state *ss, if (r) return r; + /* Prefer already selected package. */ + r = pkgA->ss.pkg_selected - pkgB->ss.pkg_selected; + if (r) + return r; + + /* Prefer highest declared provider priority. */ + r = pkgA->provider_priority - pkgB->provider_priority; + if (r) + return r; + /* Prefer lowest available repository */ return ffs(pkgB->repos) - ffs(pkgA->repos); } @@ -639,18 +653,14 @@ static void select_package(struct apk_solver_state *ss, struct apk_name *name) if (name->ss.requirers || name->ss.has_iif) { foreach_array_item(p, name->providers) { - dbg_printf(" consider "PKG_VER_FMT" iif_triggered=%d, tag_ok=%d, selectable=%d\n", - PKG_VER_PRINTF(p->pkg), p->pkg->ss.iif_triggered, p->pkg->ss.tag_ok, p->pkg->ss.pkg_selectable); + dbg_printf(" consider "PKG_VER_FMT" iif_triggered=%d, tag_ok=%d, selectable=%d, selected=%d, provider_priority=%d\n", + PKG_VER_PRINTF(p->pkg), p->pkg->ss.iif_triggered, p->pkg->ss.tag_ok, p->pkg->ss.pkg_selectable, + p->pkg->ss.pkg_selected, p->pkg->provider_priority); /* Ensure valid pinning and install-if trigger */ if (name->ss.requirers == 0 && (!p->pkg->ss.iif_triggered || !p->pkg->ss.tag_ok)) continue; - /* Virtual packages cannot be autoselected */ - if (p->version == &apk_null_blob && - p->pkg->name->auto_select_virtual == 0 && - p->pkg->name->ss.requirers == 0) - continue; if (compare_providers(ss, p, &chosen) > 0) chosen = *p; } |