Improve the script fix_ffmpeg_dependencies

* add FFmpeg stubs to the 'Required.private' section.
  This will make the logic more robust after integration this
  in qt multimedia.
* add some script comments.
* fix shellcheck.
* add validity checks.

Pick-to: 6.8 6.9
Change-Id: I28639d21c7210109e52ff98ce682da51f8744287
Reviewed-by: Jøger Hansegård <jogerh@gmail.com>
Reviewed-by: Pavel Dubsky <pavel.dubsky@qt.io>
This commit is contained in:
Artem Dyomin 2024-10-29 09:59:22 +01:00
parent 07775b2ad2
commit a442e4893f
2 changed files with 36 additions and 8 deletions

View File

@ -15,10 +15,12 @@ if [ "$(uname -s)" = "Darwin" ]; then
fi fi
ffmpeg_libs=("avcodec" "avdevice" "avfilter" "avformat" "avutil" "swresample" "swscale") ffmpeg_libs=("avcodec" "avdevice" "avfilter" "avformat" "avutil" "swresample" "swscale")
stub_prefix="Qt6FFmpegStub-"
for lib_name in "${ffmpeg_libs[@]}"; do for lib_name in "${ffmpeg_libs[@]}"; do
lib_path="$lib_dir/lib$lib_name.so" lib_path="$lib_dir/lib$lib_name.so"
pkg_config_file_path="$lib_dir/pkgconfig/lib$lib_name.pc" pkg_config_file_path="$lib_dir/pkgconfig/lib$lib_name.pc"
stubs_required_versions=""
if [ ! -f "$lib_path" ]; then if [ ! -f "$lib_path" ]; then
echo "FFmpeg lib $lib_path hasn't been found" echo "FFmpeg lib $lib_path hasn't been found"
@ -30,21 +32,46 @@ for lib_name in "${ffmpeg_libs[@]}"; do
exit 1 exit 1
fi fi
read_needed_deps() {
readelf -d "$lib_path" | grep '(NEEDED)'
}
while read -r line; do while read -r line; do
if [[ $line =~ .*\[(lib((ssl|crypto|va|va-x11|va-drm)(_3)?\.so(\.[0-9]+)*))\].* ]]; then if [[ $line =~ .*\[(lib((ssl|crypto|va|va-x11|va-drm)(_3)?\.so(\.[0-9]+)*))\].* ]]; then
stub_name="libQt6FFmpegStub-${BASH_REMATCH[2]}" stub_name="lib$stub_prefix${BASH_REMATCH[2]}"
if [[ ${BASH_REMATCH[4]} == "_3" ]]; then android_ssl_suffix=${BASH_REMATCH[4]}
stub_name="${stub_name/_3/}" # Remove "_3" from stub_name soversion=${BASH_REMATCH[5]}
if [ -n "$android_ssl_suffix" ] && [ -n "$soversion" ]; then
>&2 echo "both, android_ssl_suffix $android_ssl_suffix and soversion $soversion are found"
continue
fi fi
if [[ "$android_ssl_suffix" == "_3" ]]; then
stub_name="${stub_name/_3/}" # Remove "_3" from stub_name
stubs_required_versions+=" ${stub_name/.so/ = 3},"
elif [[ -n "$soversion" ]]; then
stubs_required_versions+=" ${stub_name/.so./ = },"
fi
if [[ -n "$additional_suffix" ]]; then if [[ -n "$additional_suffix" ]]; then
stub_name="${stub_name%%.*}${additional_suffix}.${stub_name#*.}" # Add additional_suffix stub_name="${stub_name%%.*}${additional_suffix}.${stub_name#*.}" # Add additional_suffix
fi fi
patchelf --replace-needed "${BASH_REMATCH[1]}" "${stub_name}" $lib_path
fi
done <<< "$(readelf -d $lib_path | grep '(NEEDED)' )"
sed -i.bak -E '/^Libs.private:/s/ -l(va|va-x11|va-drm|ssl|crypto)/ -lQt6FFmpegStub-\1/g;' $pkg_config_file_path && rm -f ${pkg_config_file_path}.bak patchelf --replace-needed "${BASH_REMATCH[1]}" "${stub_name}" "$lib_path"
fi
done <<< "$(read_needed_deps)"
sed_cmd="/^Libs.private:/s/ -l(va|va-x11|va-drm|ssl|crypto)/ -l$stub_prefix\\1/g;"
if [[ -n "$stubs_required_versions" ]]; then
stubs_required_versions="${stubs_required_versions%?}" # remove the last comma
sed_cmd+="s/(^Requires.private:[^,]*(,)?.*$)/\\1\\2$stubs_required_versions/g;"
fi
# sed -i doesn't work without parameter on macOS 13
sed -i.bak -E "$sed_cmd" "$pkg_config_file_path" && rm -f "${pkg_config_file_path}.bak"
if [[ "$set_rpath" == "yes" ]]; then if [[ "$set_rpath" == "yes" ]]; then
patchelf --set-rpath '$ORIGIN' $lib_path # shellcheck disable=SC2016
patchelf --set-rpath '$ORIGIN' "$lib_path"
fi fi
done done

View File

@ -4,6 +4,7 @@
source "${BASH_SOURCE%/*}/../unix/InstallFromCompressedFileFromURL.sh" source "${BASH_SOURCE%/*}/../unix/InstallFromCompressedFileFromURL.sh"
# version 0.18.0 doesn't work correctly for Android binaries, so we use 0.17.2
patchelf_version="0.17.2" patchelf_version="0.17.2"
url_cached="https://ci-files01-hki.ci.qt.io/input/android/patchelf/$patchelf_version.tar.gz" url_cached="https://ci-files01-hki.ci.qt.io/input/android/patchelf/$patchelf_version.tar.gz"