Index parser: support multiple package providers (#1202)

* The APKINDEX parser used to return a dictionary with one package for
  a given package name. This works for the installed packages database,
  because there can only be one provider for a package. But when
  parsing packages from binary repositories, we need to support
  multiple providers for one package. It is now possible to get a
  dictionary with either multiple providers, or just a single provider
  for each package.
* Dependency parsing logic has been adjusted, to support multiple
  providers. For multiple providers, the one with the same package
  name as the package we are looking up is prefered. If there is none
  (eg. "so:libEGL.so.1" is provided by "mesa-egl"), it prefers packages
  that will be installed anyway, and after that packages that are
  already installed. When all else fails, it just picks the first one
  and prints a note in the "pmbootstrap log".
* Added testcases for all functions in pmb.parse.apkindex and
  pmb.parse.depends
* pmbootstrap chroot has a new "--add" parameter to specify packages
  that pmbootstrap should build if neccessary, and install in the
  chroot. This can be used to quickly test the depencency resolution
  of pmbootstrap without doing a full "pmbootstrap install".

Fixes #1122.
This commit is contained in:
Oliver Smith 2018-02-20 19:52:28 +00:00 committed by GitHub
parent 481c99f50c
commit db5e69630e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
22 changed files with 850 additions and 231 deletions

View file

@ -20,37 +20,119 @@ import logging
import pmb.chroot
import pmb.chroot.apk
import pmb.parse.apkindex
import pmb.parse.arch
def recurse_error_message(pkgname, in_aports, in_apkindexes):
ret = "Could not find package '" + pkgname + "'"
if in_aports:
ret += " in the aports folder"
if in_apkindexes:
ret += " and could not find it"
if in_apkindexes:
ret += " in any APKINDEX"
return ret + "."
def package_from_aports(args, pkgname_depend):
"""
:returns: None when there is no aport, or a dict with the keys pkgname,
depends, version. The version is the combined pkgver and pkgrel.
"""
# Get the aport
aport = pmb.build.find_aport(args, pkgname_depend, False)
if not aport:
return None
# Parse its version
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
pkgname = apkbuild["pkgname"]
version = apkbuild["pkgver"] + "-r" + apkbuild["pkgrel"]
# Return the dict
logging.verbose(pkgname_depend + ": provided by: " + pkgname + "-" +
version + " in " + aport)
return {"pkgname": pkgname,
"depends": apkbuild["depends"],
"version": version}
def recurse(args, pkgnames, arch=None, in_apkindexes=True, in_aports=True,
strict=False):
def package_provider(args, pkgname, pkgnames_install, suffix="native"):
"""
:param pkgnames_install: packages to be installed
:returns: a block from the apkindex: {"pkgname": "...", ...}
or None (no provider found)
"""
# Get all providers
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
providers = pmb.parse.apkindex.providers(args, pkgname, arch, False)
# 0. No provider
if len(providers) == 0:
return None
# 1. Only one provider
logging.verbose(pkgname + ": provided by: " + ", ".join(providers))
if len(providers) == 1:
return list(providers.values())[0]
# 2. Provider with the same package name
if pkgname in providers:
logging.verbose(pkgname + ": choosing package of the same name as"
" provider")
return providers[pkgname]
# 3. Pick a package that will be installed anyway
for provider_pkgname, provider in providers.items():
if provider_pkgname in pkgnames_install:
logging.verbose(pkgname + ": choosing provider '" +
provider_pkgname + "', because it will be"
" installed anyway")
return provider
# 4. Pick a package that is already installed
installed = pmb.chroot.apk.installed(args, suffix)
for provider_pkgname, provider in providers.items():
if provider_pkgname in installed:
logging.verbose(pkgname + ": choosing provider '" +
provider_pkgname + "', because it is installed in"
" the '" + suffix + "' chroot already")
return provider
# 5. Pick the first one
provider_pkgname = list(providers.keys())[0]
logging.debug(pkgname + " has multiple providers (" +
", ".join(providers) + "), picked: " + provider_pkgname)
return providers[provider_pkgname]
def package_from_index(args, pkgname_depend, pkgnames_install, package_aport,
suffix="native"):
"""
:returns: None when there is no aport and no binary package, or a dict with
the keys pkgname, depends, version from either the aport or the
binary package provider.
"""
# No binary package
provider = package_provider(args, pkgname_depend, pkgnames_install, suffix)
if not provider:
return package_aport
# Binary package outdated
if (package_aport and pmb.parse.version.compare(package_aport["version"],
provider["version"]) == 1):
logging.verbose(pkgname_depend + ": binary package is outdated")
return package_aport
# Binary up to date (#893: overrides aport, so we have sonames in depends)
if package_aport:
logging.verbose(pkgname_depend + ": binary package is"
" up to date, using binary dependencies"
" instead of the ones from the aport")
return provider
def recurse(args, pkgnames, suffix="native"):
"""
Find all dependencies of the given pkgnames.
:param in_apkindexes: look through all APKINDEX files (with the specified arch)
:param in_aports: look through the aports folder
:param strict: raise RuntimeError, when a dependency can not be found.
:param suffix: the chroot suffix to resolve dependencies for. If a package
has multiple providers, we look at the installed packages in
the chroot to make a decision (see package_provider()).
:returns: list of pkgnames: consists of the initial pkgnames plus all
depends
"""
logging.debug("Calculate depends of packages " + str(pkgnames) +
", arch: " + arch)
logging.verbose("Search in_aports: " + str(in_aports) + ", in_apkindexes: " +
str(in_apkindexes))
# Sanity check
if not in_apkindexes and not in_aports:
raise RuntimeError("Set at least one of in_apkindexes or in_aports to"
" True.")
logging.debug("(" + suffix + ") calculate depends of " +
", ".join(pkgnames) + " (pmbootstrap -v for details)")
# Iterate over todo-list until is is empty
todo = list(pkgnames)
@ -62,64 +144,28 @@ def recurse(args, pkgnames, arch=None, in_apkindexes=True, in_aports=True,
continue
# Get depends and pkgname from aports
depends = None
pkgname = None
version = None
if in_aports:
aport = pmb.build.find_aport(args, pkgname_depend, False)
if aport:
apkbuild = pmb.parse.apkbuild(args, aport + "/APKBUILD")
depends = apkbuild["depends"]
version = apkbuild["pkgver"] + "-r" + apkbuild["pkgrel"]
logging.verbose(pkgname_depend + ": " + version +
" found in " + aport)
if pkgname_depend in apkbuild["subpackages"]:
pkgname = pkgname_depend
else:
pkgname = apkbuild["pkgname"]
# Get depends and pkgname from APKINDEX
if in_apkindexes:
index_data = pmb.parse.apkindex.read_any_index(args, pkgname_depend,
arch)
if index_data:
# The binary package's depends override the aport's depends in
# case it has the same or a higher version. Binary packages have
# sonames in their dependencies, which we need to detect
# breakage (#893).
outdated = (version and pmb.parse.version.compare(version,
index_data["version"]) == 1)
if not outdated:
if version:
logging.verbose(pkgname_depend + ": binary package is"
" up to date, using binary dependencies"
" instead of the ones from the aport")
depends = index_data["depends"]
pkgname = index_data["pkgname"]
pkgnames_install = list(ret) + todo
package = package_from_aports(args, pkgname_depend)
package = package_from_index(args, pkgname_depend, pkgnames_install,
package, suffix)
# Nothing found
if pkgname is None and strict:
if not package:
logging.info("NOTE: Run 'pmbootstrap pkgrel_bump --auto' to mark"
" packages with outdated dependencies for rebuild."
" This will most likely fix this issue (soname"
" bump?).")
logging.info("NOTE: More dependency calculation logging with"
" 'pmbootstrap -v'.")
raise RuntimeError(
recurse_error_message(
pkgname_depend,
in_aports,
in_apkindexes))
raise RuntimeError("Could not find package '" + pkgname_depend +
"' in any aports folder or APKINDEX.")
# Append to todo/ret (unless it is a duplicate)
if pkgname != pkgname_depend:
logging.verbose(pkgname_depend + ": provided by '" + pkgname + "'")
pkgname = package["pkgname"]
if pkgname in ret:
logging.verbose(pkgname + ": already found")
else:
depends = package["depends"]
logging.verbose(pkgname + ": depends on: " + ",".join(depends))
if depends:
todo += depends
ret.append(pkgname)
return ret