Files
reims-vgpu/packaging/windows-runtime/scripts/read-msys2-package-metadata.sh
T
YXC0915 9a8a776418 Cache Windows runtime compilation and batch MSYS2 package lookups
Reuse compiler objects and Cargo downloads across Alpha jobs, then link and package the exact runtime inputs on every build. Query package ownership, versions and licenses in batches and avoid recompressing the uploaded archives.

Checked the workflow with actionlint and checked the MSYS2 lookup with mock and installed-package tests.
2026-12-04 18:45:23 +08:00

49 lines
1.4 KiB
Bash

#!/usr/bin/env bash
# Pacman's ownership query returns the owner and installed version together.
set -euo pipefail
export LC_ALL=C
if (($# == 0)); then
exit 0
fi
status=0
ownership=$(pacman -Qo -- "$@" 2>&1) || status=$?
owned='^(/clang64/bin/.+) is owned by ([^[:space:]]+) ([^[:space:]]+)$'
unowned='^error: No package owns (/clang64/bin/.+)$'
declare -A seen=()
packages=()
missing=0
while IFS= read -r line; do
if [[ $line =~ $owned ]]; then
path=${BASH_REMATCH[1]}
package=${BASH_REMATCH[2]}
version=${BASH_REMATCH[3]}
printf 'owned\t%s\t%s\t%s\n' "$path" "$package" "$version"
if [[ -z ${seen[$package]+yes} ]]; then
seen[$package]=1
packages+=("$package")
fi
elif [[ $line =~ $unowned ]]; then
printf 'unowned\t%s\n' "${BASH_REMATCH[1]}"
((missing += 1))
else
printf 'Unexpected pacman ownership response: %s\n' "$line" >&2
exit 1
fi
done <<< "$ownership"
if ((status != missing % 256)); then
printf 'pacman ownership query exited with %d for %d unowned files\n' "$status" "$missing" >&2
exit 1
fi
if ((${#packages[@]})); then
pacman -Ql -- "${packages[@]}" | awk '
{
package = $1
sub(/^[^[:space:]]+[[:space:]]+/, "")
if ($0 ~ /^\/clang64\/share\/licenses\/.+/ && $0 !~ /\/$/)
printf "license\t%s\t%s\n", package, $0
}
'
fi