From d5d62e04b9bca278999f43a1cbd9b19f3a8ca29f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 10 Jun 2026 00:41:06 +0300 Subject: [PATCH] tools: Add a script for updating the checkasm subtree Trim out any files we don't need downstream. Automate doing the subtree merges, and automate resolving the conflicts for updates for files that we want to have removed. If updates end up with other conflicts, the script (or in practice, git) exits without creating the intended merge commit - but regular updates should run automatically. --- tools/update-checkasm.sh | 71 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100755 tools/update-checkasm.sh diff --git a/tools/update-checkasm.sh b/tools/update-checkasm.sh new file mode 100755 index 0000000000..80eda113de --- /dev/null +++ b/tools/update-checkasm.sh @@ -0,0 +1,71 @@ +#!/bin/sh + +set -e + +UPDATE_COMMIT=${1:-master} + +cd $(dirname $0)/.. + +trim() { + cd tests/checkasm/ext + oldifs="$IFS" + # Set IFS to contain only a newline, no regular space, to make the + # for loop below properly handle file names with spaces. + IFS=" +" + for i in $(ls -A); do + case "$i" in + include|src|LICENSE) + # Keep these + ;; + *) + if ! git rm -rf "$i"; then + echo "Unable to trim out $i - untracked file?" + exit 1 + fi + ;; + esac + done + # Remove the meson files from the include/src subdirectories. + for i in $(find . -name meson.build); do + if ! git rm -f "$i"; then + echo "Unable to trim out $i - untracked file?" + exit 1 + fi + done + IFS="$oldifs" +} + +git update-index --refresh +if ! git diff-index --quiet HEAD --; then + echo Working tree has modifications - aborting. + exit 1 +fi + +orig_commit=$(git rev-parse HEAD) +if git subtree pull --squash --prefix=tests/checkasm/ext \ + -m "checkasm: Update from upstream" \ + https://code.ffmpeg.org/FFmpeg/checkasm.git ${UPDATE_COMMIT}; then + # Successfully merged updates (or no updates at all). + new_commit=$(git rev-parse HEAD) + trim + if [ "$orig_commit" = "$new_commit" ]; then + # Nothing merged from upstream + git commit -m "checkasm: Trim out unused upstream files" + else + # Merged new changes; amend the results from trimming the subtree, + # in case upstream added new files we don't need. + git commit --amend --no-edit + fi +else + # Failed merge - possibly due to conflicts, due to updates to files that + # we have trimmed out. Try removing those files again, with "git rm", + # and check if that was enough to resolve the conflicts. + trim + if ! git commit; then + echo "Committing trimmed output failed - are there remaining merge conflicts?" + exit 1 + else + echo "Resolved conflicts by re-trimming out files." + fi +fi