Skip to content

Xbox Cloud Gaming app for PS5 Homebrew

C

check-platform-boundaries.sh: strings, every PS5 switch, no test folder allowed

Rafael Abud Ferreira9d4e17707f8d
diff --git a/AGENTS.md b/AGENTS.md
index a3f4bed..f8a861b 100644
--- a/AGENTS.md
+++ b/AGENTS.md
@@ -103,6 +103,6 @@ Para evitar degradação de desempenho, latência alta e manter a interação á
- O **PS5 é a plataforma principal**; Linux e Windows rodam o mesmo núcleo do app (`src/app/app_core.cpp`) com backends próprios. O mapa completo está em `docs/multiplatform.md`.
- **Toda alteração deve manter Linux e Windows compilando.** Uma funcionalidade exclusiva do PS5 vira no-op controlado por capacidade no desktop (`display::caps()`, `shell::canSelfUpdate()`...) ou tem a opção escondida — nunca quebra o build nem trava o app.
-- **NUNCA chame funções `sce*`, inclua headers do SDK do PS5 ou use `#if XCLOUD_PS5` fora dos arquivos de backend do PS5** (`*_ps5.cpp`, `src/platform/ps5/`, `src/display/gpu.cpp`). O script `tools/check-platform-boundaries.sh` verifica isso (também no CI).
+- **NUNCA chame funções `sce*`, inclua headers do SDK do PS5 ou use `XCLOUD_PS5` (ou outro teste de PS5) fora dos arquivos de backend do PS5** (`*_ps5.cpp`, `src/platform/ps5/`, `src/display/gpu.cpp`). O script `tools/check-platform-boundaries.sh` verifica isso (também no CI).
- Antes de considerar uma alteração pronta, compile os alvos de desktop (`ninja -C build-test` ou `build-host`, incluindo `psbox-headless`, e rode `xcloud-tests`), o app do PS5 (`ninja -C build-ps5 xcloud_app` + `bash tools/ps5/link.sh build-ps5`) e rode o script de fronteiras. Um link de desenvolvimento grava os símbolos em `symbols/vX.Y.Z-dev`; só o `tools/release.sh` grava `symbols/vX.Y.Z` (os da release, usados para decodificar crashes dos usuários).
- O fluxo de validação por screenshots no console (seção 2) continua obrigatório para mudanças de UI no PS5.
diff --git a/docs/multiplatform.md b/docs/multiplatform.md
index dc19481..36ad56f 100644
--- a/docs/multiplatform.md
+++ b/docs/multiplatform.md
@@ -30,8 +30,10 @@ plan to get there.
`cmake/platform.cmake` sets `XC_PLATFORM` and the `xc_platform` interface
target (linked by `xcloud_core`, so every target gets it):
`XC_PLATFORM_PS5`, `XC_PLATFORM_LINUX` or `XC_PLATFORM_WINDOWS`, and
-`XC_PLATFORM_DESKTOP` on the last two. They are for the rare spot that can't
-be split into backends; `XCLOUD_PS5` still works as before.
+`XC_PLATFORM_DESKTOP` on the last two. The desktop ones are for the rare spot
+that can't be split into backends; a test for the PS5 (`XC_PLATFORM_PS5`,
+`XCLOUD_PS5`, "not desktop") stays in the PS5 backends. `XCLOUD_PS5` still
+works as before.
## The app core
@@ -119,11 +121,13 @@ shared code:
## Rules for contributors
-1. No `sce*` call, PS5 SDK header (`<ps5platform/...>`) or `#if` on
- `XCLOUD_PS5` / `XC_PLATFORM_PS5` / `__PROSPERO__` outside the PS5 backends.
- `tools/check-platform-boundaries.sh` enforces it (CI runs it) and lists the
- allowed files; the legacy ones (`audio_out.cpp`, `audio_in.cpp`,
- `crash_guard.cpp`) carry a TODO naming the milestone that splits them.
+1. No `sce*` call, PS5 SDK header (`<ps5platform/...>`), `XCLOUD_PS5` /
+ `XC_PLATFORM_PS5` / `__PROSPERO__` / `__ORBIS__`, or `#if` on `__FreeBSD__`
+ or on "not `XC_PLATFORM_DESKTOP`" outside the PS5 backends.
+ `tools/check-platform-boundaries.sh` enforces it (CI runs it; comments
+ don't count) and lists the allowed files; the legacy ones (`audio_out.cpp`,
+ `audio_in.cpp`, `crash_guard.cpp`) carry a TODO naming the milestone that
+ splits them.
2. Something new that differs by platform: free functions in a portable
header, one file per backend (`*_ps5.cpp`, `*_null.cpp`, later
`*_sdl.cpp`), and the build lists which one each app links. A PS5-only
diff --git a/tools/check-platform-boundaries.sh b/tools/check-platform-boundaries.sh
index dbdcb6b..d99907d 100755
--- a/tools/check-platform-boundaries.sh
+++ b/tools/check-platform-boundaries.sh
@@ -6,8 +6,10 @@
# each line, when a file outside the list below has:
# - a PS5 system function (sceSomething),
# - a PS5 SDK header (#include <ps5platform/...>, <orbis/...>),
-# - an #if on the PS5 (XCLOUD_PS5, XC_PLATFORM_PS5, __PROSPERO__).
-# Mentions in // comments don't count. CI runs it on every push; locally:
+# - a PS5 switch: XCLOUD_PS5, XC_PLATFORM_PS5, __PROSPERO__ or __ORBIS__
+# anywhere, or an #if on __FreeBSD__ or on "not XC_PLATFORM_DESKTOP".
+# Comments don't count (a "//" inside a string doesn't start one). CI runs
+# it on every push; locally:
# bash tools/check-platform-boundaries.sh
set -euo pipefail
@@ -15,13 +17,13 @@ root=$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)
cd "$root"
# The files allowed to talk to the PS5 directly (globs on the path from the
-# repository's root; * also crosses folders).
+# repository's root; * also crosses folders). A test that fakes PS5 calls
+# goes here by its exact name.
allowed=(
'src/platform/ps5/*' # the PS5's platform layer
'src/*_ps5.cpp' # PS5 backends: display, controller, kbm, hw_decoder, shell...
'src/display/gpu.cpp' # RADV on the PS5 (the GPU path only the PS5 builds)
'ps5/*' # link stubs and compat headers for the PS5 SDK
- 'tests/*_ps5*' # tests that fake PS5 calls (none yet)
# Legacy: these still pick their PS5 code with #if. Each comes off the
# list once it is split into a PS5 backend and a portable part.
'src/media/audio_out.cpp' # TODO(M1): portable AudioQueue + audio_out_ps5.cpp / an SDL backend
@@ -38,29 +40,49 @@ is_allowed() {
return 1
}
-# Perl regular expressions; (?:(?!//).)*? keeps a match out of // comments.
-code='^(?:(?!//).)*?'
-patterns=(
- "${code}\\bsce[A-Z][A-Za-z0-9_]*"
- '^\s*#\s*include\s*[<"](ps5platform|orbis)/'
- '^\s*#\s*(if|ifdef|ifndef|elif)\b.*\b(XCLOUD_PS5|XC_PLATFORM_PS5|__PROSPERO__)\b'
-)
-
-found=0
+files=()
while IFS= read -r -d '' file; do
file=${file#./}
- is_allowed "$file" && continue
- for pattern in "${patterns[@]}"; do
- if hits=$(grep -nP -- "$pattern" "$file"); then
- while IFS= read -r hit; do
- echo "$file:$hit"
- done <<< "$hits"
- found=1
- fi
- done
+ is_allowed "$file" || files+=("$file")
done < <(find src tests ps5 -type f \( -name '*.c' -o -name '*.cc' -o -name '*.cpp' -o -name '*.h' -o -name '*.hpp' \) -print0 | sort -z)
-if (( found )); then
+# Each file with its comments blanked (newlines kept, so the line numbers
+# hold). String and character literals are stepped over whole, so what they
+# hold can't open or close a comment; their text is still checked.
+# shellcheck disable=SC2016 # Perl code, not shell
+scan='
+use strict;
+use warnings;
+my @rules = (
+ qr/\bsce[A-Z][A-Za-z0-9_]*/,
+ qr/^\s*#\s*include\s*[<"](?:ps5platform|orbis)\//,
+ qr/\b(?:XCLOUD_PS5|XC_PLATFORM_PS5|__PROSPERO__|__ORBIS__)\b/,
+ qr/^\s*#\s*(?:if|ifdef|ifndef|elif|elifdef|elifndef)\b.*\b__FreeBSD__\b/,
+ qr/^\s*#\s*(?:ifndef|elifndef)\s+XC_PLATFORM_DESKTOP\b/,
+ qr/^\s*#\s*(?:if|elif)\b.*!\s*(?:defined\s*\(?\s*)?XC_PLATFORM_DESKTOP\b/,
+);
+my $found = 0;
+for my $file (@ARGV) {
+ open(my $fh, "<", $file) or die "$file: $!\n";
+ my $src = do { local $/; <$fh> };
+ close $fh;
+ my @lines = split /\n/, $src, -1;
+ (my $code = $src) =~ s{
+ ( (?<!\w)(?:u8|[uUL])?R"([^()\\\s]{0,16})\(.*?\)\2" | "(?:\\.|[^"\\\n])*" | \x27(?:\\.|[^\x27\\\n])*\x27 )
+ | ( //[^\n]* | /\*.*?\*/ )
+ }{ defined $3 ? ($3 =~ s/[^\n]/ /gr) : $1 }gsex;
+ my $n = 0;
+ for my $line (split /\n/, $code, -1) {
+ ++$n;
+ next unless grep { $line =~ $_ } @rules;
+ print "$file:$n:$lines[$n - 1]\n";
+ $found = 1;
+ }
+}
+exit $found;
+'
+
+if (( ${#files[@]} )) && ! perl -e "$scan" -- "${files[@]}"; then
echo "PS5 code outside the PS5 backends (above). Move it into a *_ps5.cpp backend behind a" >&2
echo "portable header, or see docs/multiplatform.md; tools/check-platform-boundaries.sh lists" >&2
echo "the files allowed to have it." >&2