Based on the discussion in:
- #21288
Remove default provider priority since …packages are expected to explicitly declare virtual provides and set default variants. With default priority some package variants without `PROVIDES` and not marked as default end up with priority 0 and are not picked for installation.
Before the change without the default variant set dnsmasq-dhcpv6 is selected for dnsmasq, because the former has higher priority:
```
name <dnsmasq> selected from selectable list
select_package: dnsmasq (requirers=1, autosel=1, iif=0, order_id=0x4000005f)
consider dnsmasq-2.91-r2 iif_triggered=0, tag_ok=1, selectable=1, available=1, flags=0x0, provider_priority=0, installed=0
prefer existing package
choose as new provider
consider dnsmasq-dhcpv6-2.91-r2 iif_triggered=0, tag_ok=1, selectable=1, available=1, flags=0x0, provider_priority=1, installed=0
prefer highest declared provider priority
choose as new provider
consider dnsmasq-full-2.91-r2 iif_triggered=0, tag_ok=1, selectable=1, available=1, flags=0x0, provider_priority=1, installed=0
prefer lowest available repository
selecting: dnsmasq-dhcpv6-2.91-r2, available: 1
assign dnsmasq-dhcpv6 to dnsmasq-dhcpv6-2.91-r2
assign dnsmasq to dnsmasq-dhcpv6-2.91-r2
disqualify_package: dnsmasq-2.91-r2 (conflicting provides)
disqualify_package: dnsmasq-full-2.91-r2 (conflicting provides)
apply_constraint: libc
apply_constraint: provider: libc-1.2.5-r5: 1
```
After the change dnsmasq is selected for dnsmasq based on lexicographical order:
```
name <dnsmasq> selected from selectable list
select_package: dnsmasq (requirers=1, autosel=1, iif=0, order_id=0x4000005f)
consider dnsmasq-2.91-r2 iif_triggered=0, tag_ok=1, selectable=1, available=1, flags=0x0, provider_priority=0, installed=0
prefer existing package
choose as new provider
consider dnsmasq-dhcpv6-2.91-r2 iif_triggered=0, tag_ok=1, selectable=1, available=1, flags=0x0, provider_priority=0, installed=0
prefer lowest available repository
consider dnsmasq-full-2.91-r2 iif_triggered=0, tag_ok=1, selectable=1, available=1, flags=0x0, provider_priority=0, installed=0
prefer lowest available repository
selecting: dnsmasq-2.91-r2, available: 1
assign dnsmasq to dnsmasq-2.91-r2
disqualify_package: dnsmasq-dhcpv6-2.91-r2 (conflicting provides)
disqualify_package: dnsmasq-full-2.91-r2 (conflicting provides)
apply_constraint: libc
apply_constraint: provider: libc-1.2.5-r5: 1
```
dnsmasq is just an example and has default variant already set in #21358.
Don't mark all provides as virtual when `ALTERNATIVES` is set (recently added in #20819). Automatically marking all provides as virtual prevents variants from conflicting between each other. Alternatives have nothing to do with packaging and packages are expected to manage their own provides.
Refactor dependencies and extra dependencies logic into a helper define (introduced in #20819). The logic is the same as before.
Same as for the base package name, when a package has an ABI version, provide both unversioned provider in addition to one with ABI version and version.
So for each provide instead of providing only:
`${provide}${ABI_version}=${package_version}`
now provide:
`${provide} ${provide}${ABI_version}=${package_version}`
When a provide ends in a number, the ABI version will be prefixed with a - sign, e.g.: `provide1-0`.
Fix setting implicit self-provides for packages when they don't have any `PROVIDES` specified.
Remove redundant self-provide for kmods, since kmods are packages and will have a self-provide added already.
If a package has an ABI version defined, set priority to 10. The enables packages with an ABI version to be installed by their base name instead of a name and an ABI version, if they are the only variant which is not marked as default, e.g.:
`libfoo3`, where 3 is the ABI version can be installed by just `libfoo`.
This affects manual installation only, as the dependency resolution takes care of ABI versions.
Refactor apk priority logic into a helper define.
Due to the way apk lifecycle scripts are defined, they might end up with multiple shebangs. Remove them.
Before:
```bash
post-upgrade: |
#!/bin/sh
export PKG_UPGRADE=1
#!/bin/sh
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
[ -s ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
export root="${IPKG_INSTROOT}"
export pkgname="adblock-fast"
add_group_and_user
default_postinst
#!/bin/sh
# check if we are on real system
if [ -z "${IPKG_INSTROOT}" ]; then
/etc/init.d/adblock-fast enable
fi
exit 0
```
After:
```bash
post-upgrade: |
#!/bin/sh
export PKG_UPGRADE=1
[ "${IPKG_NO_SCRIPT}" = "1" ] && exit 0
[ -s ${IPKG_INSTROOT}/lib/functions.sh ] || exit 0
. ${IPKG_INSTROOT}/lib/functions.sh
export root="${IPKG_INSTROOT}"
export pkgname="adblock-fast"
add_group_and_user
default_postinst
# check if we are on real system
if [ -z "${IPKG_INSTROOT}" ]; then
/etc/init.d/adblock-fast enable
fi
exit 0
```
Updated internal depends and provides logic documentation.
Packages shouldn't provide a package that another package, in this case wget from packages provides. Explicitly provide a virtual `@wget-any` instead to match the implicit `wget` provide and switch the only consumer to use the new provider.
Set uclient-fetch as the default variant for wget-any.
uclient-fetch and wget are examples of packages that have versioned and virtual provides, and alternatives, where previous logic fell apart.
Drop `libelf1` provide since ABI version is added to a package name during packaging, so there's no need to specify it manually. And nothing explicitly depends on `libelf1`.
Retested depends and provides:
- ABI-versioned and non-ABI-versioned libraries
- ABI-versioned and non-ABI-versioned provides
- Virtual provides
- Kmod and package implicit provides
```bash
$ apk adbdump bin/packages/x86_64/packages/sqlite3*
depends: # 2 items
- libc
- libsqlite3-0=3.51.1-r1
$ apk adbdump bin/packages/x86_64/packages/libsqlite*
name: libsqlite3-0
version: 3.51.1-r1
...
provides: # 4 items
- libbar-any
- libfoo
- libfoo0=3.51.1-r1
```
> [!NOTE]
>
> There are still quite a few provides that need to be addressed.
Related:
- https://github.com/openwrt/packages/pull/28246
cc: @efahl