2023-01-22 18:11:10 +00:00
|
|
|
# Copyright 2023 Oliver Smith
|
2020-02-20 20:07:28 +00:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2017-06-27 15:56:15 +00:00
|
|
|
import os
|
2017-05-26 20:08:45 +00:00
|
|
|
import logging
|
2017-07-11 17:19:39 +00:00
|
|
|
import shlex
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.chroot
|
2017-06-23 15:04:49 +00:00
|
|
|
import pmb.config
|
2020-11-27 19:45:22 +00:00
|
|
|
import pmb.helpers.apk
|
2018-11-15 07:30:49 +00:00
|
|
|
import pmb.helpers.pmaports
|
2017-05-26 20:08:45 +00:00
|
|
|
import pmb.parse.apkindex
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
import pmb.parse.arch
|
|
|
|
import pmb.parse.depends
|
2017-08-12 14:03:40 +00:00
|
|
|
import pmb.parse.version
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
2017-07-11 17:19:39 +00:00
|
|
|
def update_repository_list(args, suffix="native", check=False):
|
|
|
|
"""
|
|
|
|
Update /etc/apk/repositories, if it is outdated (when the user changed the
|
|
|
|
--mirror-alpine or --mirror-pmOS parameters).
|
|
|
|
|
|
|
|
:param check: This function calls it self after updating the
|
|
|
|
/etc/apk/repositories file, to check if it was successful.
|
|
|
|
Only for this purpose, the "check" parameter should be set to
|
|
|
|
True.
|
|
|
|
"""
|
|
|
|
# Skip if we already did this
|
2021-10-30 12:20:57 +00:00
|
|
|
if suffix in pmb.helpers.other.cache["apk_repository_list_updated"]:
|
2017-07-11 17:19:39 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# Read old entries or create folder structure
|
2021-03-21 21:19:12 +00:00
|
|
|
path = f"{args.work}/chroot_{suffix}/etc/apk/repositories"
|
2017-07-11 17:19:39 +00:00
|
|
|
lines_old = []
|
|
|
|
if os.path.exists(path):
|
|
|
|
# Read all old lines
|
|
|
|
lines_old = []
|
|
|
|
with open(path) as handle:
|
|
|
|
for line in handle:
|
|
|
|
lines_old.append(line[:-1])
|
|
|
|
else:
|
2018-07-14 01:13:28 +00:00
|
|
|
pmb.helpers.run.root(args, ["mkdir", "-p", os.path.dirname(path)])
|
2017-07-11 17:19:39 +00:00
|
|
|
|
|
|
|
# Up to date: Save cache, return
|
|
|
|
lines_new = pmb.helpers.repo.urls(args)
|
|
|
|
if lines_old == lines_new:
|
2021-10-30 12:20:57 +00:00
|
|
|
pmb.helpers.other.cache["apk_repository_list_updated"].append(suffix)
|
2017-07-11 17:19:39 +00:00
|
|
|
return
|
|
|
|
|
|
|
|
# Check phase: raise error when still outdated
|
|
|
|
if check:
|
2021-03-21 21:19:12 +00:00
|
|
|
raise RuntimeError(f"Failed to update: {path}")
|
2017-07-11 17:19:39 +00:00
|
|
|
|
|
|
|
# Update the file
|
2021-03-21 21:19:12 +00:00
|
|
|
logging.debug(f"({suffix}) update /etc/apk/repositories")
|
2017-07-11 17:19:39 +00:00
|
|
|
if os.path.exists(path):
|
|
|
|
pmb.helpers.run.root(args, ["rm", path])
|
|
|
|
for line in lines_new:
|
2021-03-21 21:19:12 +00:00
|
|
|
pmb.helpers.run.root(args, ["sh", "-c", "echo "
|
|
|
|
f"{shlex.quote(line)} >> {path}"])
|
2017-07-11 17:19:39 +00:00
|
|
|
update_repository_list(args, suffix, True)
|
|
|
|
|
|
|
|
|
2017-06-23 15:04:49 +00:00
|
|
|
def check_min_version(args, suffix="native"):
|
|
|
|
"""
|
|
|
|
Check the minimum apk version, before running it the first time in the
|
|
|
|
current session (lifetime of one pmbootstrap call).
|
|
|
|
"""
|
2017-06-27 15:56:15 +00:00
|
|
|
|
2017-06-23 15:04:49 +00:00
|
|
|
# Skip if we already did this
|
2021-10-30 12:20:57 +00:00
|
|
|
if suffix in pmb.helpers.other.cache["apk_min_version_checked"]:
|
2017-06-23 15:04:49 +00:00
|
|
|
return
|
|
|
|
|
2017-06-27 15:56:15 +00:00
|
|
|
# Skip if apk is not installed yet
|
2021-03-21 21:19:12 +00:00
|
|
|
if not os.path.exists(f"{args.work}/chroot_{suffix}/sbin/apk"):
|
|
|
|
logging.debug(f"NOTE: Skipped apk version check for chroot '{suffix}'"
|
|
|
|
", because it is not installed yet!")
|
2017-06-27 15:56:15 +00:00
|
|
|
return
|
2017-06-23 15:04:49 +00:00
|
|
|
|
|
|
|
# Compare
|
2017-06-27 15:56:15 +00:00
|
|
|
version_installed = installed(args, suffix)["apk-tools"]["version"]
|
2021-01-27 17:50:33 +00:00
|
|
|
pmb.helpers.apk.check_outdated(
|
|
|
|
args, version_installed,
|
|
|
|
"Delete your http cache and zap all chroots, then try again:"
|
|
|
|
" 'pmbootstrap zap -hc'")
|
2017-06-27 15:56:15 +00:00
|
|
|
|
|
|
|
# Mark this suffix as checked
|
2021-10-30 12:20:57 +00:00
|
|
|
pmb.helpers.other.cache["apk_min_version_checked"].append(suffix)
|
2017-06-23 15:04:49 +00:00
|
|
|
|
|
|
|
|
2022-05-28 10:44:56 +00:00
|
|
|
def install_build(args, package, arch):
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
"""
|
2022-05-28 10:44:56 +00:00
|
|
|
Build an outdated package unless pmbootstrap was invoked with
|
|
|
|
"pmbootstrap install" and the option to build packages during pmb install
|
|
|
|
is disabled.
|
2021-12-06 19:30:58 +00:00
|
|
|
|
2022-05-28 10:44:56 +00:00
|
|
|
:param package: name of the package to build
|
|
|
|
:param arch: architecture of the package to build
|
|
|
|
"""
|
|
|
|
# User may have disabled building packages during "pmbootstrap install"
|
2020-06-22 10:51:07 +00:00
|
|
|
if args.action == "install" and not args.build_pkgs_on_install:
|
2022-05-28 10:44:56 +00:00
|
|
|
if not pmb.parse.apkindex.package(args, package, arch, False):
|
2020-06-22 10:51:07 +00:00
|
|
|
raise RuntimeError(f"{package}: no binary package found for"
|
|
|
|
f" {arch}, and compiling packages during"
|
|
|
|
" 'pmbootstrap install' has been disabled."
|
|
|
|
" Consider changing this option in"
|
|
|
|
" 'pmbootstrap init'.")
|
2022-05-28 10:44:56 +00:00
|
|
|
# Use the existing binary package
|
|
|
|
return
|
|
|
|
|
|
|
|
# Build the package if it's in pmaports and there is no binary package
|
|
|
|
# with the same pkgver and pkgrel. This check is done in
|
|
|
|
# pmb.build.is_necessary, which gets called in pmb.build.package.
|
|
|
|
return pmb.build.package(args, package, arch)
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
|
|
|
|
|
2022-05-29 08:13:48 +00:00
|
|
|
def packages_split_to_add_del(packages):
|
|
|
|
"""
|
|
|
|
Sort packages into "to_add" and "to_del" lists depending on their pkgname
|
|
|
|
starting with an exclamation mark.
|
|
|
|
|
|
|
|
:param packages: list of pkgnames
|
|
|
|
:returns: (to_add, to_del) - tuple of lists of pkgnames, e.g.
|
|
|
|
(["hello-world", ...], ["some-conflict-pkg", ...])
|
|
|
|
"""
|
|
|
|
to_add = []
|
|
|
|
to_del = []
|
|
|
|
|
|
|
|
for package in packages:
|
|
|
|
if package.startswith("!"):
|
|
|
|
to_del.append(package.lstrip("!"))
|
|
|
|
else:
|
|
|
|
to_add.append(package)
|
|
|
|
|
|
|
|
return (to_add, to_del)
|
|
|
|
|
|
|
|
|
2022-05-29 08:51:00 +00:00
|
|
|
def packages_get_locally_built_apks(args, packages, arch):
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
"""
|
2022-05-29 08:51:00 +00:00
|
|
|
Iterate over packages and if existing, get paths to locally built packages.
|
|
|
|
This is used to force apk to upgrade packages to newer local versions, even
|
|
|
|
if the pkgver and pkgrel did not change.
|
|
|
|
|
|
|
|
:param packages: list of pkgnames
|
|
|
|
:param arch: architecture that the locally built packages should have
|
|
|
|
:returns: list of apk file paths that are valid inside the chroots, e.g.
|
2023-08-06 18:43:28 +00:00
|
|
|
["/mnt/pmbootstrap/packages/x86_64/hello-world-1-r6.apk", ...]
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
"""
|
2022-05-29 08:51:00 +00:00
|
|
|
channel = pmb.config.pmaports.read_config(args)["channel"]
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
ret = []
|
2022-05-29 08:51:00 +00:00
|
|
|
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
for package in packages:
|
2022-05-29 08:51:00 +00:00
|
|
|
data_repo = pmb.parse.apkindex.package(args, package, arch, False)
|
|
|
|
if not data_repo:
|
|
|
|
continue
|
|
|
|
|
|
|
|
apk_file = f"{package}-{data_repo['version']}.apk"
|
|
|
|
if not os.path.exists(f"{args.work}/packages/{channel}/{arch}/{apk_file}"):
|
|
|
|
continue
|
|
|
|
|
2023-08-06 18:43:28 +00:00
|
|
|
ret.append(f"/mnt/pmbootstrap/packages/{arch}/{apk_file}")
|
2022-05-29 08:51:00 +00:00
|
|
|
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
return ret
|
|
|
|
|
|
|
|
|
2022-05-29 08:51:00 +00:00
|
|
|
def install_run_apk(args, to_add, to_add_local, to_del, suffix):
|
2022-05-29 08:05:41 +00:00
|
|
|
"""
|
|
|
|
Run apk to add packages, and ensure only the desired packages get
|
|
|
|
explicitly marked as installed.
|
2022-05-29 08:51:00 +00:00
|
|
|
|
|
|
|
:param to_add: list of pkgnames to install, without their dependencies
|
|
|
|
:param to_add_local: return of packages_get_locally_built_apks()
|
|
|
|
:param to_del: list of pkgnames to be deleted, this should be set to
|
|
|
|
conflicting dependencies in any of the packages to be
|
|
|
|
installed or their dependencies (e.g. ["osk-sdl"])
|
|
|
|
:param suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64"
|
2022-05-29 08:05:41 +00:00
|
|
|
"""
|
2022-05-29 08:43:05 +00:00
|
|
|
# Sanitize packages: don't allow '--allow-untrusted' and other options
|
|
|
|
# to be passed to apk!
|
|
|
|
for package in to_add + to_add_local + to_del:
|
|
|
|
if package.startswith("-"):
|
|
|
|
raise ValueError(f"Invalid package name: {package}")
|
|
|
|
|
2022-05-29 08:51:00 +00:00
|
|
|
commands = [["add"] + to_add]
|
2022-05-29 08:05:41 +00:00
|
|
|
|
|
|
|
# Use a virtual package to mark only the explicitly requested packages as
|
2022-05-29 08:51:00 +00:00
|
|
|
# explicitly installed, not the ones in to_add_local
|
|
|
|
if to_add_local:
|
|
|
|
commands += [["add", "-u", "--virtual", ".pmbootstrap"] + to_add_local,
|
|
|
|
["del", ".pmbootstrap"]]
|
|
|
|
|
|
|
|
if to_del:
|
|
|
|
commands += [["del"] + to_del]
|
|
|
|
|
2022-05-29 08:05:41 +00:00
|
|
|
for (i, command) in enumerate(commands):
|
|
|
|
if args.offline:
|
|
|
|
command = ["--no-network"] + command
|
|
|
|
if i == 0:
|
|
|
|
pmb.helpers.apk.apk_with_progress(args, ["apk"] + command,
|
|
|
|
chroot=True, suffix=suffix)
|
|
|
|
else:
|
|
|
|
# Virtual package related commands don't actually install or remove
|
|
|
|
# packages, but only mark the right ones as explicitly installed.
|
|
|
|
# They finish up almost instantly, so don't display a progress bar.
|
|
|
|
pmb.chroot.root(args, ["apk", "--no-progress"] + command,
|
|
|
|
suffix=suffix)
|
|
|
|
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
def install(args, packages, suffix="native", build=True):
|
|
|
|
"""
|
2022-05-28 09:37:51 +00:00
|
|
|
Install packages from pmbootstrap's local package index or the pmOS/Alpine
|
|
|
|
binary package mirrors. Iterate over all dependencies recursively, and
|
|
|
|
build missing packages as necessary.
|
|
|
|
|
|
|
|
:param packages: list of pkgnames to be installed
|
|
|
|
:param suffix: the chroot suffix, e.g. "native" or "rootfs_qemu-amd64"
|
2017-05-26 20:08:45 +00:00
|
|
|
:param build: automatically build the package, when it does not exist yet
|
2022-05-28 09:37:51 +00:00
|
|
|
or needs to be updated, and it is inside pmaports. For the
|
|
|
|
special case that all packages are expected to be in Alpine's
|
|
|
|
repositories, set this to False for performance optimization.
|
2017-05-26 20:08:45 +00:00
|
|
|
"""
|
2022-05-29 08:13:48 +00:00
|
|
|
arch = pmb.parse.arch.from_chroot_suffix(args, suffix)
|
|
|
|
|
2022-05-29 08:30:20 +00:00
|
|
|
if not packages:
|
|
|
|
logging.verbose("pmb.chroot.apk.install called with empty packages list,"
|
|
|
|
" ignoring")
|
|
|
|
return
|
|
|
|
|
2017-05-26 20:08:45 +00:00
|
|
|
# Initialize chroot
|
2017-06-23 15:04:49 +00:00
|
|
|
check_min_version(args, suffix)
|
2017-05-26 20:08:45 +00:00
|
|
|
pmb.chroot.init(args, suffix)
|
|
|
|
|
2018-02-20 19:52:28 +00:00
|
|
|
packages_with_depends = pmb.parse.depends.recurse(args, packages, suffix)
|
2022-05-29 08:13:48 +00:00
|
|
|
to_add, to_del = packages_split_to_add_del(packages_with_depends)
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
|
2022-05-29 08:13:48 +00:00
|
|
|
if build:
|
|
|
|
for package in to_add:
|
2022-05-28 10:44:56 +00:00
|
|
|
install_build(args, package, arch)
|
2017-05-26 20:08:45 +00:00
|
|
|
|
2022-05-29 08:51:00 +00:00
|
|
|
to_add_local = packages_get_locally_built_apks(args, to_add, arch)
|
|
|
|
to_add_no_deps, _ = packages_split_to_add_del(packages)
|
2022-01-07 19:21:47 +00:00
|
|
|
|
2022-05-29 09:25:49 +00:00
|
|
|
logging.info(f"({suffix}) install {' '.join(to_add_no_deps)}")
|
2022-05-29 08:51:00 +00:00
|
|
|
install_run_apk(args, to_add_no_deps, to_add_local, to_del, suffix)
|
2017-05-26 20:08:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
def installed(args, suffix="native"):
|
2017-06-08 15:54:53 +00:00
|
|
|
"""
|
2017-06-27 15:56:15 +00:00
|
|
|
Read the list of installed packages (which has almost the same format, as
|
|
|
|
an APKINDEX, but with more keys).
|
Properly rebuild/install packages when something changed (Fix #120, #108, #131) (#129)
TLDR: Always rebuild/install packages when something changed when executing "pmbootstrap install/initfs/flash", more speed in dependency resolution.
---
pmbootstrap has already gotten some support for "timestamp based rebuilds", which modifies the logic for when packages should be rebuilt. It doesn't only consider packages outdated with old pkgver/pkgrel combinations, but also packages, where a source file has a newer timestamp, than the built package has.
I've found out, that this can lead to more rebuilds than expected. For example, when you check out the pmbootstrap git repository again into another folder, although you have already built packages. Then all files have the timestamp of the checkout, and the packages will appear to be outdated. While this is not largely a concern now, this will become a problem once we have a binary package repository, because then the packages from the binary repo will always seem to be outdated, if you just freshly checked out the repository.
To combat this, git gets asked if the files from the aport we're looking at are in sync with upstream, or not. Only when the files are not in sync with upstream and the timestamps of the sources are newer, a rebuild gets triggered from now on.
In case this logic should fail, I've added an option during "pmbootstrap init" where you can enable or disable the "timestamp based rebuilds" option.
In addition to that, this commit also works on fixing #120: packages do not get updated in "pmbootstrap install" after they have been rebuilt. For this to work, we specify all packages explicitly for abuild, instead of letting abuild do the resolving. This feature will also work with the "timestamp based rebuilds".
This commit also fixes the working_dir argument in pmb.helpers.run.user, which was simply ignored before.
Finally, the performance of the dependency resolution is faster again (when compared to the current version in master), because the parsed apkbuilds and finding the aport by pkgname gets cached during one pmbootstrap call (in args.cache, which also makes it easy to put fake data there in testcases).
The new dependency resolution code can output lots of verbose messages for debugging by specifying the `-v` parameter. The meaning of that changed, it used to output the file names where log messages come from, but no one seemed to use that anyway.
2017-07-10 15:23:43 +00:00
|
|
|
|
2017-06-27 15:56:15 +00:00
|
|
|
:returns: a dictionary with the following structure:
|
|
|
|
{ "postmarketos-mkinitfs":
|
|
|
|
{
|
|
|
|
"pkgname": "postmarketos-mkinitfs"
|
|
|
|
"version": "0.0.4-r10",
|
|
|
|
"depends": ["busybox-extras", "lddtree", ...],
|
|
|
|
"provides": ["mkinitfs=0.0.1"]
|
|
|
|
}, ...
|
|
|
|
}
|
2017-06-08 15:54:53 +00:00
|
|
|
"""
|
2021-03-21 21:19:12 +00:00
|
|
|
path = f"{args.work}/chroot_{suffix}/lib/apk/db/installed"
|
2021-11-09 11:53:59 +00:00
|
|
|
return pmb.parse.apkindex.parse(path, False)
|