Allow installing Alpine's mesa for x86* arches (!1768)
When a pmaport can not be built for the desired architecture, fall back to the binary package (from postmarketOS or Alpine) if it exists. This allows us to provide an updated version of mesa for arm arches, but using Alpine's mesa package on x86* arches.
This commit is contained in:
parent
c90521a888
commit
d106063fbb
|
@ -69,14 +69,31 @@ def get_apkbuild(args, pkgname, arch):
|
|||
" could not find this package in any APKINDEX!")
|
||||
|
||||
|
||||
def check_arch_abort(args, pkgname, arch):
|
||||
def check_build_for_arch(args, pkgname, arch):
|
||||
"""
|
||||
Check if the APKBUILD can be built for a specific architecture and abort
|
||||
with a helpful message if it is not the case.
|
||||
Check if pmaport can be built or exists as binary for a specific arch.
|
||||
:returns: * True when it can be built
|
||||
* False when it can't be built, but exists in a binary repo
|
||||
(e.g. temp/mesa can't be built for x86_64, but Alpine has it)
|
||||
:raises: RuntimeError if the package can't be built for the given arch and
|
||||
does not exist as binary package.
|
||||
"""
|
||||
# Check for pmaport with arch
|
||||
if pmb.helpers.package.check_arch(args, pkgname, arch, False):
|
||||
return
|
||||
return True
|
||||
|
||||
# Check for binary package
|
||||
binary = pmb.parse.apkindex.package(args, pkgname, arch, False)
|
||||
if binary:
|
||||
pmaport = pmb.helpers.pmaports.get(args, pkgname)
|
||||
pmaport_version = pmaport["pkgver"] + "-r" + pmaport["pkgrel"]
|
||||
logging.debug(pkgname + ": found pmaport (" + pmaport_version + ") and"
|
||||
" binary package (" + binary["version"] + ", from"
|
||||
" postmarketOS or Alpine), but pmaport can't be built"
|
||||
" for " + arch + " -> using binary package")
|
||||
return False
|
||||
|
||||
# No binary package exists and can't build it
|
||||
logging.info("NOTE: You can edit the 'arch=' line inside the APKBUILD")
|
||||
if args.action == "build":
|
||||
logging.info("NOTE: Alternatively, use --arch to build for another"
|
||||
|
@ -435,7 +452,8 @@ def package(args, pkgname, arch=None, force=False, strict=False,
|
|||
return
|
||||
|
||||
# Detect the build environment (skip unnecessary builds)
|
||||
check_arch_abort(args, pkgname, arch)
|
||||
if not check_build_for_arch(args, pkgname, arch):
|
||||
return
|
||||
suffix = pmb.build.autodetect.suffix(args, apkbuild, arch)
|
||||
cross = pmb.build.autodetect.crosscompile(args, apkbuild, arch, suffix)
|
||||
if not init_buildenv(args, apkbuild, arch, strict, force, cross, suffix,
|
||||
|
|
|
@ -102,7 +102,7 @@ def test_get_apkbuild(args):
|
|||
assert "Could not find" in str(e.value)
|
||||
|
||||
|
||||
def test_check_arch_abort(monkeypatch, args):
|
||||
def test_check_build_for_arch(monkeypatch, args):
|
||||
# Fake APKBUILD data
|
||||
apkbuild = {"pkgname": "testpkgname"}
|
||||
|
||||
|
@ -110,21 +110,28 @@ def test_check_arch_abort(monkeypatch, args):
|
|||
return apkbuild
|
||||
monkeypatch.setattr(pmb.helpers.pmaports, "get", fake_helpers_pmaports_get)
|
||||
|
||||
# Arch is right
|
||||
func = pmb.build._package.check_arch_abort
|
||||
# pmaport with arch exists
|
||||
func = pmb.build._package.check_build_for_arch
|
||||
apkbuild["arch"] = ["armhf"]
|
||||
func(args, "testpkgname", "armhf")
|
||||
assert func(args, "testpkgname", "armhf") is True
|
||||
apkbuild["arch"] = ["noarch"]
|
||||
func(args, "testpkgname", "armhf")
|
||||
assert func(args, "testpkgname", "armhf") is True
|
||||
apkbuild["arch"] = ["all"]
|
||||
func(args, "testpkgname", "armhf")
|
||||
assert func(args, "testpkgname", "armhf") is True
|
||||
|
||||
# Arch is wrong
|
||||
# No binary package exists and can't build it
|
||||
apkbuild["arch"] = ["x86_64"]
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
func(args, "testpkgname", "armhf")
|
||||
assert "Can't build" in str(e.value)
|
||||
|
||||
# pmaport can't be built for x86_64, but binary package exists in Alpine
|
||||
apkbuild = {"pkgname": "mesa",
|
||||
"arch": "armhf",
|
||||
"pkgver": "9999",
|
||||
"pkgrel": "0"}
|
||||
assert func(args, "mesa", "x86_64") is False
|
||||
|
||||
|
||||
def test_get_depends(monkeypatch):
|
||||
func = pmb.build._package.get_depends
|
||||
|
|
Loading…
Reference in New Issue