Subject: Proper way to provide an alternative to a package

From: Bart Ribbers <[email-masked]>
Date: Sun, 23 Feb 2020 16:16:46 +0100

Hey all,

In postmarketOS we sometimes have a package that's provided as an 
alternative to a different one (drop-in replacement). Our current 
example is that we have a package "mesa-git"[1] which tracks the latest 
git master of Mesa, intended to be used only on specific devices we 
support. This package is only to be used at runtime on these specific 
devices, in _every_ other case it should use the regular "mesa" package 
from the Alpine repositories.

[1] 
https://gitlab.com/postmarketOS/pmaports/-/blob/master/temp/mesa-git/APKBUILD

We've been messing for a while with the usual "provides" and "replaces", 
but we just _can't_ get it right. Previously the package got installed 
even if it was not required and explicitly instructed too but we did 
manage to prevent that with some hacks in our pmbootstrap tool. Now 
however it messes stuff up when you try to install -dev packages. For 
example I'm currently trying to compile a package locally on my device, 
and one of the -dev dependencies depends on "mesa-dev". However, since 
in this case "mesa-git-dev" is installed (which should just "provide" 
mesa-dev), it causes problems:

ERROR: unsatisfiable constraints:
   mesa-git-glapi-0_git20200202-r2:
     breaks: mesa-dev-19.3.4-r1[mesa-glapi=19.3.4-r1]
     satisfies: mesa-git-dri-gallium-0_git20200202-r2[mesa-git-glapi] 
mesa-git-dri-gallium-0_git20200202-r2[so:libglapi.so.0]
                mesa-git-gl-0_git20200202-r2[so:libglapi.so.0] 
mesa-git-gles-0_git20200202-r2[so:libglapi.so.0]
                mesa-git-egl-0_git20200202-r2[so:libglapi.so.0] 
mesa-git-osmesa-0_git20200202-r2[so:libglapi.so.0]
   mesa-git-gl-0_git20200202-r2:
     breaks: mesa-dev-19.3.4-r1[mesa-gl=19.3.4-r1]
     satisfies: mesa-git-dri-gallium-0_git20200202-r2[mesa-git-gl] 
charging-sdl-0.1-r1[mesa-gl] osk-sdl-0.54-r0[mesa-gl]
                gst-plugins-base-1.16.2-r2[so:libGL.so.1] 
xorg-server-1.20.7-r0[so:libGL.so.1] qt5-qtwayland-5.12.5-r3[so:libGL.so.1]
                qt5-qtmultimedia-5.12.5-r2[so:libGL.so.1] 
plasma-framework-5.67.0-r1[so:libGL.so.1]
                xorg-server-xwayland-1.20.7-r0[so:libGL.so.1]
   mesa-git-gles-0_git20200202-r2:
     breaks: mesa-dev-19.3.4-r1[mesa-gles=19.3.4-r1]
     satisfies: mesa-git-dri-gallium-0_git20200202-r2[mesa-git-gles] 
qt5-qtbase-x11-9999-r17[so:libGLESv2.so.2]
   mesa-git-gbm-0_git20200202-r2:
     breaks: mesa-dev-19.3.4-r1[mesa-gbm=19.3.4-r1]
     satisfies: mesa-git-dri-gallium-0_git20200202-r2[mesa-git-gbm] 
xorg-server-1.20.7-r0[so:libgbm.so.1]
                kwin-5.18.1-r1[so:libgbm.so.1] 
qt5-qtbase-x11-9999-r17[so:libgbm.so.1]
                xdg-desktop-portal-kde-5.18.1-r1[so:libgbm.so.1] 
mesa-git-egl-0_git20200202-r2[so:libgbm.so.1]
                xorg-server-xwayland-1.20.7-r0[so:libgbm.so.1]
   mesa-git-egl-0_git20200202-r2:
     breaks: mesa-dev-19.3.4-r1[mesa-egl=19.3.4-r1]
     satisfies: mesa-git-dri-gallium-0_git20200202-r2[mesa-git-egl] 
gst-plugins-base-1.16.2-r2[so:libEGL.so.1]
                qt5-qtwayland-5.12.5-r3[so:libEGL.so.1] 
qt5-qtbase-x11-9999-r17[so:libEGL.so.1]
                plasma-framework-5.67.0-r1[so:libEGL.so.1] 
kwayland-5.67.0-r1[so:libEGL.so.1]
   mesa-git-osmesa-0_git20200202-r2:
     breaks: mesa-dev-19.3.4-r1[mesa-osmesa=19.3.4-r1]
   mesa-git-xatracker-0_git20200202-r2:
     breaks: mesa-dev-19.3.4-r1[mesa-xatracker=19.3.4-r1]

Can anyone explain to me how an alternative package is to be configured 
to actually work as a drop-in replacement?

Cheers,
Bart (PureTryOut)