2021-01-12 19:11:12 +01:00
|
|
|
#!/bin/bash
|
2023-11-16 10:10:29 +01:00
|
|
|
# SPDX-FileCopyrightText: 2020-2023 Fabian Vogt <fabian@ritter-vogt.de>
|
2021-01-12 19:11:12 +01:00
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
set -euo pipefail
|
|
|
|
|
2021-10-05 16:54:17 +02:00
|
|
|
qtvers=
|
2021-01-12 19:11:12 +01:00
|
|
|
ret=0
|
|
|
|
|
|
|
|
while [ $# -gt 0 ]; do
|
|
|
|
case $1 in
|
|
|
|
--qtver)
|
2021-10-05 16:54:17 +02:00
|
|
|
qtvers=$2
|
2021-01-12 19:11:12 +01:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown argument $1" >&2
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
shift
|
|
|
|
done
|
|
|
|
|
|
|
|
# Guess Qt version
|
2021-10-05 16:54:17 +02:00
|
|
|
qtver=
|
|
|
|
[[ -n ${qtvers} ]] || qtvers="5 6 7"
|
|
|
|
|
|
|
|
for ver in ${qtvers}; do
|
2024-01-22 10:48:52 +01:00
|
|
|
if [ -e "/usr/lib/libQt${ver}Core.so.${ver}" ] || [ -e "/usr/lib64/libQt${ver}Core.so.${ver}" ]; then
|
|
|
|
qtver="${qtver}${ver}"
|
|
|
|
fi
|
2021-10-05 16:54:17 +02:00
|
|
|
done
|
|
|
|
|
2021-10-19 21:01:08 +02:00
|
|
|
# Zero or more than one version of Qt found. Abort.
|
2021-10-05 16:54:17 +02:00
|
|
|
if [[ ${#qtver} -ne 1 ]]; then
|
|
|
|
echo "Failed to guess Qt version!" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ ${qtver} == 5 ]]; then
|
|
|
|
importscanner="qmlimportscanner-qt5"
|
|
|
|
else
|
2023-11-16 10:10:29 +01:00
|
|
|
importscanner="$(qtpaths${qtver} --qt-query QT_HOST_LIBEXECS)/qmlimportscanner"
|
2021-01-12 19:11:12 +01:00
|
|
|
fi
|
|
|
|
|
2021-10-05 16:54:17 +02:00
|
|
|
command -v "${importscanner}" &>/dev/null || echo "Failed to locate qmlimportscanner"
|
|
|
|
|
2021-01-12 19:11:12 +01:00
|
|
|
declare -A dependencies
|
2023-11-16 10:10:29 +01:00
|
|
|
# foundDependency Module.Uri 42 69
|
|
|
|
# In the dependencies array, it sets the version of qt5qmlimport(Module.Uri.42) to 69, if lower.
|
2021-01-12 19:11:12 +01:00
|
|
|
foundDependency() {
|
2023-11-16 10:10:29 +01:00
|
|
|
uri="$1.$2"
|
|
|
|
if [ ${dependencies[$uri]:=0} -lt $3 ]; then
|
|
|
|
dependencies[$uri]=$3
|
2021-01-12 19:11:12 +01:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# TODO: Get exit status of qmlimportscanner
|
2023-11-16 10:10:29 +01:00
|
|
|
while read import version; do
|
|
|
|
if [ -z "$version" ]; then
|
|
|
|
dependencies[$import]=0
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
|
|
|
maj="${version%.*}"
|
|
|
|
min="${version#*.}"
|
|
|
|
|
2023-07-11 13:36:28 +02:00
|
|
|
# For imports without minor version like "import org.kde.kirigami 2",
|
|
|
|
# the minor version is reported as 255. Treat that as 0 instead.
|
2023-11-16 10:10:29 +01:00
|
|
|
if [ "$min" = 255 ]; then
|
2023-07-11 13:36:28 +02:00
|
|
|
min=0
|
|
|
|
fi
|
2023-11-16 10:10:29 +01:00
|
|
|
foundDependency "$import" "$maj" "$min"
|
|
|
|
done < <(grep -vE '/designer/.*\.qml' | xargs -r "$importscanner" -qmlFiles | jq -r '.[] | select(.type == "module") | .name + " " + .version')
|
2021-01-12 19:11:12 +01:00
|
|
|
|
|
|
|
for export in "${!dependencies[@]}"; do
|
2023-11-16 10:10:29 +01:00
|
|
|
ver="${dependencies["$export"]}"
|
|
|
|
if [ "$ver" != 0 ]; then
|
|
|
|
echo "qt${qtver}qmlimport(${export}) >= ${ver}"
|
|
|
|
else
|
|
|
|
echo "qt${qtver}qmlimport(${export})"
|
|
|
|
fi
|
2021-01-12 19:11:12 +01:00
|
|
|
done
|
|
|
|
|
|
|
|
exit $ret
|