summaryrefslogtreecommitdiff
path: root/lib/common-functions
diff options
context:
space:
mode:
Diffstat (limited to 'lib/common-functions')
-rwxr-xr-xlib/common-functions92
1 files changed, 92 insertions, 0 deletions
diff --git a/lib/common-functions b/lib/common-functions
index 873521d..5dd1c0d 100755
--- a/lib/common-functions
+++ b/lib/common-functions
@@ -947,3 +947,95 @@ apply_trunk_patch() {
-type f \
-exec cp '{}' "${source_dir}" \;
}
+
+# update_blocked_packages_count
+# update the count how many packages are blocked by a build assignment
+update_blocked_packages_count() {
+ ( # new shell is intentional
+ temp_dir=$(mktemp -d 'tmp.sanity-check.XXXXXXXXXX' --tmpdir)
+ trap 'rm -rf --one-file-system "${temp_dir}"' EXIT
+ # shellcheck disable=SC2016
+ {
+ printf 'SELECT '
+ printf '`a_bp`.`build_assignment`,'
+ printf '`b_bp`.`build_assignment`'
+ printf ' FROM `binary_packages` AS `a_bp`'
+ mysql_join_binary_packages_binary_packages_in_repositories 'a_bp' 'a_bpir'
+ printf ' AND `a_bpir`.`repository`=%s' \
+ "${repository_ids__any_build_list}"
+ mysql_join_binary_packages_dependencies 'a_bp'
+ mysql_join_dependencies_dependency_types
+ printf ' AND `dependency_types`.`relevant_for_binary_packages`'
+ mysql_join_dependencies_install_target_providers_with_versions
+ mysql_join_install_target_providers_binary_packages '' 'b_bp'
+ mysql_join_binary_packages_binary_packages_in_repositories 'b_bp' 'b_bpir'
+ printf ' AND `a_bpir`.`repository`=%s' \
+ "${repository_ids__any_build_list}"
+ printf ' WHERE `a_bp`.`architecture`=`b_bp`.`architecture`'
+ printf ' OR `a_bp`.`architecture`=%s' \
+ "${architecture_ids__any}"
+ printf ' OR `b_bp`.`architecture`=%s' \
+ "${architecture_ids__any}"
+ } | \
+ mysql_run_query | \
+ tr '\t' ' ' | \
+ sort -u | \
+ sort -k1,1 > \
+ "${temp_dir}/links.new"
+ touch "${temp_dir}/links.1" "${temp_dir}/links.2"
+ # new links (sorted by 1st column); old links (sorted by 1st / 2nd column)
+ while [ -s "${temp_dir}/links.new" ]; do
+ cat "${temp_dir}/links.1" "${temp_dir}/links.new" | \
+ sort -k2,2 > \
+ "${temp_dir}/links.2"
+ sort -k1,1 "${temp_dir}/links.2" > \
+ "${temp_dir}/links.1"
+ duplicates=$(
+ uniq -d "${temp_dir}/links.1"
+ )
+ if [ -n "${duplicates}" ]; then
+ >&2 echo 'internal error: there are %s duplicate links' \
+ "$(
+ printf '%s\n' "${duplicates}" | \
+ wc -l
+ )"
+ exit 42
+ fi
+ {
+ {
+ join -1 2 -2 1 -o 1.1,2.2 "${temp_dir}/links.2" "${temp_dir}/links.new"
+ sort -k2,2 "${temp_dir}/links.new" | \
+ join -1 2 -2 1 -o 1.1,2.2 - "${temp_dir}/links.1"
+ sort -k2,2 "${temp_dir}/links.new" | \
+ join -1 2 -2 1 -o 1.1,2.2 - "${temp_dir}/links.new"
+ } | \
+ sort -u
+ sed 'p' "${temp_dir}/links.1"
+ } | \
+ sort | \
+ uniq -u | \
+ sort -k1,1 | \
+ sponge "${temp_dir}/links.new"
+ done
+ cut -d' ' -f1 "${temp_dir}/links.1" | \
+ uniq -c | \
+ sed 's/^\s\+//' | \
+ tr ' ' '\t' > \
+ "${temp_dir}/link-counts"
+ # shellcheck disable=SC2016
+ {
+ printf 'CREATE TEMPORARY TABLE `lc` ('
+ printf '`count` MEDIUMINT,'
+ printf '`ba_id` BIGINT,'
+ printf 'PRIMARY KEY (`ba_id`)'
+ printf ');\n'
+ printf 'LOAD DATA LOCAL INFILE "%s" INTO TABLE `lc`(`count`,`ba_id`);\n' \
+ "${temp_dir}/link-counts"
+ printf 'UPDATE `build_assignments`'
+ printf ' LEFT JOIN `lc`'
+ printf ' ON `build_assignments`.`id`=`lc`.`ba_id`'
+ printf ' SET `build_assignments`.`currently_blocking`=`lc`.`count`;\n'
+ } | \
+ mysql_run_query
+ )
+}