From 5211106b49e811280bc47e7c22193b9922e769ea Mon Sep 17 00:00:00 2001 From: XargonWan Date: Tue, 10 Dec 2024 11:11:32 +0900 Subject: [PATCH] POST_BUILD_CHECK: reworked to run everything from inside the flatpak, improved logging and output --- automation_tools/post_build_check.sh | 64 ++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/automation_tools/post_build_check.sh b/automation_tools/post_build_check.sh index 1a7a31a1..17f0655f 100755 --- a/automation_tools/post_build_check.sh +++ b/automation_tools/post_build_check.sh @@ -1,31 +1,65 @@ #!/bin/bash -# todo create launch test commands ie mame -help, ruffle --version +# This script runs entirely inside the Flatpak sandbox for net.retrodeck.retrodeck +# Flatpak App ID +FLATPAK_APP_ID="net.retrodeck.retrodeck" -# Log file -LOG_FILE="$HOME/check.log" +# Log file inside the Flatpak sandbox +LOG_FILE="$HOME/retrodeck-post-build-check.log" # Clear previous log > "$LOG_FILE" +# Ensure global.sh is sourced inside the Flatpak sandbox +GLOBAL_SH_PATH="/app/libexec/global.sh" + +# Check if the global.sh script exists +if ! flatpak run --command=ls "$FLATPAK_APP_ID" "$GLOBAL_SH_PATH" &> /dev/null; then + echo "✗ global.sh not found at $GLOBAL_SH_PATH" | tee -a "$LOG_FILE" + exit 1 +fi + +# Source global.sh to load the `features` variable +echo "Sourcing $GLOBAL_SH_PATH to load features" | tee -a "$LOG_FILE" +features=$(flatpak run --command=bash "$FLATPAK_APP_ID" -c "source $GLOBAL_SH_PATH && echo \$features") + +# Ensure `features` variable is set +if [ -z "$features" ]; then + echo "✗ Failed to load features from $GLOBAL_SH_PATH" | tee -a "$LOG_FILE" + exit 1 +fi + # Extract launch commands using jq -commands=($(jq -r '.emulator | to_entries[] | .value.launch' /app/retrodeck/config/retrodeck/reference_lists/features.json)) +echo "Extracting launch commands from $features" | tee -a "$LOG_FILE" +commands=($(flatpak run --command=jq "$FLATPAK_APP_ID" -r '.emulator | to_entries[] | .value.launch' "$features")) +echo "Extracted launch commands: ${commands[@]}" | tee -a "$LOG_FILE" # Timeout duration in seconds -TIMEOUT=5 +TIMEOUT=3 # Function to run command with timeout run_and_check() { - local cmd="flatpak run net.retrodeck.retrodeck $1" + local cmd="$1" + + echo "Validating command: \"$cmd\"" | tee -a "$LOG_FILE" - # Verify command exists - if ! command -v "$cmd" &> /dev/null; then + # Verify command exists within the Flatpak sandbox + if ! flatpak run --command=which "$FLATPAK_APP_ID" "$cmd" &> /dev/null; then echo "✗ Command not found: $cmd (Exit Code: 127)" | tee -a "$LOG_FILE" return 127 fi - # Run command with timeout - timeout -s TERM $TIMEOUT "$cmd" + # Run command with timeout inside the sandbox + flatpak run --command=timeout "$FLATPAK_APP_ID" -s TERM $TIMEOUT "$cmd" &> /dev/null & + local pid=$! + sleep $TIMEOUT + + # Ensure the process is terminated + if kill -0 $pid 2>/dev/null; then + #echo "✗ $cmd did not terminate, killing process" | tee -a "$LOG_FILE" + kill -9 $pid + fi + local exit_code=$? # Log the results @@ -39,7 +73,7 @@ run_and_check() { echo "✗ $cmd terminated after $TIMEOUT seconds" | tee -a "$LOG_FILE" ;; 137) - echo "✗ $cmd killed" | tee -a "$LOG_FILE" + echo "✗ $cmd killed after timeout" | tee -a "$LOG_FILE" ;; *) echo "✗ $cmd failed" | tee -a "$LOG_FILE" @@ -49,7 +83,11 @@ run_and_check() { return $exit_code } -# Execute commands +# Execute commands inside the Flatpak sandbox for cmd in "${commands[@]}"; do run_and_check "$cmd" -done \ No newline at end of file +done + +echo "$LOG_FILE" + +grep "✗" "$LOG_FILE" \ No newline at end of file