Files
RetroArch/samples/menu/setting_command/build.sh
Davey Hughes 2fb077f223 menu: a setting's command fires once per press (#19730)
menu_action_handle_setting() calls the row's handler and then
menu_setting_generic(), and both run the change handler. A handler
that runs it itself, as the boolean ones and Start do, fired the
row's command twice: once through SD_FLAG_CMD_APPLY_AUTO, or through
SD_FLAG_CMD_TRIGGER_EVENT_TRIGGERED, which stays set after a row's
first press, and once more from menu_setting_generic(). Toggling a
boolean with CMD_EVENT_REINIT, such as Bilinear Filtering from its
second press on, reinitialised the video driver twice.

The row carries neither flag while its handler runs, so the command
fires from menu_setting_generic() alone.

Still twice: set_path_generic() and menu_input_st_string_cb(), which
run the change handler before menu_setting_generic() themselves, and
the rows general_write_handler() picks the command for, such as the
audio ones.

samples/menu/setting_command presses two such rows on the null video
driver with OK, right, left and Start, and counts its inits.
2026-10-07 06:15:31 +02:00

70 lines
2.5 KiB
Bash
Executable File

#!/bin/sh
# Builds the one-command-per-press harness.
#
# Like playlist_nav, this links the SHIPPING objects of a built
# RetroArch with only main() replaced, so a press on a settings row
# runs the real dispatcher, the row's real handlers and the real
# reinit; only the null video driver's init is swapped at run time,
# to count how often it runs.
#
# Requires a completed NON-Qt build: with Qt enabled main() lives in
# ui_qt.o, which drags the whole Qt UI in with it. From the repo
# root:
#
# ./configure --disable-qt && make
# samples/menu/setting_command/build.sh
#
# retroarch.c is recompiled here with main renamed, so the harness can
# supply its own without having to exclude the object that holds most
# of the frontend. Both the compile and the link reuse the project's
# own command lines, taken from make -n, so the harness cannot drift
# away from how the program is really built.
set -eu
here=$(cd "$(dirname "$0")" && pwd)
root=$(cd "$here/../../.." && pwd)
cd "$root"
if [ ! -f obj-unix/release/retroarch.o ]; then
echo "build RetroArch first: ./configure --disable-qt && make" >&2
exit 1
fi
cc_line=$(mktemp)
ld_line=$(mktemp)
trap 'rm -f "$cc_line" "$ld_line"' EXIT
# The project's own compile line for retroarch.o ...
touch retroarch.c
make -n 2>/dev/null | grep -E '\-o obj-unix/release/retroarch\.o' | head -1 > "$cc_line"
if [ ! -s "$cc_line" ]; then
echo "could not determine the compile command for retroarch.o" >&2
exit 1
fi
# ... reused twice: once for retroarch.c with main renamed out of the
# way, once for the harness itself, so both are built exactly the way
# the frontend is.
sed 's#-o obj-unix/release/retroarch\.o#-Dmain=rarch_harness_unused_main -o samples/menu/setting_command/retroarch_nomain.o#' \
"$cc_line" | sh
sed -e 's#-o obj-unix/release/retroarch\.o#-o samples/menu/setting_command/harness_main.o#' \
-e 's# retroarch\.c# samples/menu/setting_command/setting_command_test.c#' \
"$cc_line" | sh
# The project's own link line, with retroarch.o swapped for the pair
# above. Removing the binary first is what makes make -n emit it.
rm -f retroarch
make -n 2>/dev/null | grep -E ' -o retroarch ' | tail -1 > "$ld_line"
if [ ! -s "$ld_line" ]; then
echo "could not determine the link command" >&2
exit 1
fi
sed -e 's#obj-unix/release/retroarch\.o#samples/menu/setting_command/retroarch_nomain.o samples/menu/setting_command/harness_main.o#' \
-e 's#-o retroarch #-o samples/menu/setting_command/setting_command_test #' \
"$ld_line" | sh
echo "built samples/menu/setting_command/setting_command_test"