update_chroot: Add a way to remove hard blockers

And set it to remove some old version of dev-python/setuptools_scm
package.
This commit is contained in:
Krzesimir Nowak 2021-09-15 21:00:20 +02:00
parent 2f9ce7b5b0
commit 186f1de4fa
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,62 @@
# Copyright © Microsoft Corporation
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
get_versions_from_equery() {
local equery_cmd="${1}"
local pkg="${2}"
"${equery_cmd}" --quiet --no-color list --format='${version} ${fullversion}' "${pkg}"
}
filter_out_too_new() {
local version="${1}"
local line
local other
local otherfull
local result
while read -r line; do
other=$(echo "${line}" | cut -d' ' -f1)
otherfull=$(echo "${line}" | cut -d' ' -f2)
result=$(printf '%s\n%s\n' "${version}" "${other}" | sort --version-sort | head --lines 1)
if [[ "${result}" != "${version}" ]]; then
echo "${otherfull}"
fi
done
}
# Remove hard blocks using passed emerge and equery commands, and a
# list of packages to be dropped. A package is specified as full
# package name and a version, separated by a colon. All packages with
# this name and with a lower version will be forcibly removed.
#
# Example invocation:
#
# $ remove_hard_blocks \
# emerge-amd64-usr equery-amd64-usr \
# dev-python/setuptools_scm:2
remove_hard_blocks() {
local emerge_cmd="${1}"
local equery_cmd="${2}"
local pkg_ver
local line
local pkg
local version
local -a pkgs_to_drop
shift 2
for pkg_ver; do
pkg=$(echo "${pkg_ver}" | cut -d: -f1)
version=$(echo "${pkg_ver}" | cut -d: -f2)
while read -r line; do
pkgs_to_drop+=("${pkg}-${line}")
done < <(get_versions_from_equery "${equery_cmd}" "${pkg}" | filter_out_too_new "${version}")
done
if [[ ${#pkgs_to_drop[@]} -gt 0 ]]; then
info "Dropping the following packages to avoid hard blocks: ${pkgs_to_drop[@]}"
"${emerge_cmd}" -C "${pkgs_to_drop[@]}"
else
info "No hard blockers to remove"
fi
}

View File

@ -7,6 +7,7 @@
. "$(dirname "$0")/common.sh" || exit 1 . "$(dirname "$0")/common.sh" || exit 1
. "${BUILD_LIBRARY_DIR}/toolchain_util.sh" . "${BUILD_LIBRARY_DIR}/toolchain_util.sh"
. "${BUILD_LIBRARY_DIR}/update_chroot_util.sh"
# Script must run inside the chroot # Script must run inside the chroot
assert_inside_chroot "$@" assert_inside_chroot "$@"
@ -242,6 +243,17 @@ if [ "${FLAGS_workon}" -eq "${FLAGS_TRUE}" ]; then
done done
fi fi
sudo_e_emerge() {
sudo -E "${EMERGE_CMD}" "${@}"
}
info "Maybe removing some hard blocks"
# dev-python/setuptools_scm: blocks the update of the package (newer
# versions have !!<dev-python/setuptools_scm-2 in BDEPEND).
remove_hard_blocks \
sudo_e_emerge equery \
dev-python/setuptools_scm:2
# Second pass, update everything else. # Second pass, update everything else.
EMERGE_FLAGS+=( --deep ) EMERGE_FLAGS+=( --deep )
info "Updating all SDK packages" info "Updating all SDK packages"