From af759804fdc6b657dae7316118730b34f5ed32aa Mon Sep 17 00:00:00 2001 From: Stackrats Date: Mon, 28 Sep 2026 21:57:28 +0700 Subject: [PATCH] Leave the AppImage GTK hook alone when X11 is only a comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The v0.7.4 Linux release builds failed in "Fix the AppImage for Wayland hosts": the script reported rewriting the GTK hook, then its own check found the forced-X11 line still there and refused the AppImage. Tauri's CLI now bundles its own copy of linuxdeploy-plugin-gtk (tauri-apps/tauri#16062), and that hook carries the line commented out: `# export GDK_BACKEND=x11`. The script matched the text anywhere on a line, so the comment counted as forcing X11; the rewrite only replaced a line starting with the export, so it changed nothing, and the verification matched the same comment again. Only an active export forces X11, so detection, rewrite and verification now all match that — at any indentation, never inside a comment. A hook that leaves GDK_BACKEND unset already gets GTK's Wayland-then-X11 choice and passes through byte for byte. The regression test gains both cases: Tauri's commented hook is left unchanged with GDK_BACKEND unset, and an indented export is still rewritten. Against the old script both fail. Run over a real AppImage carrying Tauri's hook, the old script fails exactly as CI did, and the new one repacks and verifies it. --- scripts/fix-appimage-wayland.sh | 20 ++++++++---- scripts/test-fix-appimage-wayland.sh | 48 ++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/scripts/fix-appimage-wayland.sh b/scripts/fix-appimage-wayland.sh index 02a2c94..34cead3 100755 --- a/scripts/fix-appimage-wayland.sh +++ b/scripts/fix-appimage-wayland.sh @@ -36,6 +36,11 @@ # next real resize. The hook is rewritten to prefer Wayland and fall back to # X11, and to let a GDK_BACKEND the user has already exported win. # +# Tauri's CLI now ships its own copy of the plugin (tauri-apps/tauri#16062), +# whose hook carries the line commented out — `# export GDK_BACKEND=x11`. Only +# an active export forces X11, so only that is rewritten; a hook that leaves +# GDK_BACKEND unset already gets GTK's own Wayland-then-X11 choice. +# # Usage: # scripts/fix-appimage-wayland.sh [more...] strip and repack # scripts/fix-appimage-wayland.sh --strip-only strip in place @@ -54,9 +59,10 @@ STRIP_LIBS=( libwayland-server.so.0 ) -# The hook the GTK plugin writes, and the line in it that forces X11. +# The hook the GTK plugin writes, and the line in it that forces X11: an +# active export, not the same text inside a comment. GTK_HOOK=apprun-hooks/linuxdeploy-plugin-gtk.sh -GDK_FORCED_X11='export GDK_BACKEND=x11' +GDK_FORCED_X11='^[[:space:]]*export[[:space:]]+GDK_BACKEND=x11([[:space:]]|$)' GDK_PREFER_WAYLAND='export GDK_BACKEND="${GDK_BACKEND:-wayland,x11}" # rewritten by fix-appimage-wayland.sh: native Wayland where it exists, X11 otherwise, and an exported value wins' info() { printf '\033[1;34m==>\033[0m %s\n' "$*"; } @@ -85,11 +91,11 @@ strip_appdir() { prefer_wayland() { local hook="$1/$GTK_HOOK" [[ -f "$hook" ]] || { printf '0'; return 0; } - if grep -qF "$GDK_FORCED_X11" "$hook"; then - # Whole-line replacement on the exact export, via awk rather than sed so - # the replacement's $ and " need no escaping. + if grep -qE "$GDK_FORCED_X11" "$hook"; then + # Whole-line replacement of the export, via awk rather than sed so the + # replacement's $ and " need no escaping. awk -v from="$GDK_FORCED_X11" -v to="$GDK_PREFER_WAYLAND" \ - 'index($0, from) == 1 { print to; next } { print }' "$hook" > "$hook.tmp" \ + '$0 ~ from { print to; next } { print }' "$hook" > "$hook.tmp" \ && mv "$hook.tmp" "$hook" printf ' rewrote %s\n' "$GTK_HOOK" >&2 printf '1' @@ -181,7 +187,7 @@ for IMG in "$@"; do find "$VERIFY/squashfs-root" -name 'libwebkit2gtk-4.1.so.0' | grep -q . \ || die "libwebkit2gtk missing from the repacked AppImage — bad repack." if [[ -f "$VERIFY/squashfs-root/$GTK_HOOK" ]]; then - grep -qF "$GDK_FORCED_X11" "$VERIFY/squashfs-root/$GTK_HOOK" \ + grep -qE "$GDK_FORCED_X11" "$VERIFY/squashfs-root/$GTK_HOOK" \ && die "the GTK hook still forces GDK_BACKEND=x11 after the repack." fi diff --git a/scripts/test-fix-appimage-wayland.sh b/scripts/test-fix-appimage-wayland.sh index 6fa165c..6cd3c23 100755 --- a/scripts/test-fix-appimage-wayland.sh +++ b/scripts/test-fix-appimage-wayland.sh @@ -14,6 +14,8 @@ # * both AppDir layouts are handled (usr/lib and usr/lib/) # * the GTK plugin's hook stops forcing GDK_BACKEND=x11, prefers Wayland, # and still lets a user's own exported GDK_BACKEND win +# * a hook that only mentions the export in a comment (Tauri's bundled +# plugin) is left alone, and an indented export is still caught # * a second run is a clean no-op rather than an error # * a missing AppDir fails loudly instead of silently succeeding # @@ -138,6 +140,52 @@ else fail "the rewrite disturbed lines other than the GDK_BACKEND export" fi +# ---------------------------------------------------------------- case 2c --- +# Tauri's CLI ships its own copy of the plugin, and its hook has the line +# commented out. That forces nothing: the hook must come through byte for +# byte, and GDK_BACKEND stays unset for GTK to choose. Matching the text +# inside the comment is what failed the v0.7.4 Linux release build. +C="$T/Commented" +mkdir -p "$C/apprun-hooks" +cat > "$C/apprun-hooks/linuxdeploy-plugin-gtk.sh" <<'HOOK' +#! /usr/bin/env bash +export GTK_THEME="$APPIMAGE_GTK_THEME" # Custom themes are broken +# export GDK_BACKEND=x11 # Monitor this closely. AppImage used to crash on Wayland! +export XDG_DATA_DIRS="$APPDIR/usr/share:/usr/share:$XDG_DATA_DIRS" # g_get_system_data_dirs() from GLib +HOOK +cp "$C/apprun-hooks/linuxdeploy-plugin-gtk.sh" "$T/commented-before.sh" +out=$(bash "$SCRIPT" --strip-only "$C" 2>&1) || fail "strip-only exited non-zero on a commented hook" +if [[ "$out" == *"hook rewritten: 0"* ]] \ + && cmp -s "$T/commented-before.sh" "$C/apprun-hooks/linuxdeploy-plugin-gtk.sh"; then + pass "a commented-out export is left alone" +else + fail "a hook whose export is only a comment was changed ($out)" +fi +got=$(backend_after "$C/apprun-hooks/linuxdeploy-plugin-gtk.sh") +if [[ -z "$got" ]]; then + pass "the commented hook leaves GDK_BACKEND for GTK to choose" +else + fail "expected GDK_BACKEND unset after the commented hook, got '$got'" +fi + +# An active export does not have to start in column one — inside an `if` it +# is indented, and it forces X11 all the same. +I="$T/Indented" +mkdir -p "$I/apprun-hooks" +cat > "$I/apprun-hooks/linuxdeploy-plugin-gtk.sh" <<'HOOK' +#! /usr/bin/env bash +if true; then + export GDK_BACKEND=x11 +fi +HOOK +bash "$SCRIPT" --strip-only "$I" >/dev/null 2>&1 || fail "strip-only exited non-zero on an indented hook" +got=$(backend_after "$I/apprun-hooks/linuxdeploy-plugin-gtk.sh") +if [[ "$got" == "wayland,x11" ]]; then + pass "an indented export is rewritten too" +else + fail "expected GDK_BACKEND=wayland,x11 after an indented export, got '$got'" +fi + # ---------------------------------------------------------------- case 3 ---- # Idempotency: re-running over an already-clean AppDir must succeed quietly, # because the release workflow may be re-run against the same artefacts.