From 93e383fe19c84cfcb5298e69693fc1669735875f Mon Sep 17 00:00:00 2001 From: Thomas Guillem <thomas@gllm.fr> Date: Thu, 7 Jul 2022 10:13:03 +0200 Subject: [PATCH] add get-vlc.sh Moved from vlc-android/buildsystem/compile.sh VLC Hash, patches, and clone commands are now all in the same place. --- buildsystem/get-vlc.sh | 106 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100755 buildsystem/get-vlc.sh diff --git a/buildsystem/get-vlc.sh b/buildsystem/get-vlc.sh new file mode 100755 index 0000000..267961e --- /dev/null +++ b/buildsystem/get-vlc.sh @@ -0,0 +1,106 @@ +#! /bin/sh +set -e + +############# +# FUNCTIONS # +############# + +diagnostic() +{ + echo "$@" 1>&2; +} + +fail() +{ + diagnostic "$1" + exit 1 +} + +# Try to check whether a patch file has already been applied to the current directory tree +# Warning: this function assumes: +# - The patch file contains a Message-Id header. This can be generated with `git format-patch --thread ...` option +# - The patch has been applied with `git am --message-id ...` option to keep the Message-Id in the commit description +check_patch_is_applied() +{ + patch_file=$1 + diagnostic "Checking presence of patch $1" + message_id=$(grep -E '^Message-Id: [^ ]+' "$patch_file" | sed 's/^Message-Id: \([^\ ]+\)/\1/') + if [ -z "$message_id" ]; then + diagnostic "Error: patch $patch_file does not contain a Message-Id." + diagnostic "Please consider generating your patch files with the 'git format-patch --thread ...' option." + diagnostic "" + exit 1 + fi + if [ -z "$(git log --grep="$message_id")" ]; then + diagnostic "Cannot find patch $patch_file in tree, aborting." + diagnostic "There can be two reasons for that:" + diagnostic "- you forgot to apply the patch on this tree, or" + diagnostic "- you applied the patch without the 'git am --message-id ...' option." + diagnostic "" + exit 1 + fi +} + +RESET=0 +while [ $# -gt 0 ]; do + case $1 in + help|--help|-h) + echo "Use -b to bypass libvlc source checks (vlc custom sources)" + exit 0 + ;; + --reset) + RESET=1 + ;; + -b) + BYPASS_VLC_SRC_CHECKS=1 + ;; + *) + diagnostic "$0: Invalid option '$1'." + diagnostic "$0: Try --help for more information." + exit 1 + ;; + esac + shift +done + +#################### +# Fetch VLC source # +#################### + +VLC_TESTED_HASH=d7d51df095b1883d40856c5c315280dec495ea7a +VLC_REPOSITORY=https://code.videolan.org/videolan/vlc.git +VLC_BRANCH=4.0.x +if [ ! -d "vlc" ]; then + diagnostic "VLC sources: not found, cloning" + git clone "${VLC_REPOSITORY}" vlc -b ${VLC_BRANCH} --single-branch || fail "VLC sources: git clone failed" + cd vlc + diagnostic "VLC sources: resetting to the VLC_TESTED_HASH commit (${VLC_TESTED_HASH})" + git reset --hard ${VLC_TESTED_HASH} || fail "VLC sources: VLC_TESTED_HASH ${VLC_TESTED_HASH} not found" + diagnostic "VLC sources: applying custom patches" + # Keep Message-Id inside commits description to track them afterwards + git am --message-id ../libvlcjni/libvlc/patches/vlc3/*.patch || fail "VLC sources: cannot apply custom patches" + cd .. +else + diagnostic "VLC source: found sources, leaving untouched" +fi +if [ "$BYPASS_VLC_SRC_CHECKS" = 1 ]; then + diagnostic "VLC sources: Bypassing checks (required by option)" +elif [ $RESET -eq 1 ]; then + cd vlc + git reset --hard ${VLC_TESTED_HASH} || fail "VLC sources: VLC_TESTED_HASH ${VLC_TESTED_HASH} not found" + for patch_file in ../libvlcjni/libvlc/patches/vlc3/*.patch; do + git am --message-id $patch_file + check_patch_is_applied "$patch_file" + done + cd .. +else + diagnostic "VLC sources: Checking VLC_TESTED_HASH and patches presence" + diagnostic "NOTE: checks can be bypass by adding '-b' option to this script." + cd vlc + git cat-file -e ${VLC_TESTED_HASH} 2> /dev/null || \ + fail "Error: Your vlc checkout does not contain the latest tested commit: ${VLC_TESTED_HASH}" + for patch_file in ../libvlcjni/libvlc/patches/vlc3/*.patch; do + check_patch_is_applied "$patch_file" + done + cd .. +fi -- GitLab