summaryrefslogtreecommitdiff
path: root/bin/why-dont-you
diff options
context:
space:
mode:
authorErich Eckner <git@eckner.net>2017-08-29 14:30:50 +0200
committerErich Eckner <git@eckner.net>2017-08-29 14:30:50 +0200
commita7575e046de803de7f54f0820a2742a8063a0ee8 (patch)
treea25aa6617e4d6a43ec16b7c40e99470da5c2e138 /bin/why-dont-you
parent421601b9f48b5026e8a744b730d441af13671346 (diff)
downloadbuilder-a7575e046de803de7f54f0820a2742a8063a0ee8.tar.xz
bin/why_dont_you -> bin/why-dont-you
Diffstat (limited to 'bin/why-dont-you')
-rwxr-xr-xbin/why-dont-you260
1 files changed, 260 insertions, 0 deletions
diff --git a/bin/why-dont-you b/bin/why-dont-you
new file mode 100755
index 0000000..593ad1b
--- /dev/null
+++ b/bin/why-dont-you
@@ -0,0 +1,260 @@
+#!/bin/sh
+
+# usage: why_dont_you $action $package1 $package2 ...
+
+# investigate, why a certain operation is not done with certain packages
+
+# shellcheck source=conf/default.conf
+. "${0%/*}/../conf/default.conf"
+
+action="$1"
+shift
+
+case "${action}" in
+
+ 'build')
+
+ for pkg in "$@"; do
+ (
+ grep "^$(str_to_regex "${pkg}") " "${work_dir}/build-list" || \
+ >&2 printf '"%s" is not on the build list.\n' "${pkg}"
+ ) | \
+ while read -r package git_revision mod_git_revision repository; do
+
+ if package_locked_or_blocked "${package}" "${git_revision}" "${mod_git_revision}" "${repository}"; then
+ printf '"%s" is locked or blocked\n' "${pkg}"
+ continue
+ fi
+
+ unmet_dependencies=$(find_dependencies_on_build_list "${package}" "${git_revision}" "${mod_git_revision}" "${repository}")
+ if [ -n "${unmet_dependencies}" ]; then
+ printf '"%s" has unmet dependencies:\n' "${package}"
+ echo "${unmet_dependencies}" | \
+ while read -r dep; do
+ grep -lxF "${dep}" "${work_dir}/package-infos/"*".builds" | \
+ sed '
+ s|^.*/||
+ s|\(\.[^.]\+\)\{4\}||
+ '
+ done | \
+ sort -u
+ printf '\n'
+
+ continue
+ fi
+
+ if [ -f "${work_dir}/package-states/${package}.${git_revision}.${mod_git_revision}.${repository}.broken" ]; then
+ printf '"%s" is broken (%sx built), but would be built\n' \
+ "${pkg}" \
+ "$(wc -l < "${work_dir}/package-states/${package}.${git_revision}.${mod_git_revision}.${repository}.broken")"
+ else
+ printf '"%s" would be built\n' "${pkg}"
+ fi
+ done
+
+ done
+
+ ;;
+
+ 'unstage')
+
+ for pkg in "$@"; do
+
+ if ! find "${work_dir}/package-states" -maxdepth 1 | \
+ grep -q "/$(str_to_regex "${pkg}")\(\.[^.]\+\)\{3\}\.done\$"; then
+ printf '"%s" is not in staging!\n' "${pkg}"
+ continue
+ fi
+
+ dependent_packages=$(
+ grep -lxF "${pkg}" "${work_dir}/package-infos/"*".depends" | \
+ sed '
+ s|^.*/||
+ s|\.depends$||
+ '
+ )
+
+ build_list_items_file=$(mktemp)
+ dependent_packages_file=$(mktemp)
+
+ grep -vxF 'break_loops' "${work_dir}/build-list" | \
+ awk '{print $1 "." $2 "." $3 "." $4}' | \
+ sort -u > \
+ "${build_list_items_file}"
+
+ printf '%s\n' "${dependent_packages}" | \
+ sort -u > \
+ "${dependent_packages_file}"
+
+ dependent_still_on_build_list=$(
+ join -1 1 -2 1 -o 1.1 \
+ "${build_list_items_file}" \
+ "${dependent_packages_file}"
+ )
+
+ rm -f \
+ "${build_list_items_file}" \
+ "${dependent_packages_file}"
+
+ if [ -n "${dependent_still_on_build_list}" ]; then
+ printf 'The following packages are dependent on "%s", but still on the build list:\n' "${pkg}"
+ echo "${dependent_still_on_build_list}"
+ printf '\n'
+ continue
+ fi
+
+ dependent_still_in_staging=$(
+ echo "${dependent_packages}" | \
+ while read -r sf; do
+ if [ -f "${work_dir}/package-states/${sf}.done" ]; then
+ echo "${sf}"
+ fi
+ done
+ )
+
+ if [ -n "${dependent_still_in_staging}" ]; then
+ printf 'The following packages are dependent on "%s" and still in staging - maybe they cannot be unstaged:\n' "${pkg}"
+ echo "${dependent_still_in_staging}"
+ printf '\n'
+ continue
+ fi
+
+ printf 'Package "%s" can be unstaged.\n' "${pkg}"
+
+ done
+
+ ;;
+
+ 'keep')
+
+ tmp_file=$(mktemp)
+ trap 'rm -f "${tmp_file}"' EXIT
+
+ while read -r pkg; do
+
+ if builds_file=$(
+ find "${work_dir}/package-infos" -maxdepth 1 -printf '%f\n' | \
+ grep -m1 "^$(str_to_regex "${pkg}")\(\.[^.]\+\)\{3\}\.builds\$"
+ ); then
+
+ builds_file="${builds_file%.*}"
+ prepo="${builds_file##*.}"
+ builds_file="${builds_file%.*}"
+ mod_rev="${builds_file##*.}"
+ builds_file="${builds_file%.*}"
+ rev="${builds_file##*.}"
+
+ else
+
+ found_PKGBUILD=false
+ mod_rev=$(cat "${work_dir}/archlinux32.revision")
+ for repo in ${repo_names}; do
+ eval 'repo_path="${repo_paths__'"${repo}"'}"'
+ rev=$(cat "${work_dir}/${repo}.revision")
+ if [ "${repo}" = 'archlinux32' ]; then
+ if git -C "${repo_path}" archive "${mod_rev}" | \
+ grep -q "^[^/]\+/$(str_to_regex "${pkg}")/PKGBUILD\$"; then
+ prepo=$(
+ git -C "${repo_path}" archive "${mod_rev}" | \
+ grep "^[^/]\+/$(str_to_regex "${pkg}")/PKGBUILD\$" | \
+ cut -d/ -f1
+ )
+ found_PKGBUILD=true
+ break
+ fi
+ else
+ prepo=$(
+ git -C "${repo_path}" archive "${rev}" -- "${pkg}/repos" 2>/dev/null | \
+ tar -t 2> /dev/null | \
+ grep '^[^/]\+/repos/[^/]\+/PKGBUILD$' | \
+ grep -v -- '-i686/PKGBUILD$' | \
+ grep -v -- '[-/]\(staging\|testing\|unstable\)-[^/]\+/PKGBUILD$' | \
+ sed '
+ s|^[^/]\+/repos/\([^/]\+\)-[^/-]\+/PKGBUILD$|\1|
+ ' | \
+ head -n1
+ )
+ if [ -n "${prepo}" ]; then
+ found_PKGBUILD=true
+ break
+ fi
+ fi
+ done
+ if ! ${found_PKGBUILD}; then
+ continue
+ fi
+
+ generate_package_metadata "${pkg}" "${rev}" "${mod_rev}" "${prepo}"
+
+ fi
+
+ sed "s|^|${pkg} builds |" "${work_dir}/package-infos/${pkg}.${rev}.${mod_rev}.${prepo}.builds" >> \
+ "${tmp_file}"
+
+ done < \
+ "${work_dir}/deletion-list"
+
+ sort -k3,3 "${tmp_file}" | \
+ sponge "${tmp_file}"
+
+ for pkg in "$@"; do
+
+ if ! grep -qxF "${pkg}" "${work_dir}/deletion-list"; then
+ printf 'Package "%s" is not on the deletion list.\n' "${pkg}"
+ continue
+ fi
+
+ if git -C "${repo_paths__archlinux32}" archive "$(cat "${work_dir}/archlinux32.revision")" -- blacklist | \
+ tar -Ox 'blacklist' | \
+ grep -qxF "${pkg}"; then
+ printf 'Package "%s" is explicitely blacklisted.\n' "${pkg}"
+ continue
+ fi
+
+ if [ "lib32-${pkg#lib32-}" = "${pkg}" ]; then
+ printf 'Package "%s" is a library from multilib.\n' "${pkg}"
+ continue
+ fi
+
+ needs=$(
+ find "${work_dir}/package-infos" -maxdepth 1 -name "${pkg}.*.needs"
+ )
+ if [ -z "${needs}" ]; then
+ printf 'Package "%s" was deleted in the git repositories.\n' "${pkg}"
+ continue
+ fi
+
+ needs=$(
+ sort -u "${needs}"
+ )
+
+ errors=$(
+ (
+ # shellcheck disable=SC2086
+ printf '%s\n' ${needs}
+ awk '{print $3}' "${tmp_file}" | \
+ sort -u
+ ) | \
+ sort | \
+ uniq -d | \
+ join -1 1 -2 3 -o 2.1,2.2,2.3 - "${tmp_file}"
+ )
+ if [ -n "${errors}" ]; then
+ printf 'Package "%s" has dependencies on the deletion list:\n' "${pkg}"
+ # shellcheck disable=SC2086,SC2183
+ printf '%s %s %s\n' ${errors}
+ printf '\n'
+ continue
+ fi
+
+ printf 'It seems, package "%s" should not be deleted.\n' "${pkg}"
+
+ done
+
+ ;;
+
+ *)
+ >&2 printf 'unknown action "%s"\n' "${action}"
+ exit 1
+
+esac