pmb.chroot.apk.install_{is_necessary -> build} (MR 2185)
install_is_necessary used to do the following things: 1. Error out if there's no binary package but pmb was invoked as "pmbootstrap install" and build_pkgs_on_install is disabled. 2. Build the package if necessary. 3. Return if a package "needs to be installed" (Boolean or Float). The only caller of the function is pmb.chroot.apk.install. It would not add the package to the long "apk add" command if according to 3. it does not need to be installed. When I implemented this a few years ago, I probably thought it would be useful to not unnecessarily pass packages to apk. But this actually makes it more complicated and doesn't have a benefit, apk is perfectly capable of recognizing which packages it had already installed. Replace the function with a much simpler pmb.chroot.apk.install_build, which only does 1. and 2. Change the order of the package, arch arguments to match called functions pmb.parse.apkindex.package and pmb.build.package.
This commit is contained in:
parent
c898b13296
commit
e91dbefd16
|
@ -87,74 +87,30 @@ def check_min_version(args, suffix="native"):
|
||||||
pmb.helpers.other.cache["apk_min_version_checked"].append(suffix)
|
pmb.helpers.other.cache["apk_min_version_checked"].append(suffix)
|
||||||
|
|
||||||
|
|
||||||
def install_is_necessary(args, build, arch, package, packages_installed):
|
def install_build(args, package, arch):
|
||||||
"""
|
"""
|
||||||
This function optionally builds an out of date package, and checks if the
|
Build an outdated package unless pmbootstrap was invoked with
|
||||||
version installed inside a chroot is up to date.
|
"pmbootstrap install" and the option to build packages during pmb install
|
||||||
:param build: Set to true to build the package, if the binary packages are
|
is disabled.
|
||||||
out of date, and it is in the aports folder.
|
|
||||||
:param packages_installed: Return value from installed().
|
|
||||||
:returns: True if the package needs to be installed/updated,
|
|
||||||
False otherwise.
|
|
||||||
"""
|
|
||||||
# For packages to be removed we can do the test immediately
|
|
||||||
if package.startswith("!"):
|
|
||||||
return package[1:] in packages_installed
|
|
||||||
|
|
||||||
# User may have disabled buiding packages during "pmbootstrap install"
|
:param package: name of the package to build
|
||||||
build_disabled = False
|
:param arch: architecture of the package to build
|
||||||
|
"""
|
||||||
|
# User may have disabled building packages during "pmbootstrap install"
|
||||||
if args.action == "install" and not args.build_pkgs_on_install:
|
if args.action == "install" and not args.build_pkgs_on_install:
|
||||||
build_disabled = True
|
if not pmb.parse.apkindex.package(args, package, arch, False):
|
||||||
|
|
||||||
# Build package
|
|
||||||
if build and not build_disabled:
|
|
||||||
pmb.build.package(args, package, arch)
|
|
||||||
|
|
||||||
# No further checks when not installed
|
|
||||||
if package not in packages_installed:
|
|
||||||
return True
|
|
||||||
|
|
||||||
# Make sure that we really have a binary package
|
|
||||||
data_repo = pmb.parse.apkindex.package(args, package, arch, False)
|
|
||||||
if not data_repo:
|
|
||||||
if build_disabled:
|
|
||||||
raise RuntimeError(f"{package}: no binary package found for"
|
raise RuntimeError(f"{package}: no binary package found for"
|
||||||
f" {arch}, and compiling packages during"
|
f" {arch}, and compiling packages during"
|
||||||
" 'pmbootstrap install' has been disabled."
|
" 'pmbootstrap install' has been disabled."
|
||||||
" Consider changing this option in"
|
" Consider changing this option in"
|
||||||
" 'pmbootstrap init'.")
|
" 'pmbootstrap init'.")
|
||||||
logging.warning("WARNING: Internal error in pmbootstrap,"
|
# Use the existing binary package
|
||||||
f" package '{package}' for {arch}"
|
return
|
||||||
" has not been built yet, but it should have"
|
|
||||||
" been. Rebuilding it with force. Please "
|
|
||||||
" report this, if there is no ticket about this"
|
|
||||||
" yet!")
|
|
||||||
pmb.build.package(args, package, arch, True)
|
|
||||||
return install_is_necessary(args, build, arch, package,
|
|
||||||
packages_installed)
|
|
||||||
|
|
||||||
# Compare the installed version vs. the version in the repos
|
# Build the package if it's in pmaports and there is no binary package
|
||||||
data_installed = packages_installed[package]
|
# with the same pkgver and pkgrel. This check is done in
|
||||||
compare = pmb.parse.version.compare(data_installed["version"],
|
# pmb.build.is_necessary, which gets called in pmb.build.package.
|
||||||
data_repo["version"])
|
return pmb.build.package(args, package, arch)
|
||||||
# a) Installed newer (should not happen normally)
|
|
||||||
if compare == 1:
|
|
||||||
logging.info(f"WARNING: {arch} package '{package}'"
|
|
||||||
f" installed version {data_installed['version']}"
|
|
||||||
" is newer, than the version in the repositories:"
|
|
||||||
f" {data_repo['version']}"
|
|
||||||
" See also: <https://postmarketos.org/warning-repo>")
|
|
||||||
return False
|
|
||||||
|
|
||||||
# b) Repo newer
|
|
||||||
elif compare == -1:
|
|
||||||
return True
|
|
||||||
|
|
||||||
# c) Same version, look at last modified
|
|
||||||
elif compare == 0:
|
|
||||||
time_installed = float(data_installed["timestamp"])
|
|
||||||
time_repo = float(data_repo["timestamp"])
|
|
||||||
return time_repo > time_installed
|
|
||||||
|
|
||||||
|
|
||||||
def replace_aports_packages_with_path(args, packages, suffix, arch):
|
def replace_aports_packages_with_path(args, packages, suffix, arch):
|
||||||
|
@ -211,13 +167,12 @@ def install(args, packages, suffix="native", build=True):
|
||||||
to_add = []
|
to_add = []
|
||||||
to_del = []
|
to_del = []
|
||||||
for package in packages_with_depends:
|
for package in packages_with_depends:
|
||||||
if not install_is_necessary(
|
|
||||||
args, build, arch, package, packages_installed):
|
|
||||||
continue
|
|
||||||
if package.startswith("!"):
|
if package.startswith("!"):
|
||||||
to_del.append(package.lstrip("!"))
|
to_del.append(package.lstrip("!"))
|
||||||
else:
|
continue
|
||||||
to_add.append(package)
|
if build:
|
||||||
|
install_build(args, package, arch)
|
||||||
|
to_add.append(package)
|
||||||
if not len(to_add) and not len(to_del):
|
if not len(to_add) and not len(to_del):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -18,15 +18,40 @@ def args(tmpdir, request):
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
def test_install_is_necessary(args):
|
def test_install_build(monkeypatch, args):
|
||||||
# osk-sdl not installed, nothing to do
|
func = pmb.chroot.apk.install_build
|
||||||
ret = pmb.chroot.apk.install_is_necessary(args, False, "aarch64",
|
ret_apkindex_package = None
|
||||||
"!osk-sdl",
|
|
||||||
{"unl0kr": {"unl0kr": {}}})
|
|
||||||
assert not ret
|
|
||||||
|
|
||||||
# osk-sdl installed, (un)install necessary
|
def fake_build_package(args, package, arch):
|
||||||
ret = pmb.chroot.apk.install_is_necessary(args, False, "aarch64",
|
return "build-pkg"
|
||||||
"!osk-sdl",
|
monkeypatch.setattr(pmb.build, "package", fake_build_package)
|
||||||
{"osk-sdl": {"osk-sdl": {}}})
|
|
||||||
assert ret
|
def fake_apkindex_package(args, package, arch, must_exist):
|
||||||
|
return ret_apkindex_package
|
||||||
|
monkeypatch.setattr(pmb.parse.apkindex, "package", fake_apkindex_package)
|
||||||
|
|
||||||
|
package = "hello-world"
|
||||||
|
arch = "x86_64"
|
||||||
|
|
||||||
|
# invoked as pmb install, build_pkgs_on_install disabled
|
||||||
|
args.action = "install"
|
||||||
|
args.build_pkgs_on_install = False
|
||||||
|
with pytest.raises(RuntimeError) as e:
|
||||||
|
func(args, package, arch)
|
||||||
|
assert "no binary package found" in str(e.value)
|
||||||
|
|
||||||
|
# invoked as pmb install, build_pkgs_on_install disabled, binary exists
|
||||||
|
args.action = "install"
|
||||||
|
args.build_pkgs_on_install = False
|
||||||
|
ret_apkindex_package = {"pkgname": "hello-world"}
|
||||||
|
assert func(args, package, arch) is None
|
||||||
|
|
||||||
|
# invoked as pmb install, build_pkgs_on_install enabled
|
||||||
|
args.action = "install"
|
||||||
|
args.build_pkgs_on_install = True
|
||||||
|
assert func(args, package, arch) == "build-pkg"
|
||||||
|
|
||||||
|
# invoked as not pmb install
|
||||||
|
args.action = "chroot"
|
||||||
|
args.build_pkgs_on_install = False
|
||||||
|
assert func(args, package, arch) == "build-pkg"
|
||||||
|
|
Loading…
Reference in New Issue