mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-20 13:26:02 +00:00
Merge upstream main and close diagnostic publication races
This commit is contained in:
473 files changed
+36063
-3507
No files matched your search
@@ -0,0 +1,40 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
missing=()
|
||||
for package in "$@"; do
|
||||
if [ "$(dpkg-query -W -f='${Status}' "$package" 2>/dev/null || true)" != 'install ok installed' ]; then
|
||||
missing+=("$package")
|
||||
fi
|
||||
done
|
||||
if [ "${#missing[@]}" = 0 ]; then
|
||||
echo "Ubuntu build dependencies are already installed."
|
||||
exit 0
|
||||
fi
|
||||
options=(
|
||||
-o Dir::Etc::sourcelist=sources.list.d/ubuntu.sources
|
||||
-o Dir::Etc::sourceparts=-
|
||||
-o Acquire::Retries=1
|
||||
-o Acquire::http::Timeout=15
|
||||
-o Acquire::https::Timeout=15
|
||||
-o DPkg::Lock::Timeout=30
|
||||
)
|
||||
install_packages() {
|
||||
echo "Updating Ubuntu package indexes."
|
||||
sudo timeout --kill-after=10s 60s apt-get "${options[@]}" -o APT::Update::Error-Mode=any update -q || return $?
|
||||
echo "Installing: ${missing[*]}"
|
||||
sudo timeout --kill-after=10s 120s env DEBIAN_FRONTEND=noninteractive NEEDRESTART_MODE=a apt-get "${options[@]}" install -y -q --no-install-recommends "${missing[@]}"
|
||||
}
|
||||
if install_packages; then
|
||||
exit 0
|
||||
fi
|
||||
echo "::warning::Runner mirror failed or timed out; retrying with the official Ubuntu mirror."
|
||||
sources=$(mktemp --suffix=.sources)
|
||||
trap 'rm -f "$sources"' EXIT
|
||||
mirror=https://archive.ubuntu.com/ubuntu
|
||||
case "$(dpkg --print-architecture)" in
|
||||
arm64) mirror=https://ports.ubuntu.com/ubuntu-ports ;;
|
||||
esac
|
||||
sed -E "s@^URIs:.*@URIs: $mirror@" /etc/apt/sources.list.d/ubuntu.sources > "$sources"
|
||||
chmod 644 "$sources"
|
||||
options[1]="Dir::Etc::sourcelist=$sources"
|
||||
install_packages
|
||||
@@ -0,0 +1,16 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
repo=$(cd "$(dirname "$0")/../.." && pwd)
|
||||
source "$repo/tools/ci/toolchains.env"
|
||||
ndk="$ANDROID_HOME/ndk/$CI_ANDROID_NDK_VERSION"
|
||||
if [ ! -f "$ndk/source.properties" ]; then
|
||||
sdkmanager --sdk_root="$ANDROID_HOME" --install "ndk;$CI_ANDROID_NDK_VERSION"
|
||||
fi
|
||||
actual=$(sed -n 's/^Pkg.Revision *= *//p' "$ndk/source.properties" | tr -d '\r')
|
||||
test "$actual" = "$CI_ANDROID_NDK_VERSION"
|
||||
{
|
||||
echo "NDK_VERSION=$actual"
|
||||
echo "ANDROID_NDK_HOME=$ndk"
|
||||
echo "ANDROID_NDK_ROOT=$ndk"
|
||||
echo "ANDROID_NDK_LATEST_HOME=$ndk"
|
||||
} >> "$GITHUB_ENV"
|
||||
@@ -0,0 +1 @@
|
||||
CI_ANDROID_NDK_VERSION=30.0.16248370
|
||||
@@ -0,0 +1,65 @@
|
||||
# Runtime component preparation
|
||||
|
||||
`recipes.json` owns component source inputs, builders, outputs, package requirements
|
||||
and pinned downloads. `prepare.py` runs those recipes, calculates cache identities,
|
||||
installs the union of missing tools and verifies the prepared artifact handoff.
|
||||
Builders live in `recipes/`; the workflow describes scheduling and gates.
|
||||
|
||||
```mermaid
|
||||
flowchart LR
|
||||
Source[Pin source tree] --> Components[Prepare verified components]
|
||||
Source --> Xbox[Xbox ARM64 backend]
|
||||
Source --> Tests[Python and native tests]
|
||||
Components --> APK[Compile APK and Android tests]
|
||||
Xbox --> APK
|
||||
APK --> Gate[Compile and test APK gate]
|
||||
Tests --> Gate
|
||||
Gate --> Publish[Main only: signing and publishing]
|
||||
```
|
||||
|
||||
All workers verify the same source tree. The component artifact records that tree,
|
||||
recipe identities and every output hash; the APK worker verifies the inventory
|
||||
before building. This handoff verifies consistency within the same CI run. It is
|
||||
not independent provenance for arbitrary artifacts. Source policy checks, tests,
|
||||
APK content/ABI checks and signing/publication gates remain in place.
|
||||
|
||||
`tools/ci/toolchains.env` pins the Android NDK shared by component, APK and native
|
||||
test workers. Linux builds use Ubuntu 24.04. Recipe and input changes invalidate
|
||||
the relevant component cache; ordinary caches remain performance aids.
|
||||
|
||||
## Verified preload snapshots
|
||||
|
||||
`preloads.lock.json` pins a small immutable preload archive. It records each
|
||||
binary's hash, its producing main CI run, the original APK artifact identity and
|
||||
digest, source/header hashes, the ARM64 build recipe and x86 compiler-image inputs.
|
||||
It covers core ARM64 preloads and the x86 preload libraries. VR, Android native
|
||||
libraries, Comet and Xbox use their registered recipes and existing release pins
|
||||
or component caches.
|
||||
|
||||
Every build compares current source inputs, including transitive quoted headers,
|
||||
and build recipes with this manifest. Changed groups rebuild from source. A
|
||||
missing release also selects a rebuild. Corrupt archives, unexpected files and
|
||||
binary hash mismatches fail the build. Existing preload checks, runtime packaging
|
||||
checks and all test jobs still run.
|
||||
|
||||
The trust anchor is the manifest in the pinned main base. A new or changed PR
|
||||
manifest is independently checked against a successful `push` build of main:
|
||||
GitHub must confirm the run/source/workflow and original APK artifact digest, and
|
||||
every claimed binary must match that APK. The claimed source inputs and recipe
|
||||
must match that run's Git source. A PR cannot establish trust by changing both a
|
||||
binary and its claimed checksum. This is approved-build reuse, not a claim of
|
||||
bit-for-bit reproducible compilation or a signed SLSA attestation.
|
||||
|
||||
To refresh after source or compiler changes:
|
||||
|
||||
1. Let a main build compile and test the new inputs.
|
||||
2. Run `python tools/components/preloads.py snapshot --run RUN_ID`.
|
||||
3. Publish `app/build/component-snapshot/preloads.tar.gz` to
|
||||
DroidDeck-Components as `preloads-<full archive SHA-256>`, without replacing an
|
||||
existing release. Include the manifest and producing run in the release notes.
|
||||
4. Review and commit the updated manifest. CI independently checks its origin.
|
||||
|
||||
The workflow dispatch `rebuild_preloads` option forces source compilation even
|
||||
when an approved snapshot matches. Use it when refreshing a compiler or system
|
||||
header revision. Runner image updates do not silently replace an approved binary;
|
||||
the producing run remains the record of its compiler environment.
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
D=${1:?output directory}
|
||||
mkdir -p "$D"
|
||||
aarch64-linux-gnu-g++ -shared -fPIC -O2 -Wall -Wno-attributes -Wno-nonnull-compare \
|
||||
-pthread -std=c++17 -static-libstdc++ -static-libgcc -Wl,--exclude-libs,ALL \
|
||||
-o "$D/libfakeinput.so" app/src/main/cpp/fakeinput_steam.cpp -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$D/libfakeinput.so"
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -pthread \
|
||||
-o "$D/libblsession.so" tools/linuxfs/preload/*.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$D/libblsession.so"
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -pthread \
|
||||
-o "$D/libblfastpath.so" tools/proot/fastpath/fastpath.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$D/libblfastpath.so"
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -nostdlib -ffreestanding -fno-stack-protector \
|
||||
-fno-tree-loop-distribute-patterns -Wl,-z,defs -o "$D/libblaudit.so" tools/proot/fastpath/audit.c
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$D/libblaudit.so"
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -pthread \
|
||||
-o "$D/libssbs.so" tools/linuxfs/ssbs/ssbs_adapter.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$D/libssbs.so"
|
||||
mkdir -p "$D/usr/local/bin"
|
||||
aarch64-linux-gnu-gcc -O2 -Wall -Wextra -o "$D/usr/local/bin/droiddeck-clipboard" tools/linuxfs/clipboard/clipboard.c -ldl
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$D/usr/local/bin/droiddeck-clipboard"
|
||||
@@ -0,0 +1,126 @@
|
||||
{
|
||||
"archive_sha256": "cb6487a94f25a3068fd07958174eb5b5e14f709655ff4ef0a8cdbd99138513b2",
|
||||
"arm64_recipe": "1c92a1b0669277de3e78e9f292634affb5b5a19d5ea49d3ad8610c1dc638c2fb",
|
||||
"groups": {
|
||||
"arm64": {
|
||||
"@runner": "84f825635599f81ed33f62c5fc4c73f66044d1468b060d65f83855eb9c8bfe77",
|
||||
"app/src/main/cpp/adrenotools/src/hook/kgsl.h": "396c56761034a4ed783543ee3312c6ec64d63b2a1cf7eecf1939c23251f25adf",
|
||||
"app/src/main/cpp/fakeinput_steam.cpp": "3d11e859ca58a42a9da92a3fc589d404df790e151f7e18ea6114645750e70ef5",
|
||||
"app/src/main/cpp/venc/venc_proto.h": "2242ddbc8981d14a33bac70264bb3e7f701fd1c3ebb988e17bbb2b19b6b808f7",
|
||||
"tools/linuxfs/clipboard/clipboard.c": "96291c2bbc040c83caabf059ab3e95a9ed90d6a768c759d7cb4c0b64706bddfa",
|
||||
"tools/linuxfs/preload/binfmt.c": "0933cc49cb53f0aa1206e2eae516d38dc3337e74174be07e10619c42aa56792b",
|
||||
"tools/linuxfs/preload/dircache.c": "8e7f19ea4a1198783d53a3f357326c6177da157b0cc7e0d22e1670963e1c26e7",
|
||||
"tools/linuxfs/preload/drm.c": "e0eabab0d8ed9e841918e827bf87168efa7f2dfb8404169e9bed3ab5eda2836c",
|
||||
"tools/linuxfs/preload/fsync.c": "795c114c2a05d3f250d07145d04c5658091699da3b96290da36348ccadfb0c09",
|
||||
"tools/linuxfs/preload/inputudev.c": "2648248d3d235a582eb8459709e0a85de537c03ac10c5040fbfb50d9846c68eb",
|
||||
"tools/linuxfs/preload/kgslid.c": "88a7875fd5289930204d155d92ac9d15492cd06db16ed87aa9c95af37f3e7089",
|
||||
"tools/linuxfs/preload/kgslpoll.c": "f0d853d919a52487c04cbda5fb3fa22269da54b7f4ee2f7dd3b5bd9909418670",
|
||||
"tools/linuxfs/preload/links.c": "b7bbcf9112393b152f358fe6f8dc9a1955f0c8532e1eddf016a971415cd13c64",
|
||||
"tools/linuxfs/preload/lock.c": "f71b3fd40e6a2b74908d3cdc601e8748699ae9c7a89b542d2445b999015ffd66",
|
||||
"tools/linuxfs/preload/net.c": "335853c8ea0e9a8ebbc5a5500dc4bded9c34c4310a6ab8aa46b07d5ce1c2b55e",
|
||||
"tools/linuxfs/preload/netif.c": "cc26d50b8d4639d8dd4697811bbf85c9d9f31761f9504a4af42473de3cb22b3c",
|
||||
"tools/linuxfs/preload/noexec.c": "1855aeaeda3d506329bd9af1107580c74d1f56787c411b2e01c0a8a9d4059c7b",
|
||||
"tools/linuxfs/preload/ntsync.c": "0614c48af0c062bfcb4c30141efe1b792b340767a67d2fe92ee9877d2ba16e0d",
|
||||
"tools/linuxfs/preload/opens.c": "92ae4aea16aa457a898dedf4a70eb332d80d3b1e77f3a60bace7715a4317399e",
|
||||
"tools/linuxfs/preload/pathcache.c": "eb0d4b5238fe6c8891e805d90bd837e466754100c978fad2d0ff717116b9b8a3",
|
||||
"tools/linuxfs/preload/perms.c": "f600619c4ca130f69001ed7ad7bd74a3dc215b14c61479c45bb770f916d244b9",
|
||||
"tools/linuxfs/preload/pulseguard.c": "57674ea40283e53a27bc78362de1ba41ee972d172ea38b1f818b1d6eed0abe65",
|
||||
"tools/linuxfs/preload/quest_kgsl.c": "59d9b8416be6a1c680f1d1e4c2427d2cbb7b415344261adb357d9d211ec95cfe",
|
||||
"tools/linuxfs/preload/robust.c": "9eb6c0ed50e0f48a8cfb86bd92587f471354bdf2531b9177f4b3ab83bdfed39a",
|
||||
"tools/linuxfs/preload/rptouch.c": "0e3f8bf2f9a41324361f38fa4da8d2d47593c9555f0cabf8228767397846c7c3",
|
||||
"tools/linuxfs/preload/space.c": "118389bcc89dfa2b4230b80915e21d2d4331c4cff1f5a58265f85e6ecb5c29d2",
|
||||
"tools/linuxfs/preload/storage.c": "08a8b46c3588f3160bb8608489768010ec36d5ccdb2b25a431ec9d6fcd413a6e",
|
||||
"tools/linuxfs/preload/sysv.c": "49774ee5e2e39b84dcfadf63abdc741b3df236cb11783744a1280adee36965e8",
|
||||
"tools/linuxfs/preload/tracefs.c": "be3f8a2f032b56e6e08a931e77a9386aea4bb93421a482271e06386ec0c469b6",
|
||||
"tools/linuxfs/preload/tracer.c": "f34e5377c891b0a8d00489245d66f96bc352df4cd90f47a951dcadae980af4c1",
|
||||
"tools/linuxfs/preload/udevmon.c": "2045dfb883cfb6e2016c359a3dc3af17f3b8f383f6dd0d5dfee407ef0d344852",
|
||||
"tools/linuxfs/preload/usr2.c": "6ae704380b45a9b3a74c4fe2b3ce4482470dae59ced26cf0aee64f4b4dcc11f9",
|
||||
"tools/linuxfs/preload/venc.c": "24c3c46fe49d28adfc8c977e52c9cc407f534b26f56d94b3425b8bb01803dba8",
|
||||
"tools/linuxfs/preload/vmwrite.c": "1a3ea2ec4354e0716c17f7db537b19ab82bcd524f2aece2fa5dec89b076a2188",
|
||||
"tools/linuxfs/preload/webhelper.c": "a8213a7a96b407459c83fb93365cfe58fd05964e7bb262b8061c1c0792a6aac8",
|
||||
"tools/linuxfs/preload/writewatch.c": "61e395d1caa184d329dead0e36c4e92cb1069b1154ac36581f37406c1c242240",
|
||||
"tools/linuxfs/preload/xmode.c": "9a09995bf52d40b07f16828bcc545b59b8fb1ba60d9cb09f14f7f31dba1e65a6",
|
||||
"tools/linuxfs/preload/zram.c": "12bcf07459728d4a7ede6fa0fea8deb330f7c5d0f0dd61e610e81b9efecd4262",
|
||||
"tools/linuxfs/ssbs/ssbs_adapter.c": "9e4e0fe637f7b8f91f12d8151f02e8d31bcb4294be2b2c62d3cd3ce76f200306",
|
||||
"tools/proot/fastpath/audit.c": "bfe347a2ddaceef40a78d7d590e4e679724ee4c82f3f1f1e3c7017a18ad536d4",
|
||||
"tools/proot/fastpath/fastpath.c": "4cd07b25ba14f6faa6bac5091ae323ded6b646dbb34b9e5a92ea6385e4d37cb5",
|
||||
"tools/quest/kgsl_compat.c": "111afffda7a6df2469610f6c342ae086b1a97a559c586efc4a28015b86efd6bd",
|
||||
"tools/quest/kgsl_compat.h": "2e9e0eb647530a35277954b7e61a22ee958067fe46056a608fb32f40f273f1bf"
|
||||
},
|
||||
"x86": {
|
||||
"@runner": "84f825635599f81ed33f62c5fc4c73f66044d1468b060d65f83855eb9c8bfe77",
|
||||
"app/src/main/cpp/adrenotools/src/hook/kgsl.h": "396c56761034a4ed783543ee3312c6ec64d63b2a1cf7eecf1939c23251f25adf",
|
||||
"app/src/main/cpp/fakeinput_steam.cpp": "3d11e859ca58a42a9da92a3fc589d404df790e151f7e18ea6114645750e70ef5",
|
||||
"app/src/main/cpp/venc/venc_proto.h": "2242ddbc8981d14a33bac70264bb3e7f701fd1c3ebb988e17bbb2b19b6b808f7",
|
||||
"tools/linuxfs/build-x86-preloads.sh": "d0820252809881db89db5a17427e74b9aa4964aae70623cb7f4b474e90c7a23b",
|
||||
"tools/linuxfs/debian-image.env": "1c79dea4314c784042a5c59208765c8401771098f293185d61a157d89edf6e52",
|
||||
"tools/linuxfs/fex/faultreport.c": "573bf780f32f7256dc2fbf40fe850d67e67c354509fdedcac3ff7f1a261daac3",
|
||||
"tools/linuxfs/fex/vulkanpin.c": "f2693ac2be8d15f7881115e61b1c6b3fe4aeec8f603584c6fce5b0f046563d51",
|
||||
"tools/linuxfs/fex/webkitinput.c": "693ffd6c8c8c97e87156444ad2255c84dbf22cd0053d135fb8d9be094b5534d1",
|
||||
"tools/linuxfs/preload/binfmt.c": "0933cc49cb53f0aa1206e2eae516d38dc3337e74174be07e10619c42aa56792b",
|
||||
"tools/linuxfs/preload/dircache.c": "8e7f19ea4a1198783d53a3f357326c6177da157b0cc7e0d22e1670963e1c26e7",
|
||||
"tools/linuxfs/preload/drm.c": "e0eabab0d8ed9e841918e827bf87168efa7f2dfb8404169e9bed3ab5eda2836c",
|
||||
"tools/linuxfs/preload/fsync.c": "795c114c2a05d3f250d07145d04c5658091699da3b96290da36348ccadfb0c09",
|
||||
"tools/linuxfs/preload/inputudev.c": "2648248d3d235a582eb8459709e0a85de537c03ac10c5040fbfb50d9846c68eb",
|
||||
"tools/linuxfs/preload/kgslid.c": "88a7875fd5289930204d155d92ac9d15492cd06db16ed87aa9c95af37f3e7089",
|
||||
"tools/linuxfs/preload/kgslpoll.c": "f0d853d919a52487c04cbda5fb3fa22269da54b7f4ee2f7dd3b5bd9909418670",
|
||||
"tools/linuxfs/preload/links.c": "b7bbcf9112393b152f358fe6f8dc9a1955f0c8532e1eddf016a971415cd13c64",
|
||||
"tools/linuxfs/preload/lock.c": "f71b3fd40e6a2b74908d3cdc601e8748699ae9c7a89b542d2445b999015ffd66",
|
||||
"tools/linuxfs/preload/net.c": "335853c8ea0e9a8ebbc5a5500dc4bded9c34c4310a6ab8aa46b07d5ce1c2b55e",
|
||||
"tools/linuxfs/preload/netif.c": "cc26d50b8d4639d8dd4697811bbf85c9d9f31761f9504a4af42473de3cb22b3c",
|
||||
"tools/linuxfs/preload/noexec.c": "1855aeaeda3d506329bd9af1107580c74d1f56787c411b2e01c0a8a9d4059c7b",
|
||||
"tools/linuxfs/preload/ntsync.c": "0614c48af0c062bfcb4c30141efe1b792b340767a67d2fe92ee9877d2ba16e0d",
|
||||
"tools/linuxfs/preload/opens.c": "92ae4aea16aa457a898dedf4a70eb332d80d3b1e77f3a60bace7715a4317399e",
|
||||
"tools/linuxfs/preload/pathcache.c": "eb0d4b5238fe6c8891e805d90bd837e466754100c978fad2d0ff717116b9b8a3",
|
||||
"tools/linuxfs/preload/perms.c": "f600619c4ca130f69001ed7ad7bd74a3dc215b14c61479c45bb770f916d244b9",
|
||||
"tools/linuxfs/preload/pulseguard.c": "57674ea40283e53a27bc78362de1ba41ee972d172ea38b1f818b1d6eed0abe65",
|
||||
"tools/linuxfs/preload/quest_kgsl.c": "59d9b8416be6a1c680f1d1e4c2427d2cbb7b415344261adb357d9d211ec95cfe",
|
||||
"tools/linuxfs/preload/robust.c": "9eb6c0ed50e0f48a8cfb86bd92587f471354bdf2531b9177f4b3ab83bdfed39a",
|
||||
"tools/linuxfs/preload/rptouch.c": "0e3f8bf2f9a41324361f38fa4da8d2d47593c9555f0cabf8228767397846c7c3",
|
||||
"tools/linuxfs/preload/space.c": "118389bcc89dfa2b4230b80915e21d2d4331c4cff1f5a58265f85e6ecb5c29d2",
|
||||
"tools/linuxfs/preload/storage.c": "08a8b46c3588f3160bb8608489768010ec36d5ccdb2b25a431ec9d6fcd413a6e",
|
||||
"tools/linuxfs/preload/sysv.c": "49774ee5e2e39b84dcfadf63abdc741b3df236cb11783744a1280adee36965e8",
|
||||
"tools/linuxfs/preload/tracefs.c": "be3f8a2f032b56e6e08a931e77a9386aea4bb93421a482271e06386ec0c469b6",
|
||||
"tools/linuxfs/preload/tracer.c": "f34e5377c891b0a8d00489245d66f96bc352df4cd90f47a951dcadae980af4c1",
|
||||
"tools/linuxfs/preload/udevmon.c": "2045dfb883cfb6e2016c359a3dc3af17f3b8f383f6dd0d5dfee407ef0d344852",
|
||||
"tools/linuxfs/preload/usr2.c": "6ae704380b45a9b3a74c4fe2b3ce4482470dae59ced26cf0aee64f4b4dcc11f9",
|
||||
"tools/linuxfs/preload/venc.c": "24c3c46fe49d28adfc8c977e52c9cc407f534b26f56d94b3425b8bb01803dba8",
|
||||
"tools/linuxfs/preload/vmwrite.c": "1a3ea2ec4354e0716c17f7db537b19ab82bcd524f2aece2fa5dec89b076a2188",
|
||||
"tools/linuxfs/preload/webhelper.c": "a8213a7a96b407459c83fb93365cfe58fd05964e7bb262b8061c1c0792a6aac8",
|
||||
"tools/linuxfs/preload/writewatch.c": "61e395d1caa184d329dead0e36c4e92cb1069b1154ac36581f37406c1c242240",
|
||||
"tools/linuxfs/preload/xmode.c": "9a09995bf52d40b07f16828bcc545b59b8fb1ba60d9cb09f14f7f31dba1e65a6",
|
||||
"tools/linuxfs/preload/zram.c": "12bcf07459728d4a7ede6fa0fea8deb330f7c5d0f0dd61e610e81b9efecd4262",
|
||||
"tools/quest/kgsl_compat.c": "111afffda7a6df2469610f6c342ae086b1a97a559c586efc4a28015b86efd6bd",
|
||||
"tools/quest/kgsl_compat.h": "2e9e0eb647530a35277954b7e61a22ee958067fe46056a608fb32f40f273f1bf"
|
||||
}
|
||||
},
|
||||
"origin": {
|
||||
"artifact": 12520502054,
|
||||
"artifact_sha256": "b7e800a1884a516ec52b050b7f904f9881427bca4579f660b909fd18f15e49ff",
|
||||
"commit": "b76f13f7acc0af0cc00369dde61fb88e40529e6d",
|
||||
"run": 39992155294,
|
||||
"url": "https://github.com/Droid-Deck/DroidDeck/actions/runs/39992155294"
|
||||
},
|
||||
"outputs": {
|
||||
"i386/libblsession.so": "5343cdb704217ddc81ee593e67d5987363dc7b5ac78bd4bd36000219e5063268",
|
||||
"i386/libfakeinput.so": "188d88dfb13b6e2f2df948e7b8b4d9ec604770f55d1ea5b6b9e21ad56a74ce5e",
|
||||
"i386/libfaultreport.so": "95f9ef60f04a13ee60cfbd4d2d2efb60a7063b722e646c78c9dc27162292877b",
|
||||
"libblaudit.so": "6c6abe89baf5d7309babee0c3372a4b00c2b689e2a63de38c5e9a660626509b5",
|
||||
"libblfastpath.so": "0e1f151b5c1c5ea9dd380ad58d09f8fe7ba3ae037d0991cb3eef6899e9d5ec83",
|
||||
"libblsession.so": "29d4b5ea46dba941107e02c0ee544244b137a339cada43bff65c350f2ef2755a",
|
||||
"libfakeinput.so": "5f6dc3aea05de2dc1fbe0bbfac2ce4d11e3d47f761c6b06c8badb15fe1904392",
|
||||
"libssbs.so": "c288ed0da26c2481aff270d1cdafe1205061c4a300c2c46ae1b53c6e0c94f44b",
|
||||
"usr/local/bin/droiddeck-clipboard": "ec50e8f67fdf76372927189b0fdb670f9b70fd3484f2fe3e833bc8f9fdc44205",
|
||||
"x86_64/libblsession.so": "61d19f06aebab6a789f8c99f687af9903376bfc853e46b70c48a2ce5e497accc",
|
||||
"x86_64/libfakeinput.so": "8663dd2086bf8ae53069a480dd9ae4619109d32f0947a29e2ce38f07a21ae2e6",
|
||||
"x86_64/libfaultreport.so": "bb0dc9165d0d764473e552508650edd586df16d620fc5b16b8b1c5740a28ce22",
|
||||
"x86_64/libvulkan-thunk.so": "74f01b652d7e8179561a096a552328b68da640cc4bad3981edd38e6afbf90243",
|
||||
"x86_64/libwebkitinput.so": "9b07380a7b017397b9c56bb7bb1161e046b0c6a647fc413888904606b0def6d0"
|
||||
},
|
||||
"toolchain": {
|
||||
"arm64": "Ubuntu 24.04 GCC cross compiler; exact build commands pinned by arm64_recipe",
|
||||
"x86": "Debian bullseye compiler image and recipe pinned by source inputs"
|
||||
},
|
||||
"version": 1,
|
||||
"x86_recipe": "36d06d49f7a4bff5ef675c1e03ce5a5b61498df4c36b9d15a938b41564f755cc"
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
"""Reuse reviewed preload snapshots; changed snapshots must prove their main-build origin."""
|
||||
import argparse
|
||||
import gzip
|
||||
import http.client
|
||||
import hashlib
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import posixpath
|
||||
import re
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tarfile
|
||||
import textwrap
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from zipfile import ZipFile
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
REPO = 'Droid-Deck/DroidDeck'
|
||||
LOCK = 'tools/components/preloads.lock.json'
|
||||
DEFINITIONS = json.loads((ROOT / 'tools/components/recipes.json').read_text())
|
||||
INPUTS = {group: DEFINITIONS[name]['source_inputs'] for group, name in
|
||||
[('arm64', 'arm64-preloads'), ('x86', 'x86-preloads')]}
|
||||
OUTPUTS = {group: DEFINITIONS[name]['snapshot_outputs'] for group, name in
|
||||
[('arm64', 'arm64-preloads'), ('x86', 'x86-preloads')]}
|
||||
COMMON = [name for name in INPUTS['arm64'] if name in INPUTS['x86']]
|
||||
FILES = set(sum(OUTPUTS.values(), []))
|
||||
|
||||
|
||||
def sha(data):
|
||||
return hashlib.sha256(data).hexdigest()
|
||||
|
||||
|
||||
def run(*args, root=ROOT):
|
||||
return subprocess.check_output(args, cwd=root)
|
||||
|
||||
|
||||
def api(path):
|
||||
return json.loads(run('gh', 'api', 'repos/' + REPO + '/' + path))
|
||||
|
||||
|
||||
def source_files(group, root=ROOT, commit=None, patterns=None):
|
||||
patterns = patterns if patterns is not None else INPUTS[group]
|
||||
if commit:
|
||||
paths = run('git', 'ls-tree', '-r', '--name-only', commit, '--', *patterns, root=root).decode().splitlines()
|
||||
read = lambda path: run('git', 'show', f'{commit}:{path}', root=root)
|
||||
else:
|
||||
paths = run('git', 'ls-files', '--cached', '--others', '--exclude-standard', '--', *patterns, root=root).decode().splitlines()
|
||||
read = lambda path: (root / path).read_bytes()
|
||||
paths = [p for p in paths if not p.endswith('.md') and '__pycache__' not in p and not p.endswith('.pyc')]
|
||||
if not paths:
|
||||
raise ValueError('No preload inputs found')
|
||||
result = {}
|
||||
pending = list(paths)
|
||||
while pending:
|
||||
path = pending.pop()
|
||||
if path in result:
|
||||
continue
|
||||
if path.startswith('../') or path.startswith('/'):
|
||||
raise ValueError('Preload include escapes repository')
|
||||
content = read(path).replace(b'\r\n', b'\n')
|
||||
result[path] = sha(content)
|
||||
for include in re.findall(rb'^\s*#\s*include\s*"([^"\n]+)"', content, re.M):
|
||||
pending.append(posixpath.normpath(posixpath.join(posixpath.dirname(path), include.decode())))
|
||||
workflow = (run('git', 'show', f'{commit}:.github/workflows/build.yml', root=root).decode() if commit
|
||||
else (root / '.github/workflows/build.yml').read_text())
|
||||
job = 'components' if re.search(r'(?m)^ components:', workflow) else 'build'
|
||||
runner = re.search(r'(?ms)^ ' + job + r':\n.*?^ runs-on: ([^\n]+)', workflow)
|
||||
if runner is None:
|
||||
raise ValueError('APK build runner policy is missing')
|
||||
result['@runner'] = sha(runner[1].strip().encode())
|
||||
return dict(sorted(result.items()))
|
||||
|
||||
|
||||
def recipe(root=ROOT, commit=None):
|
||||
def read(path):
|
||||
return (run('git', 'show', f'{commit}:{path}', root=root).decode() if commit
|
||||
else (root / path).read_text())
|
||||
script = 'tools/components/build-arm64-preloads.sh'
|
||||
if commit and run('git', 'ls-tree', commit, script, root=root) == b'':
|
||||
workflow = read('.github/workflows/build.yml')
|
||||
text = workflow[workflow.index(' aarch64-linux-gnu-g++ -shared'):]
|
||||
text = textwrap.dedent(text[:text.index(' VK_INCLUDE=')])
|
||||
else:
|
||||
text = read(script)
|
||||
preamble = '#!/usr/bin/env bash\nset -euo pipefail\nD=${1:?output directory}\nmkdir -p "$D"\n'
|
||||
if not text.startswith(preamble):
|
||||
return sha(text.encode())
|
||||
text = text[len(preamble):]
|
||||
return sha(text.replace('\r\n', '\n').encode())
|
||||
|
||||
|
||||
def x86_recipe(root=ROOT, commit=None):
|
||||
path = 'tools/components/recipes/x86-preloads.sh'
|
||||
if commit and not run('git', 'ls-tree', commit, path, root=root):
|
||||
workflow = run('git', 'show', f'{commit}:.github/workflows/build.yml', root=root).decode()
|
||||
section = workflow[workflow.index(' - name: Build the x86 preloads'):]
|
||||
text = section.split(' run: |\n', 1)[1].split('\n - name:', 1)[0]
|
||||
text = textwrap.dedent(text).rstrip() + '\n'
|
||||
else:
|
||||
text = (run('git', 'show', f'{commit}:{path}', root=root).decode() if commit
|
||||
else (root / path).read_text())
|
||||
text = text.removeprefix('#!/usr/bin/env bash\n')
|
||||
return sha(text.replace('\r\n', '\n').encode())
|
||||
|
||||
|
||||
def artifact_bytes(origin, cache):
|
||||
build = api(f"actions/runs/{origin['run']}")
|
||||
if (build['event'] != 'push' or build['head_branch'] != 'main' or build['conclusion'] != 'success'
|
||||
or build['head_sha'] != origin['commit'] or build['path'] != '.github/workflows/build.yml'
|
||||
or build['repository']['full_name'] != REPO):
|
||||
raise ValueError('Snapshot is not from a successful main APK build')
|
||||
artifact = api(f"actions/artifacts/{origin['artifact']}")
|
||||
if (artifact['name'] != 'droiddeck-apk' or artifact['workflow_run']['id'] != origin['run']
|
||||
or artifact['digest'] != 'sha256:' + origin['artifact_sha256']):
|
||||
raise ValueError('Original APK artifact identity or digest mismatch')
|
||||
cache.mkdir(parents=True, exist_ok=True)
|
||||
path = cache / (origin['artifact_sha256'] + '.zip')
|
||||
if not path.exists():
|
||||
path.write_bytes(run('gh', 'api', f"repos/{REPO}/actions/artifacts/{origin['artifact']}/zip"))
|
||||
content = path.read_bytes()
|
||||
if sha(content) != origin['artifact_sha256']:
|
||||
raise ValueError('Original APK archive checksum mismatch')
|
||||
with ZipFile(io.BytesIO(content)) as archive:
|
||||
names = [name for name in archive.namelist() if name.endswith('.apk')]
|
||||
if len(names) != 1:
|
||||
raise ValueError('Expected one original APK')
|
||||
with ZipFile(io.BytesIO(archive.read(names[0]))) as apk:
|
||||
return {name: apk.read('assets/linuxfs/' + name) for name in FILES}
|
||||
|
||||
|
||||
def validate_lock(data):
|
||||
if data.get('version') != 1 or set(data['groups']) != set(INPUTS):
|
||||
raise ValueError('Unsupported preload snapshot')
|
||||
if set(data['outputs']) != FILES:
|
||||
raise ValueError('Unexpected preload output set')
|
||||
for digest in [data['archive_sha256'], *data['outputs'].values()]:
|
||||
if len(digest) != 64 or any(c not in '0123456789abcdef' for c in digest):
|
||||
raise ValueError('Invalid preload checksum')
|
||||
|
||||
|
||||
def producer_sources(group, commit, root=ROOT):
|
||||
config = 'tools/components/recipes.json'
|
||||
if run('git', 'ls-tree', commit, config, root=root):
|
||||
definitions = json.loads(run('git', 'show', f'{commit}:{config}', root=root))
|
||||
name = 'arm64-preloads' if group == 'arm64' else 'x86-preloads'
|
||||
patterns = definitions[name]['source_inputs']
|
||||
else:
|
||||
# Older approved builds kept ARM64 commands inline, before the Vulkan/VR build.
|
||||
if group == 'arm64':
|
||||
text = run('git', 'show', f'{commit}:.github/workflows/build.yml', root=root).decode()
|
||||
text = text[text.index(' aarch64-linux-gnu-g++ -shared'):]
|
||||
text = text[:text.index(' VK_INCLUDE=')]
|
||||
else:
|
||||
text = run('git', 'show', f'{commit}:tools/linuxfs/build-x86-preloads.sh', root=root).decode()
|
||||
patterns = re.findall(r'\b((?:tools|app)/[\w./*+-]+\.(?:cpp|c|h))(?=\s|$)', text)
|
||||
if group == 'x86':
|
||||
patterns += ['tools/linuxfs/fex', 'tools/linuxfs/build-x86-preloads.sh', 'tools/linuxfs/debian-image.env']
|
||||
return source_files(group, root, commit, patterns)
|
||||
|
||||
|
||||
def prove_origin(data, cache, root=ROOT):
|
||||
content = artifact_bytes(data['origin'], cache)
|
||||
if {name: sha(value) for name, value in content.items()} != data['outputs']:
|
||||
raise ValueError('Snapshot binaries differ from the original main APK')
|
||||
commit = data['origin']['commit']
|
||||
run('git', 'fetch', '--no-tags', 'origin', commit, root=root)
|
||||
for group in INPUTS:
|
||||
if source_files(group, root, commit) != data['groups'][group]:
|
||||
raise ValueError('Snapshot inputs differ from the producing source')
|
||||
for name, checksum in producer_sources(group, commit, root).items():
|
||||
if data['groups'][group].get(name) != checksum:
|
||||
raise ValueError('Snapshot omits or changes a producing build dependency')
|
||||
if recipe(root, commit) != data['arm64_recipe']:
|
||||
raise ValueError('Snapshot recipe differs from the producing source')
|
||||
if x86_recipe(root, commit) != data['x86_recipe']:
|
||||
raise ValueError('Snapshot x86 recipe differs from the producing source')
|
||||
|
||||
|
||||
def unpack(content, data):
|
||||
if sha(content) != data['archive_sha256']:
|
||||
raise ValueError('Preload archive checksum mismatch')
|
||||
result = {}
|
||||
total = 0
|
||||
with tarfile.open(fileobj=io.BytesIO(content), mode='r:gz') as archive:
|
||||
for entry in archive:
|
||||
if entry.name not in FILES or entry.name in result or not entry.isfile() or entry.size > 32 * 1024 * 1024:
|
||||
raise ValueError('Unsafe or unexpected preload archive entry')
|
||||
total += entry.size
|
||||
if total > 64 * 1024 * 1024:
|
||||
raise ValueError('Preload archive exceeds expanded size limit')
|
||||
value = archive.extractfile(entry).read()
|
||||
if sha(value) != data['outputs'][entry.name]:
|
||||
raise ValueError('Preload binary checksum mismatch')
|
||||
result[entry.name] = value
|
||||
if set(result) != FILES:
|
||||
raise ValueError('Incomplete preload archive')
|
||||
return result
|
||||
|
||||
|
||||
def restore(root=ROOT):
|
||||
data = json.loads((root / LOCK).read_text())
|
||||
validate_lock(data)
|
||||
matching = {group: source_files(group, root) == data['groups'][group] for group in INPUTS}
|
||||
matching['arm64'] &= recipe(root) == data['arm64_recipe']
|
||||
matching['x86'] &= x86_recipe(root) == data.get('x86_recipe')
|
||||
if os.environ.get('FORCE_PRELOAD_REBUILD') == 'true':
|
||||
matching = dict.fromkeys(INPUTS, False)
|
||||
if any(matching.values()):
|
||||
base = os.environ.get('COMPONENT_TRUSTED_BASE')
|
||||
approved = None
|
||||
if base:
|
||||
result = subprocess.run(['git', 'show', f'{base}:{LOCK}'], cwd=root, capture_output=True)
|
||||
if result.returncode == 0:
|
||||
approved = json.loads(result.stdout)
|
||||
if approved != data:
|
||||
try:
|
||||
prove_origin(data, root / 'app/build/component-downloads', root)
|
||||
except (subprocess.CalledProcessError, OSError, http.client.HTTPException):
|
||||
print('Snapshot origin is unavailable; rebuilding without trusting the snapshot.')
|
||||
matching = dict.fromkeys(INPUTS, False)
|
||||
if any(matching.values()):
|
||||
url = (f"https://github.com/Droid-Deck/DroidDeck-Components/releases/download/"
|
||||
f"preloads-{data['archive_sha256']}/preloads.tar.gz")
|
||||
try:
|
||||
with urllib.request.urlopen(url, timeout=60) as response:
|
||||
content = response.read(64 * 1024 * 1024)
|
||||
except (OSError, http.client.HTTPException) as error:
|
||||
if isinstance(error, urllib.error.HTTPError) and error.code not in (404, 429) and error.code < 500:
|
||||
raise
|
||||
print('Preload snapshot is unavailable; rebuilding from source.')
|
||||
matching = dict.fromkeys(INPUTS, False)
|
||||
else:
|
||||
binaries = unpack(content, data)
|
||||
for group, matches in matching.items():
|
||||
if matches:
|
||||
for name in OUTPUTS[group]:
|
||||
path = root / 'app/src/main/assets/linuxfs' / name
|
||||
if not path.resolve().is_relative_to(root.resolve()) or path.is_symlink():
|
||||
raise ValueError('Preload output escapes repository or is a symlink')
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
path.write_bytes(binaries[name])
|
||||
path.chmod(0o755 if name.endswith('droiddeck-clipboard') else 0o644)
|
||||
for group, matches in matching.items():
|
||||
print(f"{group}: {'verified snapshot reused' if matches else 'inputs changed or snapshot unavailable; rebuild required'}")
|
||||
if os.environ.get('GITHUB_OUTPUT'):
|
||||
with open(os.environ['GITHUB_OUTPUT'], 'a') as output:
|
||||
output.write(f'{group}={str(matches).lower()}\n')
|
||||
return matching
|
||||
|
||||
|
||||
def snapshot(run_id, destination, root=ROOT):
|
||||
build = api(f'actions/runs/{run_id}')
|
||||
candidates = api(f'actions/runs/{run_id}/artifacts?per_page=100')['artifacts']
|
||||
artifact = next(a for a in candidates if a['name'] == 'droiddeck-apk')
|
||||
origin = dict(run=run_id, commit=build['head_sha'], artifact=artifact['id'],
|
||||
artifact_sha256=artifact['digest'].removeprefix('sha256:'),
|
||||
url=build['html_url'])
|
||||
content = artifact_bytes(origin, root / 'app/build/component-downloads')
|
||||
run('git', 'fetch', '--no-tags', 'origin', origin['commit'], root=root)
|
||||
data = dict(version=1, origin=origin, groups={g: source_files(g, root, origin['commit']) for g in INPUTS},
|
||||
arm64_recipe=recipe(root, origin['commit']), x86_recipe=x86_recipe(root, origin['commit']),
|
||||
outputs={name: sha(value) for name, value in content.items()},
|
||||
toolchain=dict(arm64='Ubuntu 24.04 GCC cross compiler; exact build commands pinned by arm64_recipe',
|
||||
x86='Debian bullseye compiler image and recipe pinned by source inputs'))
|
||||
stream = io.BytesIO()
|
||||
with gzip.GzipFile(fileobj=stream, mode='wb', mtime=0) as compressed:
|
||||
with tarfile.open(fileobj=compressed, mode='w') as archive:
|
||||
for name, value in sorted(content.items()):
|
||||
entry = tarfile.TarInfo(name)
|
||||
entry.size, entry.mode = len(value), 0o644
|
||||
archive.addfile(entry, io.BytesIO(value))
|
||||
destination.mkdir(parents=True, exist_ok=True)
|
||||
(destination / 'preloads.tar.gz').write_bytes(stream.getvalue())
|
||||
data['archive_sha256'] = sha(stream.getvalue())
|
||||
(root / LOCK).write_text(json.dumps(data, indent=2, sort_keys=True) + '\n')
|
||||
print('Snapshot SHA-256: ' + data['archive_sha256'])
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('operation', choices=['restore', 'snapshot'])
|
||||
parser.add_argument('--run', type=int)
|
||||
parser.add_argument('--out', type=Path, default=ROOT / 'app/build/component-snapshot')
|
||||
args = parser.parse_args()
|
||||
if args.operation == 'restore':
|
||||
restore()
|
||||
else:
|
||||
snapshot(args.run, args.out)
|
||||
@@ -0,0 +1,167 @@
|
||||
"""One entry point for runtime recipes, cache identities and verified job handoff."""
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path, PurePosixPath
|
||||
import shutil
|
||||
import subprocess
|
||||
import tarfile
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
REGISTRY = 'tools/components/recipes.json'
|
||||
TREES = ['app/src/main/assets/linuxfs', 'app/src/main/assets/directaudio',
|
||||
'app/src/main/assets/droiddeck-esync', 'app/build/prepared-assets',
|
||||
'app/build/component-records']
|
||||
LIBRARIES = ['app/src/main/jniLibs/arm64-v8a/' + name for name in
|
||||
('libproot.so', 'libproot-loader.so', 'libdirectaudiorelay.so')]
|
||||
MANIFEST = 'app/build/prepared-components.json'
|
||||
|
||||
|
||||
def digest(path):
|
||||
with path.open('rb') as stream:
|
||||
return hashlib.file_digest(stream, 'sha256').hexdigest()
|
||||
|
||||
|
||||
def registry(root=ROOT):
|
||||
return json.loads((root / REGISTRY).read_text())
|
||||
|
||||
|
||||
def identity(name, root=ROOT):
|
||||
spec = registry(root)[name]
|
||||
paths = subprocess.check_output(['git', 'ls-files', '--cached', '--others', '--exclude-standard',
|
||||
'--', *spec['inputs'], *spec.get('source_inputs', [])], cwd=root, text=True).splitlines()
|
||||
values = {}
|
||||
for name_ in sorted(set(paths)):
|
||||
if '__pycache__' in name_ or name_.endswith(('.pyc', '.md')):
|
||||
continue
|
||||
content = (root / name_).read_bytes()
|
||||
if b'\0' not in content:
|
||||
content = content.replace(b'\r\n', b'\n')
|
||||
values[name_] = hashlib.sha256(content).hexdigest()
|
||||
policy = dict(spec=spec, sources=values, runner=os.environ.get('RUNNER_OS', 'Linux'),
|
||||
architecture=os.environ.get('RUNNER_ARCH', 'X64'))
|
||||
entrypoint = root / 'tools/components/prepare.py'
|
||||
if entrypoint.is_file():
|
||||
policy['entrypoint'] = hashlib.sha256(entrypoint.read_bytes().replace(b'\r\n', b'\n')).hexdigest()
|
||||
installer = root / 'tools/ci/install-ubuntu-packages.sh'
|
||||
if spec.get('packages') and installer.is_file():
|
||||
policy['installer'] = hashlib.sha256(installer.read_bytes().replace(b'\r\n', b'\n')).hexdigest()
|
||||
if spec.get('ndk'):
|
||||
policy['ndk'] = os.environ.get('NDK_VERSION', '')
|
||||
policy['ndk_policy'] = hashlib.sha256((root / 'tools/ci/toolchains.env').read_bytes().replace(b'\r\n', b'\n')).hexdigest()
|
||||
return hashlib.sha256(json.dumps(policy, sort_keys=True).encode()).hexdigest()
|
||||
|
||||
|
||||
def prepare(name, root=ROOT):
|
||||
spec = registry(root)[name]
|
||||
prepare_tools([name], root)
|
||||
if 'command' in spec:
|
||||
command = spec['command']
|
||||
else:
|
||||
script = (root / spec['script']).resolve()
|
||||
if not script.is_relative_to((root / 'tools/components').resolve()):
|
||||
raise ValueError('Recipe script escapes components directory')
|
||||
command = ['bash', str(script)]
|
||||
environment = dict(os.environ)
|
||||
if spec.get('source'):
|
||||
environment.update(COMPONENT_SOURCE_URL=spec['source']['url'],
|
||||
COMPONENT_SOURCE_SHA256=spec['source']['sha256'])
|
||||
subprocess.run(command, cwd=root, env=environment, check=True)
|
||||
missing = [name_ for name_ in spec['outputs'] if not (root / name_).is_file()]
|
||||
if missing:
|
||||
raise ValueError(f'{name} did not prepare required outputs: {missing}')
|
||||
record = dict(component=name, input_sha256=identity(name, root),
|
||||
outputs={p: digest(root / p) for p in spec['outputs']})
|
||||
destination = root / 'app/build/component-records' / (name + '.json')
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
destination.write_text(json.dumps(record, sort_keys=True, indent=2) + '\n')
|
||||
|
||||
|
||||
def prepare_tools(names, root=ROOT):
|
||||
packages = sorted({package for name in names for package in registry(root)[name].get('packages', [])})
|
||||
if packages:
|
||||
subprocess.run(['bash', 'tools/ci/install-ubuntu-packages.sh', *packages], cwd=root, check=True)
|
||||
|
||||
|
||||
def files(root=ROOT):
|
||||
result = []
|
||||
for name in TREES:
|
||||
folder = root / name
|
||||
if not folder.is_dir() or folder.is_symlink():
|
||||
raise ValueError('Missing prepared component tree: ' + name)
|
||||
for path in folder.rglob('*'):
|
||||
if path.is_symlink():
|
||||
raise ValueError('Symlink in prepared components: ' + str(path))
|
||||
if path.is_file():
|
||||
result.append(path.relative_to(root).as_posix())
|
||||
for name in LIBRARIES:
|
||||
if not (root / name).is_file() or (root / name).is_symlink():
|
||||
raise ValueError('Missing prepared component library: ' + name)
|
||||
result.append(name)
|
||||
return sorted(result)
|
||||
|
||||
|
||||
def pack(destination, root=ROOT):
|
||||
names = files(root)
|
||||
tree = subprocess.check_output(['git', 'rev-parse', 'HEAD^{tree}'], cwd=root, text=True).strip()
|
||||
data = dict(version=1, source_tree=tree, run=os.environ.get('GITHUB_RUN_ID', ''),
|
||||
recipes={name: identity(name, root) for name in registry(root)},
|
||||
files={name: digest(root / name) for name in names})
|
||||
(root / MANIFEST).write_text(json.dumps(data, sort_keys=True, indent=2) + '\n')
|
||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||
with tarfile.open(destination, mode='w:gz', compresslevel=1) as archive:
|
||||
for name in names + [MANIFEST]:
|
||||
archive.add(root / name, arcname=name, recursive=False)
|
||||
|
||||
|
||||
def unpack(archive_path, source_tree, root=ROOT):
|
||||
total = 0
|
||||
seen = set()
|
||||
with tarfile.open(archive_path, mode='r:gz') as archive:
|
||||
for entry in archive:
|
||||
allowed = entry.name in LIBRARIES + [MANIFEST] or any(entry.name.startswith(p + '/') for p in TREES)
|
||||
path = root / entry.name
|
||||
total += entry.size
|
||||
if (not allowed or '\\' in entry.name or '..' in PurePosixPath(entry.name).parts
|
||||
or PurePosixPath(entry.name).as_posix() != entry.name
|
||||
or not entry.isfile() or entry.name in seen or len(seen) >= 100000
|
||||
or entry.size > 512 * 1024 * 1024
|
||||
or total > 2 * 1024**3 or not path.resolve().is_relative_to(root.resolve())
|
||||
or path.is_symlink()):
|
||||
raise ValueError('Unsafe prepared component archive')
|
||||
seen.add(entry.name)
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with path.open('wb') as output:
|
||||
shutil.copyfileobj(archive.extractfile(entry), output)
|
||||
path.chmod(entry.mode & 0o777)
|
||||
data = json.loads((root / MANIFEST).read_text())
|
||||
actual = {name: digest(root / name) for name in files(root)}
|
||||
recipes = {name: identity(name, root) for name in registry(root)}
|
||||
if (data.get('version') != 1 or data['source_tree'] != source_tree or data['files'] != actual
|
||||
or data['recipes'] != recipes):
|
||||
raise ValueError('Prepared components do not match the pinned source tree and file hashes')
|
||||
print('Prepared component source identity and all output hashes verified.')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('recipe')
|
||||
parser.add_argument('--archive', type=Path, default=ROOT / 'app/build/prepared-components.tar.gz')
|
||||
parser.add_argument('--tree')
|
||||
args = parser.parse_args()
|
||||
if args.recipe == 'plan':
|
||||
for name in registry():
|
||||
value = identity(name)
|
||||
print(f'{name}: {value}')
|
||||
if os.environ.get('GITHUB_OUTPUT'):
|
||||
with open(os.environ['GITHUB_OUTPUT'], 'a') as stream:
|
||||
stream.write(f'{name}={value}\n')
|
||||
elif args.recipe == 'tools':
|
||||
prepare_tools(os.environ.get('COMPONENTS_TO_BUILD', '').split())
|
||||
elif args.recipe == 'pack':
|
||||
pack(args.archive)
|
||||
elif args.recipe == 'unpack':
|
||||
unpack(args.archive, args.tree)
|
||||
else:
|
||||
prepare(args.recipe)
|
||||
@@ -0,0 +1,226 @@
|
||||
{
|
||||
"runtime": {
|
||||
"script": "tools/components/recipes/runtime.sh",
|
||||
"inputs": [
|
||||
"tools/components/recipes/runtime.sh",
|
||||
"tools/quest",
|
||||
"tools/linuxfs/overlay",
|
||||
"tools/linuxfs/desktop",
|
||||
"tools/linuxfs/licenses",
|
||||
"tools/linuxfs/uruntime.env",
|
||||
"tools/gamescope/release.env",
|
||||
"tools/wlroots/release.env",
|
||||
"tools/mangoapp",
|
||||
"tools/msitools",
|
||||
"tools/pipewire",
|
||||
"tools/vr",
|
||||
"app/src/main/cpp/waylandcomp/generated",
|
||||
"app/src/main/cpp/waylandcomp/src/headpose_shm.h",
|
||||
"app/src/main/cpp/waylandcomp/src/spatialpose_shm.h",
|
||||
"app/src/main/cpp/venc/venc_proto.h"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/assets/linuxfs/usr/local/bin/gamescope",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-vr/droiddeck/bin/linuxarm64/driver_droiddeck.so"
|
||||
],
|
||||
"ndk": true,
|
||||
"packages": [
|
||||
"gcc-aarch64-linux-gnu",
|
||||
"g++-aarch64-linux-gnu",
|
||||
"libvulkan1",
|
||||
"mesa-vulkan-drivers"
|
||||
]
|
||||
},
|
||||
"esync": {
|
||||
"script": "tools/components/recipes/esync.sh",
|
||||
"inputs": [
|
||||
"tools/components/recipes/esync.sh",
|
||||
"tools/droiddeck-esync/release.env"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/assets/droiddeck-esync/index.json",
|
||||
"app/src/main/assets/droiddeck-esync/index.json.sig"
|
||||
]
|
||||
},
|
||||
"debian-image": {
|
||||
"script": "tools/components/recipes/debian-image.sh",
|
||||
"inputs": [
|
||||
"tools/components/recipes/debian-image.sh"
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
"x86-preloads": {
|
||||
"script": "tools/components/recipes/x86-preloads.sh",
|
||||
"inputs": [
|
||||
"tools/components/recipes/x86-preloads.sh",
|
||||
"tools/linuxfs/build-x86-preloads.sh",
|
||||
"tools/linuxfs/preload",
|
||||
"tools/linuxfs/fex"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/assets/linuxfs/x86_64/libfakeinput.so",
|
||||
"app/src/main/assets/linuxfs/x86_64/libblsession.so",
|
||||
"app/src/main/assets/linuxfs/x86_64/libfaultreport.so",
|
||||
"app/src/main/assets/linuxfs/i386/libfakeinput.so",
|
||||
"app/src/main/assets/linuxfs/i386/libblsession.so",
|
||||
"app/src/main/assets/linuxfs/i386/libfaultreport.so",
|
||||
"app/src/main/assets/linuxfs/x86_64/libwebkitinput.so",
|
||||
"app/src/main/assets/linuxfs/x86_64/libvulkan-thunk.so"
|
||||
],
|
||||
"source_inputs": [
|
||||
"app/src/main/cpp/fakeinput_steam.cpp",
|
||||
"app/src/main/cpp/adrenotools/src/hook/kgsl.h",
|
||||
"app/src/main/cpp/venc/venc_proto.h",
|
||||
"tools/linuxfs/preload",
|
||||
"tools/quest/kgsl_compat.c",
|
||||
"tools/quest/kgsl_compat.h",
|
||||
"tools/linuxfs/fex",
|
||||
"tools/linuxfs/build-x86-preloads.sh",
|
||||
"tools/linuxfs/debian-image.env"
|
||||
],
|
||||
"snapshot_outputs": [
|
||||
"x86_64/libfakeinput.so",
|
||||
"x86_64/libblsession.so",
|
||||
"x86_64/libfaultreport.so",
|
||||
"i386/libfakeinput.so",
|
||||
"i386/libblsession.so",
|
||||
"i386/libfaultreport.so",
|
||||
"x86_64/libwebkitinput.so",
|
||||
"x86_64/libvulkan-thunk.so"
|
||||
]
|
||||
},
|
||||
"pulseaudio-source": {
|
||||
"script": "tools/components/recipes/pulseaudio-source.sh",
|
||||
"inputs": [
|
||||
"tools/components/recipes/pulseaudio-source.sh"
|
||||
],
|
||||
"outputs": [
|
||||
"pa13/src/pulsecore/module.h"
|
||||
],
|
||||
"source": {
|
||||
"url": "https://github.com/pulseaudio/pulseaudio/archive/refs/tags/v13.0.tar.gz",
|
||||
"sha256": "bd7980bc9bd44bd3b3363545dabd19476ebf4d6bb6d2527e7d179256394a6758"
|
||||
}
|
||||
},
|
||||
"directaudio": {
|
||||
"script": "tools/components/recipes/directaudio.sh",
|
||||
"inputs": [
|
||||
"tools/components/recipes/directaudio.sh",
|
||||
"tools/directaudio"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so"
|
||||
],
|
||||
"ndk": true
|
||||
},
|
||||
"audio": {
|
||||
"script": "tools/components/recipes/audio.sh",
|
||||
"inputs": [
|
||||
"tools/aaudio-sink",
|
||||
"tools/directaudio",
|
||||
"tools/components/recipes/audio.sh",
|
||||
"app/src/main/assets/pulseaudio.tzst"
|
||||
],
|
||||
"outputs": [
|
||||
"app/build/prepared-assets/pulseaudio.tzst"
|
||||
],
|
||||
"ndk": true
|
||||
},
|
||||
"proot": {
|
||||
"script": "tools/components/recipes/proot.sh",
|
||||
"inputs": [
|
||||
"tools/proot",
|
||||
"tools/components/recipes/proot.sh"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/jniLibs/arm64-v8a/libproot.so",
|
||||
"app/src/main/jniLibs/arm64-v8a/libproot-loader.so"
|
||||
],
|
||||
"ndk": true
|
||||
},
|
||||
"comet": {
|
||||
"script": "tools/components/recipes/comet.sh",
|
||||
"inputs": [
|
||||
"tools/comet",
|
||||
"tools/components/recipes/comet.sh"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-comet/comet",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-comet/version"
|
||||
],
|
||||
"packages": [
|
||||
"gcc-aarch64-linux-gnu"
|
||||
]
|
||||
},
|
||||
"arm64-preloads": {
|
||||
"script": "tools/components/recipes/arm64-preloads.sh",
|
||||
"inputs": [
|
||||
"tools/components/build-arm64-preloads.sh",
|
||||
"tools/linuxfs/preload",
|
||||
"app/src/main/cpp/fakeinput_steam.cpp",
|
||||
"tools/components/recipes/arm64-preloads.sh"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/assets/linuxfs/libfakeinput.so",
|
||||
"app/src/main/assets/linuxfs/libblsession.so",
|
||||
"app/src/main/assets/linuxfs/libblfastpath.so",
|
||||
"app/src/main/assets/linuxfs/libblaudit.so",
|
||||
"app/src/main/assets/linuxfs/libssbs.so",
|
||||
"app/src/main/assets/linuxfs/usr/local/bin/droiddeck-clipboard"
|
||||
],
|
||||
"packages": [
|
||||
"gcc-aarch64-linux-gnu",
|
||||
"g++-aarch64-linux-gnu"
|
||||
],
|
||||
"source_inputs": [
|
||||
"app/src/main/cpp/fakeinput_steam.cpp",
|
||||
"app/src/main/cpp/adrenotools/src/hook/kgsl.h",
|
||||
"app/src/main/cpp/venc/venc_proto.h",
|
||||
"tools/linuxfs/preload",
|
||||
"tools/quest/kgsl_compat.c",
|
||||
"tools/quest/kgsl_compat.h",
|
||||
"tools/proot/fastpath",
|
||||
"tools/linuxfs/ssbs",
|
||||
"tools/linuxfs/clipboard"
|
||||
],
|
||||
"snapshot_outputs": [
|
||||
"libfakeinput.so",
|
||||
"libblsession.so",
|
||||
"libblfastpath.so",
|
||||
"libblaudit.so",
|
||||
"libssbs.so",
|
||||
"usr/local/bin/droiddeck-clipboard"
|
||||
]
|
||||
},
|
||||
"preload-snapshot": {
|
||||
"command": [
|
||||
"python3",
|
||||
"tools/components/preloads.py",
|
||||
"restore"
|
||||
],
|
||||
"inputs": [
|
||||
"tools/components/preloads.py",
|
||||
"tools/components/preloads.lock.json"
|
||||
],
|
||||
"outputs": []
|
||||
},
|
||||
"xbox": {
|
||||
"script": "tools/components/recipes/xbox.sh",
|
||||
"inputs": [
|
||||
"tools/xbox",
|
||||
"tools/components/recipes/xbox.sh"
|
||||
],
|
||||
"outputs": [
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-xbox/xodus-cli",
|
||||
"app/src/main/assets/linuxfs/usr/local/lib/droiddeck-xbox/xodus-service"
|
||||
],
|
||||
"packages": [
|
||||
"build-essential",
|
||||
"pkg-config",
|
||||
"libssl-dev",
|
||||
"protobuf-compiler",
|
||||
"cmake",
|
||||
"xz-utils"
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
bash tools/components/build-arm64-preloads.sh app/src/main/assets/linuxfs
|
||||
@@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
export NDK="${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_HOME:-$ANDROID_NDK_ROOT}}"
|
||||
tools/aaudio-sink/build.sh "$PWD/pa13" "$PWD/sink-out"
|
||||
rm -rf pa-bundle && mkdir -p pa-bundle
|
||||
tar --use-compress-program=unzstd -xf app/src/main/assets/pulseaudio.tzst -C pa-bundle
|
||||
test ! -f pa-bundle/modules/arm64/module-aaudio-sink.so
|
||||
install -m755 sink-out/module-aaudio-sink.so pa-bundle/modules/arm64/module-aaudio-sink.so
|
||||
install -m755 sink-out/module-directaudio-native-sink.so pa-bundle/modules/arm64/module-directaudio-native-sink.so
|
||||
(cd pa-bundle && tar --use-compress-program='zstd -19' -cf ../pulseaudio.tzst .)
|
||||
mkdir -p app/build/prepared-assets
|
||||
mv pulseaudio.tzst app/build/prepared-assets/pulseaudio.tzst
|
||||
tar --use-compress-program=unzstd -tf app/build/prepared-assets/pulseaudio.tzst | grep -c '\.so$'
|
||||
rm -rf pa-bundle sink-out
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
rustup toolchain install 1.90.0 --profile minimal
|
||||
rustup target add --toolchain 1.90.0 aarch64-unknown-linux-gnu
|
||||
RUSTUP_TOOLCHAIN=1.90.0 bash tools/comet/build.sh
|
||||
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
. tools/linuxfs/debian-image.env
|
||||
image=public.ecr.aws/docker/library/debian:bullseye
|
||||
if gh release download "$DEBIAN_IMAGE_TAG" -R "$GITHUB_REPOSITORY" -p "$DEBIAN_IMAGE_ASSET" -O /tmp/debian-image.tar.zst \
|
||||
&& { [ -z "$DEBIAN_IMAGE_SHA256" ] || echo "$DEBIAN_IMAGE_SHA256 /tmp/debian-image.tar.zst" | sha256sum -c -; }; then
|
||||
zstd -dc /tmp/debian-image.tar.zst | docker load
|
||||
rm -f /tmp/debian-image.tar.zst
|
||||
else
|
||||
echo "::warning::the hosted Debian image could not be fetched; pulling from the registry instead"
|
||||
for attempt in 1 2 3 4 5; do
|
||||
docker pull "$image" && break
|
||||
[ "$attempt" -lt 5 ] || { echo "::error::could not pull $image after $attempt attempts"; exit 1; }
|
||||
echo "pull attempt $attempt failed (registry busy?); retrying in $((attempt * 30)) s"
|
||||
sleep $((attempt * 30))
|
||||
done
|
||||
fi
|
||||
docker image ls "$image"
|
||||
@@ -0,0 +1,3 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
tools/directaudio/fetch.sh "$PWD" "$PWD/sink-out"
|
||||
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
if [ -f tools/droiddeck-esync/release.env ]; then
|
||||
. tools/droiddeck-esync/release.env
|
||||
release_url="https://github.com/${SYNC_BUNDLE_REPO}/releases/download/${SYNC_BUNDLE_TAG}"
|
||||
curl -fsSL --retry 3 -o sync-bundle.tzst "$release_url/$SYNC_BUNDLE_ASSET"
|
||||
echo "$SYNC_BUNDLE_SHA256 sync-bundle.tzst" | sha256sum -c -
|
||||
mkdir -p app/src/main/assets/droiddeck-esync
|
||||
tar --use-compress-program=unzstd -xf sync-bundle.tzst -C app/src/main/assets/droiddeck-esync
|
||||
rm sync-bundle.tzst
|
||||
curl -fsSL --retry 3 -o sync-index.json "$release_url/index.json"
|
||||
revoked=$(python3 -c 'import json, sys; print(" ".join(p["id"] for p in json.load(open(sys.argv[1]))["packs"] if p.get("revoked") is True))' sync-index.json)
|
||||
for id in $revoked; do
|
||||
if [ -e "app/src/main/assets/droiddeck-esync/packs/$id.tzst" ]; then
|
||||
echo "::warning::$SYNC_BUNDLE_ASSET carries revoked pack $id; it is left out of the APK (point tools/droiddeck-esync/release.env at a newer bundle)"
|
||||
rm -f "app/src/main/assets/droiddeck-esync/packs/$id.tzst"
|
||||
fi
|
||||
done
|
||||
rm sync-index.json
|
||||
test -f app/src/main/assets/droiddeck-esync/index.json
|
||||
test -f app/src/main/assets/droiddeck-esync/index.json.sig
|
||||
ls -lR app/src/main/assets/droiddeck-esync
|
||||
fi
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
export NDK="${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_HOME:-$ANDROID_NDK_ROOT}}"
|
||||
tools/proot/build.sh app/src/main/jniLibs/arm64-v8a
|
||||
@@ -0,0 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
curl -fsSL --retry 3 -o pa.tar.gz "$COMPONENT_SOURCE_URL"
|
||||
echo "$COMPONENT_SOURCE_SHA256 pa.tar.gz" | sha256sum -c -
|
||||
mkdir -p pa13 && tar -xzf pa.tar.gz -C pa13 --strip-components=1 && rm pa.tar.gz
|
||||
@@ -0,0 +1,83 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
D=app/src/main/assets/linuxfs
|
||||
mkdir -p "$D"
|
||||
VK_INCLUDE=$(ls -d "${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_HOME:-$ANDROID_NDK_ROOT}}"/toolchains/llvm/prebuilt/*/sysroot/usr/include | head -1) \
|
||||
tools/vr/build.sh --native "$D/usr/local/lib/droiddeck-vr"
|
||||
for script in tools/linuxfs/overlay/usr/local/bin/droiddeck-* tools/linuxfs/overlay/usr/local/bin/steam-compatibility; do
|
||||
install -Dm644 "$script" "$D/usr/local/bin/$(basename "$script")"
|
||||
done
|
||||
for f in tools/linuxfs/overlay/usr/bin/* tools/linuxfs/overlay/usr/bin/steamos-polkit-helpers/*; do
|
||||
[ -f "$f" ] && install -Dm644 "$f" "$D/${f#tools/linuxfs/overlay/}"
|
||||
done
|
||||
if [ -f tools/gamescope/release.env ]; then
|
||||
. tools/gamescope/release.env
|
||||
curl -fsSL --retry 3 -o gamescope.tzst "https://github.com/${GAMESCOPE_REPO:-${GITHUB_REPOSITORY}}/releases/download/${GAMESCOPE_TAG}/gamescope.tzst"
|
||||
echo "${GAMESCOPE_SHA256} gamescope.tzst" | sha256sum -c -
|
||||
tar --use-compress-program=unzstd -xf gamescope.tzst -C "$D"
|
||||
test -f "$D/usr/local/bin/gamescope"
|
||||
rm gamescope.tzst
|
||||
fi
|
||||
. tools/linuxfs/uruntime.env
|
||||
curl -fsSL --retry 3 -o uruntime "https://github.com/VHSgunzo/uruntime/releases/download/${URUNTIME_VERSION}/${URUNTIME_ASSET}"
|
||||
echo "${URUNTIME_SHA256} uruntime" | sha256sum -c -
|
||||
install -Dm644 uruntime "$D/usr/local/lib/droiddeck/uruntime"
|
||||
install -Dm644 tools/linuxfs/licenses/uruntime-LICENSE "$D/usr/local/share/licenses/uruntime/LICENSE"
|
||||
rm uruntime
|
||||
M="$D/usr/local/lib/mangoapp"
|
||||
mkdir -p "$M" mango-pkgs
|
||||
grep -v '^#' tools/mangoapp/packages.txt | while read -r sum url; do
|
||||
[ -n "$url" ] || continue
|
||||
curl -fsSL --retry 3 -o mango-pkgs/pkg.tar.zst "$url"
|
||||
echo "$sum mango-pkgs/pkg.tar.zst" | sha256sum -c -
|
||||
tar --use-compress-program=unzstd -xf mango-pkgs/pkg.tar.zst -C mango-pkgs
|
||||
rm mango-pkgs/pkg.tar.zst
|
||||
done
|
||||
install -m644 mango-pkgs/usr/bin/mangoapp "$M/mangoapp"
|
||||
for so in libfmt.so.10 libspdlog.so.1.13 libglfw.so.3 libtraceevent.so.1; do
|
||||
cp -L "mango-pkgs/usr/lib/$so" "$M/$so"
|
||||
done
|
||||
aarch64-linux-gnu-gcc -shared -fPIC -O2 -Wall -Wl,-soname,libtracefs.so.1 \
|
||||
-o "$M/libtracefs.so.1" tools/mangoapp/libtracefs-shim.c
|
||||
aarch64-linux-gnu-strip --strip-unneeded "$M/libtracefs.so.1"
|
||||
install -Dm644 tools/mangoapp/mangoapp "$D/usr/local/bin/mangoapp"
|
||||
rm -rf mango-pkgs
|
||||
ls -l "$M"
|
||||
mkdir -p pw-pkgs
|
||||
grep -v '^#' tools/pipewire/packages.txt | while read -r sum url; do
|
||||
[ -n "$url" ] || continue
|
||||
curl -fsSL --retry 3 -o pw-pkgs/pkg.tar.zst "$url"
|
||||
echo "$sum pw-pkgs/pkg.tar.zst" | sha256sum -c -
|
||||
tar --use-compress-program=unzstd -xf pw-pkgs/pkg.tar.zst -C pw-pkgs
|
||||
rm pw-pkgs/pkg.tar.zst
|
||||
done
|
||||
tools/pipewire/assemble.sh pw-pkgs "$D/usr/local/lib/droiddeck-pipewire.tzst"
|
||||
rm -rf pw-pkgs
|
||||
ls -l "$D/usr/local/lib/droiddeck-pipewire.tzst"
|
||||
T="$D/usr/local/lib/droiddeck-msitools"
|
||||
mkdir -p "$T" msi-pkgs
|
||||
grep -v '^#' tools/msitools/packages.txt | while read -r sum url; do
|
||||
[ -n "$url" ] || continue
|
||||
curl -fsSL --retry 3 -o msi-pkgs/pkg.tar.xz "$url"
|
||||
echo "$sum msi-pkgs/pkg.tar.xz" | sha256sum -c -
|
||||
tar -xJf msi-pkgs/pkg.tar.xz -C msi-pkgs
|
||||
rm msi-pkgs/pkg.tar.xz
|
||||
done
|
||||
install -m644 msi-pkgs/usr/bin/msiinfo "$T/msiinfo"
|
||||
install -m644 msi-pkgs/usr/bin/cabextract "$T/cabextract"
|
||||
install -m644 msi-pkgs/usr/lib/7zip/7z "$T/7z"
|
||||
install -m644 msi-pkgs/usr/lib/7zip/7z.so "$T/7z.so"
|
||||
for so in libmsi-1.0.so.0 libgsf-1.so.114 libgcab-1.0.so.0; do
|
||||
cp -L "msi-pkgs/usr/lib/$so" "$T/$so"
|
||||
done
|
||||
for f in NOTICE GPL-2 GPL-3 LGPL-2.1 7zip-License 7zip-unRarLicense; do
|
||||
install -Dm644 "tools/msitools/licenses/$f" "$D/usr/local/share/licenses/droiddeck-msitools/$f"
|
||||
done
|
||||
rm -rf msi-pkgs
|
||||
ls -l "$T"
|
||||
install -Dm644 tools/linuxfs/desktop/droiddeck-desktop "$D/usr/local/bin/droiddeck-desktop"
|
||||
install -Dm644 tools/linuxfs/desktop/droiddeck-gpu "$D/usr/local/bin/droiddeck-gpu"
|
||||
install -Dm644 tools/linuxfs/desktop/droiddeck-desktop-gpu "$D/usr/local/bin/droiddeck-desktop-gpu"
|
||||
install -Dm644 tools/linuxfs/desktop/kwin_wayland_wrapper "$D/usr/local/bin/kwin_wayland_wrapper"
|
||||
install -Dm644 tools/linuxfs/desktop/firefox-droiddeck.js "$D/usr/lib/firefox/defaults/pref/droiddeck.js"
|
||||
ls -lR "$D"
|
||||
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
docker run --rm -v "$PWD:/src" -w /src public.ecr.aws/docker/library/debian:bullseye bash -c '
|
||||
set -euo pipefail
|
||||
install_compilers() {
|
||||
apt-get -o Acquire::Check-Valid-Until=false update -qq &&
|
||||
DEBIAN_FRONTEND=noninteractive apt-get install -y -qq --no-install-recommends gcc g++ gcc-multilib g++-multilib binutils >/dev/null
|
||||
}
|
||||
printf "deb http://deb.debian.org/debian bullseye main\ndeb http://security.debian.org/debian-security bullseye-security main\n" > /etc/apt/sources.list
|
||||
if ! install_compilers; then
|
||||
printf "deb http://archive.debian.org/debian bullseye main\ndeb http://archive.debian.org/debian-security bullseye-security main\n" > /etc/apt/sources.list
|
||||
install_compilers
|
||||
fi
|
||||
tools/linuxfs/build-x86-preloads.sh app/src/main/assets/linuxfs
|
||||
'
|
||||
sudo chown -R "$(id -u):$(id -g)" app/src/main/assets/linuxfs
|
||||
ls -l app/src/main/assets/linuxfs/x86_64 app/src/main/assets/linuxfs/i386
|
||||
@@ -0,0 +1,4 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
rustup toolchain install 1.99.0 --profile minimal
|
||||
bash tools/xbox/build.sh
|
||||
Executable
+17
@@ -0,0 +1,17 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
repo_root=$1
|
||||
source_dir=$2
|
||||
: "${NDK:=${ANDROID_NDK_LATEST_HOME:-${ANDROID_NDK_HOME:-${ANDROID_NDK_ROOT:-}}}}"
|
||||
: "${NDK:?set NDK to the Android NDK root}"
|
||||
case "$(uname -s)" in
|
||||
Darwin) host=darwin-x86_64 ;;
|
||||
Linux) host=linux-x86_64 ;;
|
||||
*) echo 'Unsupported NDK host' >&2; exit 1 ;;
|
||||
esac
|
||||
toolchain="$NDK/toolchains/llvm/prebuilt/$host/bin"
|
||||
patch -d "$source_dir" -p1 < "$repo_root/tools/directaudio/microphone-toggle.patch"
|
||||
"$toolchain/aarch64-linux-android28-clang" -O2 -Wl,-z,max-page-size=16384 \
|
||||
"$source_dir/directaudio-relay.c" -o "$repo_root/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so" \
|
||||
-laaudio -llog -pthread
|
||||
"$toolchain/llvm-strip" --strip-unneeded "$repo_root/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so"
|
||||
@@ -3,7 +3,7 @@ set -euo pipefail
|
||||
repo_root=$1
|
||||
sink_out=$2
|
||||
. "${repo_root}/tools/directaudio/release.env"
|
||||
for v in DIRECTAUDIO_REPO DIRECTAUDIO_TAG DIRECTAUDIO_WINE11_SHA256 DIRECTAUDIO_SYSTHREAD_SHA256 DIRECTAUDIO_RELAY_SHA256 DIRECTAUDIO_SINK_SHA256; do
|
||||
for v in DIRECTAUDIO_REPO DIRECTAUDIO_TAG DIRECTAUDIO_WINE11_SHA256 DIRECTAUDIO_SYSTHREAD_SHA256 DIRECTAUDIO_SINK_SHA256 DIRECTAUDIO_SOURCE_COMMIT DIRECTAUDIO_SOURCE_SHA256; do
|
||||
[[ -n "${!v:-}" && "${!v}" != TBD ]] || { echo "tools/directaudio/release.env: ${v} is not set" >&2; exit 1; }
|
||||
done
|
||||
work=$(mktemp -d)
|
||||
@@ -24,7 +24,15 @@ fetch() {
|
||||
}
|
||||
fetch directaudio-linux-wine11.zip "${DIRECTAUDIO_WINE11_SHA256}"
|
||||
fetch directaudio-linux-wine11-systhread.zip "${DIRECTAUDIO_SYSTHREAD_SHA256}"
|
||||
fetch directaudio-linux-relay.zip "${DIRECTAUDIO_RELAY_SHA256}"
|
||||
source_archive="${cache}/${DIRECTAUDIO_SOURCE_SHA256}-directaudio-source.tar.gz"
|
||||
if ! echo "${DIRECTAUDIO_SOURCE_SHA256} ${source_archive}" | sha256sum -c - >/dev/null 2>&1; then
|
||||
curl -fsSL --retry 3 -o "${work}/source.tar.gz" \
|
||||
"https://github.com/${DIRECTAUDIO_REPO}/archive/${DIRECTAUDIO_SOURCE_COMMIT}.tar.gz"
|
||||
echo "${DIRECTAUDIO_SOURCE_SHA256} ${work}/source.tar.gz" | sha256sum -c - >/dev/null
|
||||
mv "${work}/source.tar.gz" "${source_archive}"
|
||||
fi
|
||||
mkdir "${work}/source"
|
||||
tar -xzf "${source_archive}" --strip-components=1 -C "${work}/source"
|
||||
fetch directaudio-linux-sink.zip "${DIRECTAUDIO_SINK_SHA256}"
|
||||
|
||||
assets="${repo_root}/app/src/main/assets/directaudio"
|
||||
@@ -40,9 +48,8 @@ done
|
||||
grep -q '^abi wine11$' "${assets}/linux-wine11/version.txt"
|
||||
grep -q '^abi systhread$' "${assets}/linux-wine11-systhread/version.txt"
|
||||
|
||||
mkdir -p "${work}/relay" "${work}/sink" "${sink_out}" "${repo_root}/app/src/main/jniLibs/arm64-v8a"
|
||||
unzip -q "${work}/directaudio-linux-relay.zip" -d "${work}/relay"
|
||||
install -m755 "${work}/relay/libdirectaudiorelay.so" "${repo_root}/app/src/main/jniLibs/arm64-v8a/libdirectaudiorelay.so"
|
||||
mkdir -p "${work}/sink" "${sink_out}" "${repo_root}/app/src/main/jniLibs/arm64-v8a"
|
||||
"${repo_root}/tools/directaudio/build-relay.sh" "${repo_root}" "${work}/source"
|
||||
unzip -q "${work}/directaudio-linux-sink.zip" -d "${work}/sink"
|
||||
install -m755 "${work}/sink/module-directaudio-native-sink.so" "${sink_out}/"
|
||||
echo "DirectAudio ${DIRECTAUDIO_TAG}: two driver sets, the relay helper and the client sink in place"
|
||||
@@ -0,0 +1,123 @@
|
||||
--- a/directaudio-relay.c
|
||||
+++ b/directaudio-relay.c
|
||||
@@ -70,6 +70,9 @@
|
||||
* session log captures it too. Event-level lines are always on: they fire a
|
||||
* handful of times per session and are what makes a field report actionable. */
|
||||
static int g_verbose;
|
||||
+static const char *g_mic_control;
|
||||
+static int g_mic_enabled = 1;
|
||||
+static pthread_mutex_t g_mic_operations = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static void rlog(const char *fmt, ...)
|
||||
{
|
||||
@@ -735,6 +738,9 @@
|
||||
(void)user;
|
||||
if (aq != __atomic_load_n(&g_mic.cq, __ATOMIC_SEQ_CST) && __atomic_load_n(&g_mic.cq, __ATOMIC_SEQ_CST))
|
||||
return AAUDIO_CALLBACK_RESULT_CONTINUE;
|
||||
+ if (!__atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE))
|
||||
+ memset(audioData, 0, numFrames * g_mic.in_channels *
|
||||
+ (g_mic.in_format == AAUDIO_FORMAT_PCM_I16 ? sizeof(int16_t) : sizeof(float)));
|
||||
__atomic_add_fetch(&g_mic.cb_count, 1, __ATOMIC_RELAXED);
|
||||
|
||||
pthread_mutex_lock(&g_clients_lock);
|
||||
@@ -832,13 +838,14 @@
|
||||
AAudioStream *aq = NULL;
|
||||
int start = 0, stop = 0;
|
||||
|
||||
+ pthread_mutex_lock(&g_mic_operations);
|
||||
pthread_mutex_lock(&g_mic.lock);
|
||||
g_mic.want += delta;
|
||||
if (g_mic.want < 0) g_mic.want = 0;
|
||||
if (g_mic.cq)
|
||||
{
|
||||
- if (g_mic.want > 0 && !g_mic.started) { g_mic.started = 1; start = 1; aq = g_mic.cq; }
|
||||
- if (g_mic.want == 0 && g_mic.started) { g_mic.started = 0; stop = 1; aq = g_mic.cq; }
|
||||
+ if (g_mic.want > 0 && __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE) && !g_mic.started) { g_mic.started = 1; start = 1; aq = g_mic.cq; }
|
||||
+ if ((g_mic.want == 0 || !__atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE)) && g_mic.started) { g_mic.started = 0; stop = 1; aq = g_mic.cq; }
|
||||
}
|
||||
pthread_mutex_unlock(&g_mic.lock);
|
||||
|
||||
@@ -856,8 +863,23 @@
|
||||
else if (stop)
|
||||
{
|
||||
AAudioStream_requestStop(aq);
|
||||
- REVENT("mic stop (%s was the last consumer)", who);
|
||||
- }
|
||||
+ REVENT("mic stop (%s)", who);
|
||||
+ }
|
||||
+ pthread_mutex_unlock(&g_mic_operations);
|
||||
+}
|
||||
+
|
||||
+static void mic_control_update(void)
|
||||
+{
|
||||
+ FILE *f;
|
||||
+ int enabled;
|
||||
+ if (!g_mic_control) return;
|
||||
+ f = fopen(g_mic_control, "r");
|
||||
+ enabled = f && fgetc(f) == '1';
|
||||
+ if (f) fclose(f);
|
||||
+ if (enabled == __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE)) return;
|
||||
+ __atomic_store_n(&g_mic_enabled, enabled, __ATOMIC_RELEASE);
|
||||
+ mic_want(0, "session toggle");
|
||||
+ REVENT("mic enabled=%d", enabled);
|
||||
}
|
||||
|
||||
static void *mic_reopen_thread(void *unused)
|
||||
@@ -870,8 +892,9 @@
|
||||
|
||||
__atomic_store_n(&g_mic.reopen_redo, 0, __ATOMIC_SEQ_CST);
|
||||
|
||||
+ pthread_mutex_lock(&g_mic_operations);
|
||||
pthread_mutex_lock(&g_mic.lock);
|
||||
- want_start = g_mic.want > 0;
|
||||
+ want_start = g_mic.want > 0 && __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE);
|
||||
pthread_mutex_unlock(&g_mic.lock);
|
||||
|
||||
if (open_input(&neu) == AAUDIO_OK)
|
||||
@@ -902,6 +925,7 @@
|
||||
AAudioStream_close(old);
|
||||
}
|
||||
|
||||
+ pthread_mutex_unlock(&g_mic_operations);
|
||||
if (__atomic_load_n(&g_mic.reopen_redo, __ATOMIC_SEQ_CST)) { usleep(20000); continue; }
|
||||
__atomic_store_n(&g_mic.reopen_running, 0, __ATOMIC_SEQ_CST);
|
||||
if (!__atomic_load_n(&g_mic.reopen_redo, __ATOMIC_SEQ_CST)) break;
|
||||
@@ -1348,7 +1372,8 @@
|
||||
/* ---- housekeeping: watchdog tick + mailbox watch, once a second ------------- */
|
||||
static void *housekeeping_thread(void *unused)
|
||||
{
|
||||
- struct timespec iv = { 1, 0 };
|
||||
+ struct timespec iv = { 0, 100000000 };
|
||||
+ unsigned tick = 0;
|
||||
|
||||
(void)unused;
|
||||
for (;;)
|
||||
@@ -1357,6 +1382,8 @@
|
||||
int reload = 0;
|
||||
|
||||
nanosleep(&iv, NULL);
|
||||
+ mic_control_update();
|
||||
+ if (++tick % 10) continue;
|
||||
|
||||
if (g_rt_path[0])
|
||||
{
|
||||
@@ -1402,8 +1429,9 @@
|
||||
{
|
||||
if (!strcmp(argv[i], "--socket") && i + 1 < argc) path = argv[++i];
|
||||
else if (!strcmp(argv[i], "--mic-fifo") && i + 1 < argc) fifo_path = argv[++i];
|
||||
+ else if (!strcmp(argv[i], "--mic-control") && i + 1 < argc) g_mic_control = argv[++i];
|
||||
else if (!strcmp(argv[i], "--log")) g_verbose = 1;
|
||||
- else { fprintf(stderr, "usage: directaudio-relay --socket <path> [--mic-fifo <path>] [--log]\n"); return 2; }
|
||||
+ else { fprintf(stderr, "usage: directaudio-relay --socket <path> [--mic-fifo <path>] [--mic-control <path>] [--log]\n"); return 2; }
|
||||
}
|
||||
if (!path)
|
||||
{
|
||||
@@ -1429,6 +1457,8 @@
|
||||
chmod(path, 0666);
|
||||
if (listen(srv, 8) != 0) { REVENT("listen: %d", errno); return 1; }
|
||||
|
||||
+ mic_control_update();
|
||||
+ REVENT("mic enabled=%d", __atomic_load_n(&g_mic_enabled, __ATOMIC_ACQUIRE));
|
||||
if (pthread_create(&th, NULL, housekeeping_thread, NULL) == 0) pthread_detach(th);
|
||||
if (fifo_path && fifo_setup(fifo_path) != 0)
|
||||
REVENT("mic-fifo: disabled");
|
||||
@@ -2,5 +2,6 @@ DIRECTAUDIO_REPO=The412Banner/directaudio
|
||||
DIRECTAUDIO_TAG=directaudio-linux-v1.1.0
|
||||
DIRECTAUDIO_WINE11_SHA256=835e6cab072f5148893c43379e60506483aeb3f1444e777b430c295cbeb472c9
|
||||
DIRECTAUDIO_SYSTHREAD_SHA256=2ddc47f446142d5940540ad40a423ca8d47fd536e3225b888df1077c6be7329e
|
||||
DIRECTAUDIO_RELAY_SHA256=b68eb6d7a892fd92a1cd73fac36dc05cabb77cc73792e2c582d3eeccad355942
|
||||
DIRECTAUDIO_SINK_SHA256=1d5d3ed709e5389ef7603f019c62b07e4e8428bb42882193d4a144a5c15425b6
|
||||
DIRECTAUDIO_SOURCE_COMMIT=52aedbf8ddd42874a5bbd21df20e1046367f442e
|
||||
DIRECTAUDIO_SOURCE_SHA256=a20c9a0684ae3b1e60a6b9c17b7f1d5ec2501627ae9683aa9f391576a6c1974d
|
||||
@@ -17,7 +17,7 @@ if __name__ == '__main__':
|
||||
sys.exit('Docker is unavailable: ' + engine.stderr.strip())
|
||||
image = run('image', 'inspect', sys.argv[1])
|
||||
if image.returncode:
|
||||
if 'No such image' not in image.stderr:
|
||||
if 'No such image' not in image.stderr and 'image not known' not in image.stderr: # Docker, Podman
|
||||
sys.exit('Cannot inspect the build image: ' + image.stderr.strip())
|
||||
repo = Path(__file__).resolve().parents[1]
|
||||
subprocess.run(['docker', 'build', '--platform', 'linux/amd64', '-t', sys.argv[1],
|
||||
|
||||
+32
-1
@@ -21,6 +21,7 @@ from pathlib import Path
|
||||
|
||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||
from adb_device import DeviceResolutionError, resolve_serial
|
||||
from proot_profile import report as proot_profile_report
|
||||
|
||||
|
||||
# tools/release/variants.txt: the same app also ships as other packages (e.g. com.antutu.benchmark.full).
|
||||
@@ -37,6 +38,13 @@ class ControlError(RuntimeError):
|
||||
self.code = code
|
||||
|
||||
|
||||
def profile_slow_us(value: str) -> int:
|
||||
number = int(value)
|
||||
if not 1 <= number <= 1_000_000_000:
|
||||
raise argparse.ArgumentTypeError("--slow-us must be between 1 and 1000000000")
|
||||
return number
|
||||
|
||||
|
||||
def adb_path(configured: str | None) -> str:
|
||||
if configured:
|
||||
return configured
|
||||
@@ -628,6 +636,10 @@ def execute(args: argparse.Namespace, adb: str, serial: str) -> dict:
|
||||
request["text"] = args.text
|
||||
return add_serial(checked(provider_call(adb, serial, "ui", request=request), "UI_FAILED"), serial)
|
||||
|
||||
if command == "proot-profile":
|
||||
lines = ["PROOT_PROFILE=1", f"PROOT_PROFILE_SLOW_US={args.slow_us}"] if args.profile_op == "enable" else ["PROOT_PROFILE=0"]
|
||||
return add_serial(checked(provider_call(adb, serial, "env", request={"op": "set", "lines": lines, "persistent": False}), "ENV_FAILED"), serial)
|
||||
|
||||
if command == "env":
|
||||
if args.env_op == "set":
|
||||
request = {"op": "set", "lines": args.lines, "persistent": args.persistent}
|
||||
@@ -828,6 +840,16 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
if name == "set-text":
|
||||
op.add_argument("--text", required=True)
|
||||
|
||||
profile = commands.add_parser("proot-profile", help="profile PRoot syscall handlers in the next session, or rank a saved log")
|
||||
profile_ops = profile.add_subparsers(dest="profile_op", required=True)
|
||||
profile_enable = profile_ops.add_parser("enable", help="enable counters and bounded slow samples for the next session")
|
||||
profile_enable.add_argument("--slow-us", type=profile_slow_us, default=1000, metavar="US")
|
||||
profile_ops.add_parser("disable", help="disable profiling for the next session")
|
||||
profile_report = profile_ops.add_parser("report", help="read a local session.log without a device")
|
||||
profile_report.add_argument("path", type=Path)
|
||||
profile_report.add_argument("--sort", choices=["wall", "cpu", "calls"], default="wall")
|
||||
profile_report.add_argument("--limit", type=int, default=20)
|
||||
|
||||
env = commands.add_parser("env", help="session environment lines (debugging tools)")
|
||||
env_ops = env.add_subparsers(dest="env_op", required=True)
|
||||
env_ops.add_parser("list")
|
||||
@@ -837,7 +859,7 @@ def build_parser() -> argparse.ArgumentParser:
|
||||
env_clear = env_ops.add_parser("clear")
|
||||
env_clear.add_argument("scope", nargs="?", choices=["next", "persistent", "all"], default="next")
|
||||
|
||||
override = commands.add_parser("override", help="put a binary first on the next session's PATH (debugging tools)")
|
||||
override = commands.add_parser("override", help="override a program or libblfastpath.so for the next session (debugging tools)")
|
||||
override.add_argument("name", help="the program name, e.g. gamescope")
|
||||
override.add_argument("path", help="the local file to push")
|
||||
|
||||
@@ -941,6 +963,15 @@ def main(argv: list[str] | None = None) -> int:
|
||||
try:
|
||||
if not PACKAGE_NAME.fullmatch(PACKAGE): # it reaches the device shell through `am start` and `content call`
|
||||
raise ControlError(f"DROIDDECK_PACKAGE is not an Android package name: {PACKAGE!r}", "INVALID_REQUEST")
|
||||
if args.command == "proot-profile" and args.profile_op == "report":
|
||||
if args.limit < 1:
|
||||
raise ControlError("--limit must be positive", "INVALID_ARGUMENTS")
|
||||
try:
|
||||
result = proot_profile_report(args.path.expanduser(), args.sort, args.limit)
|
||||
except OSError as exc:
|
||||
raise ControlError(str(exc), "FILE_IO") from exc
|
||||
print(json.dumps(result, indent=2, sort_keys=True))
|
||||
return 0
|
||||
adb = adb_path(args.adb)
|
||||
serial = resolve_serial(adb, args.serial, log=True)
|
||||
result = execute(args, adb, serial)
|
||||
|
||||
@@ -85,3 +85,17 @@ the patched component retained 1/20, then 0 after destruction. The unassigned
|
||||
control retained 20/20 and then 0. In Backpack Battles, two batches of ten touch
|
||||
drags leaked 188 and 197 SHM descriptors before the fix; the same batches added
|
||||
zero after the fix (112 total descriptors before and after each batch).
|
||||
|
||||
## 0117 WSI: cache the present-time Xwayland bypass check
|
||||
|
||||
`QueuePresentKHR` in the WSI layer calls `canBypassXWayland` for every swapchain on
|
||||
every present. Each call makes several synchronous X requests (window geometry,
|
||||
`_WINE_ALLOW_FLIP`, parent window, a child-window scan, the toplevel window). At
|
||||
high frame rates that is thousands of round trips a second: on an AYANEO Pocket FIT
|
||||
running AIO Graphics Test uncapped, Xwayland used 24-32% of a core and the game's
|
||||
present thread sat about half idle.
|
||||
|
||||
The patch can keep the result for `DROIDDECK_WSI_BYPASS_CHECK_MS` milliseconds. Unset
|
||||
or 0 keeps the per-present check; the app sets 100 only in Performance mode and 0
|
||||
otherwise. With 100, a window resize or a flip/obscure change is seen up to 100 ms
|
||||
later than before; surface creation and capability queries still check every time.
|
||||
@@ -49,7 +49,11 @@ tar --use-compress-program=unzstd -xf "$PKG" -C out --strip-components=2 usr/bin
|
||||
mv out/gamescope out/usr/local/bin/gamescope
|
||||
chmod 755 out/usr/local/bin/gamescope
|
||||
strip --strip-unneeded out/usr/local/bin/gamescope || true
|
||||
NEEDED=$(readelf -d out/usr/local/bin/gamescope | sed -n 's/.*NEEDED.*\[\(.*\)\]/\1/p')
|
||||
# The WSI layer carries patches too (0117); the runtime's stock copy is replaced.
|
||||
mkdir -p out/usr/lib
|
||||
tar --use-compress-program=unzstd -xf "$PKG" -C out usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so
|
||||
strip --strip-unneeded out/usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so || true
|
||||
NEEDED=$(for f in out/usr/local/bin/gamescope out/usr/lib/libVkLayer_FROG_gamescope_wsi_aarch64.so; do readelf -d "$f" | sed -n 's/.*NEEDED.*\[\(.*\)\]/\1/p'; done | sort -u)
|
||||
echo "NEEDED: $NEEDED"
|
||||
MISSING=""
|
||||
for lib in $NEEDED; do grep -qx "$lib" tools/gamescope/runtime-sonames.txt || MISSING="$MISSING $lib"; done
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
--- a/layer/VkLayer_FROG_gamescope_wsi.cpp 2026-10-25 07:56:48.179978889 +0000
|
||||
+++ b/layer/VkLayer_FROG_gamescope_wsi.cpp 2026-10-25 07:56:48.207978889 +0000
|
||||
@@ -23,6 +23,8 @@
|
||||
#include <optional>
|
||||
|
||||
#include <poll.h>
|
||||
+#include <time.h>
|
||||
+#include <cstdlib>
|
||||
#include <sys/stat.h>
|
||||
// For limiter file.
|
||||
#include <time.h>
|
||||
@@ -476,6 +478,34 @@
|
||||
// Cached for comparison.
|
||||
std::optional<VkRect2D> cachedWindowRect;
|
||||
|
||||
+ // canBypassXWayland costs several X round trips; at present time it is refreshed at most
|
||||
+ // every DROIDDECK_WSI_BYPASS_CHECK_MS (default 0 = every present; DroidDeck's Performance mode sets 100).
|
||||
+ std::optional<bool> presentBypass;
|
||||
+ bool presentBypassHdr = false;
|
||||
+ uint64_t presentBypassNs = 0;
|
||||
+
|
||||
+ static uint64_t presentBypassIntervalNs() {
|
||||
+ static const uint64_t interval = [] {
|
||||
+ const char *v = getenv("DROIDDECK_WSI_BYPASS_CHECK_MS");
|
||||
+ return uint64_t(v && *v ? strtoull(v, nullptr, 10) : 0) * 1000000ull;
|
||||
+ }();
|
||||
+ return interval;
|
||||
+ }
|
||||
+
|
||||
+ bool canBypassXWaylandAtPresent(bool hdrColorspace) {
|
||||
+ if (isWayland())
|
||||
+ return true;
|
||||
+ timespec ts;
|
||||
+ clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||
+ const uint64_t now = uint64_t(ts.tv_sec) * 1000000000ull + uint64_t(ts.tv_nsec);
|
||||
+ if (!presentBypass || presentBypassHdr != hdrColorspace || now - presentBypassNs >= presentBypassIntervalNs()) {
|
||||
+ presentBypass = canBypassXWayland(hdrColorspace);
|
||||
+ presentBypassHdr = hdrColorspace;
|
||||
+ presentBypassNs = now;
|
||||
+ }
|
||||
+ return *presentBypass;
|
||||
+ }
|
||||
+
|
||||
bool isWayland() const {
|
||||
// Is native Wayland?
|
||||
return connection == nullptr;
|
||||
@@ -1597,7 +1627,7 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
- const bool canBypass = gamescopeSurface->canBypassXWayland(gamescopeSwapchain->isHdrColorspace);
|
||||
+ const bool canBypass = gamescopeSurface->canBypassXWaylandAtPresent(gamescopeSwapchain->isHdrColorspace);
|
||||
if (canBypass != gamescopeSwapchain->isBypassingXWayland) {
|
||||
if (canBypass) {
|
||||
if (!(gamescopeSurface->flags & GamescopeLayerClient::Flag::NoSuboptimal))
|
||||
@@ -1,3 +1,3 @@
|
||||
GAMESCOPE_REPO=Droid-Deck/DroidDeck-Components
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-p12
|
||||
GAMESCOPE_SHA256=07b69944a1ebf2741d4a867afa6327dcc63ec458f432a8f7483089dce2197010
|
||||
GAMESCOPE_TAG=gamescope-3.16.29-p13
|
||||
GAMESCOPE_SHA256=93c789dc9e08828496f1caa2849d56acdf205838de723a24b296547a29c0b6af
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
# Runs DroidDeck's bundled innoextract with its own boost libraries. The guest's
|
||||
# env -i startup has no LD_LIBRARY_PATH, and the rootfs must not grow a second
|
||||
# copy of boost for the installer fallback.
|
||||
LD_LIBRARY_PATH=/usr/local/lib/droiddeck-inno
|
||||
export LD_LIBRARY_PATH
|
||||
exec /usr/local/lib/droiddeck-inno/innoextract "$@"
|
||||
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
Executable
BIN
Binary file not shown.
BIN
Binary file not shown.
+23
@@ -0,0 +1,23 @@
|
||||
Boost Software License - Version 1.0 - August 17th, 2003
|
||||
|
||||
Permission is hereby granted, free of charge, to any person or organization
|
||||
obtaining a copy of the software and accompanying documentation covered by
|
||||
this license (the "Software") to use, reproduce, display, distribute,
|
||||
execute, and transmit the Software, and to prepare derivative works of the
|
||||
Software, and to permit third-parties to whom the Software is furnished to
|
||||
do so, all subject to the following:
|
||||
|
||||
The copyright notices in the Software and this entire statement, including
|
||||
the above license grant, this restriction and the following disclaimer,
|
||||
must be included in all copies of the Software, in whole or in part, and
|
||||
all derivative works of the Software, unless such copies or derivative
|
||||
works are solely in the form of machine-executable object code generated by
|
||||
a source language processor.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
|
||||
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
|
||||
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||||
DEALINGS IN THE SOFTWARE.
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
|
||||
Copyright (C) 2011-2020 Daniel Scharrer <daniel@constexpr.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the author(s) be held liable for any damages
|
||||
arising from the use of this software.
|
||||
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
@@ -259,24 +259,91 @@ def focus_snapshot():
|
||||
STEAM_APP_CLASS = re.compile(r"steam_app_(\d+)$")
|
||||
|
||||
|
||||
def tag_game_windows(snap):
|
||||
if os.environ.get("BL_STEAM_CLIENT_ARCH") != "x86_64":
|
||||
return False
|
||||
def process_env(pid, proc=Path("/proc")):
|
||||
try:
|
||||
return dict(entry.split(b"=", 1) for entry in (proc / str(pid) / "environ").read_bytes().split(b"\0") if b"=" in entry)
|
||||
except OSError:
|
||||
return {}
|
||||
|
||||
|
||||
def steam_app_id(env):
|
||||
try:
|
||||
app = int(env.get(b"SteamAppId", b"0"))
|
||||
except ValueError:
|
||||
return None
|
||||
return app if 0 < app < 2**32 else None
|
||||
|
||||
|
||||
def under_reaper(pid, proc=Path("/proc")):
|
||||
for _ in range(64):
|
||||
try:
|
||||
if (proc / str(pid) / "comm").read_text().strip() == "reaper":
|
||||
return True
|
||||
stat = (proc / str(pid) / "stat").read_text()
|
||||
pid = int(stat[stat.rindex(")") + 2:].split()[1])
|
||||
except (OSError, ValueError, IndexError):
|
||||
return False
|
||||
if pid <= 1:
|
||||
return False
|
||||
return False
|
||||
|
||||
|
||||
def sandboxed_apps(proc=Path("/proc")):
|
||||
apps = {}
|
||||
try:
|
||||
pids = [entry for entry in os.listdir(proc) if entry.isdigit()]
|
||||
except OSError:
|
||||
return apps
|
||||
for pid in pids:
|
||||
env = process_env(pid, proc)
|
||||
flatpak, app = env.get(b"FLATPAK_ID"), steam_app_id(env)
|
||||
if flatpak and app:
|
||||
name = flatpak.decode(errors="replace").lower()
|
||||
for key in {name, name.rsplit(".", 1)[-1]}:
|
||||
apps[key] = app if apps.get(key, app) == app else None
|
||||
return apps
|
||||
|
||||
|
||||
def window_steam_app(win, flatpaks, proc=Path("/proc")):
|
||||
match = STEAM_APP_CLASS.match(win.get("class") or "")
|
||||
if match:
|
||||
return match.group(1) if os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64" else None
|
||||
pid = win.get("pid")
|
||||
if pid:
|
||||
if under_reaper(pid, proc):
|
||||
return None
|
||||
app = steam_app_id(process_env(pid, proc))
|
||||
if app:
|
||||
return str(app)
|
||||
app = flatpaks().get((win.get("class") or "").lower())
|
||||
return str(app) if app else None
|
||||
|
||||
|
||||
def tag_game_windows(snap, proc=Path("/proc")):
|
||||
tagged = False
|
||||
found = []
|
||||
|
||||
def flatpaks():
|
||||
if not found:
|
||||
found.append(sandboxed_apps(proc))
|
||||
return found[0]
|
||||
|
||||
for display, wins in snap.get("displays", {}).items():
|
||||
if display == os.environ.get("DISPLAY"):
|
||||
continue
|
||||
for win in wins:
|
||||
match = STEAM_APP_CLASS.match(win.get("class") or "")
|
||||
if not match or win.get("appId") or win.get("map") != "viewable" or win.get("overrideRedirect"):
|
||||
if win.get("appId") or win.get("map") != "viewable" or win.get("overrideRedirect") or win.get("inputOnly"):
|
||||
continue
|
||||
app = window_steam_app(win, flatpaks, proc)
|
||||
if not app:
|
||||
continue
|
||||
try:
|
||||
done = subprocess.run(["xprop", "-display", display, "-id", str(win["window"]), "-f", "STEAM_GAME", "32c",
|
||||
"-set", "STEAM_GAME", match.group(1)],
|
||||
"-set", "STEAM_GAME", app],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=5).returncode == 0
|
||||
except (OSError, subprocess.TimeoutExpired):
|
||||
done = False
|
||||
log("game window %s on %s tagged STEAM_GAME=%s: %s" % (win["window"], display, match.group(1), "ok" if done else "failed"))
|
||||
log("game window %s on %s tagged STEAM_GAME=%s: %s" % (win["window"], display, app, "ok" if done else "failed"))
|
||||
tagged = tagged or done
|
||||
return tagged
|
||||
|
||||
|
||||
+965
@@ -0,0 +1,965 @@
|
||||
#!/usr/bin/python3
|
||||
import fcntl
|
||||
import http.client
|
||||
import json
|
||||
import math
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import signal
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
import urllib.request
|
||||
|
||||
HOME = os.environ.get("HOME") or "/root"
|
||||
BIN = "/usr/local/bin"
|
||||
PROTON_RUN = os.path.join(BIN, "droiddeck-proton-run")
|
||||
APP_ID = "2596113170"
|
||||
INSTALLER_URL = "https://downloader.battle.net/download/getInstallerForGame?os=win&gameProgram=BATTLENET_APP&version=Live"
|
||||
CLIENT_DIR = ("Program Files (x86)", "Battle.net")
|
||||
LAUNCHER = "Battle.net Launcher.exe"
|
||||
CLIENT = "Battle.net.exe"
|
||||
CONFIG = ("users", "steamuser", "AppData", "Roaming", "Battle.net", "Battle.net.config")
|
||||
DEFAULT_CONFIG = {"Client": {"HardwareAcceleration": "false", "Streaming": {"StreamingEnabled": "false"}}}
|
||||
LAUNCH_BEHAVIOR = ("GameLaunchWindowBehavior", "2")
|
||||
CLIENT_32_BIT = ("s1",)
|
||||
CACHE = os.path.join(HOME, ".cache", "droiddeck", "battlenet")
|
||||
MENU = "/usr/local/share/applications/droiddeck-battlenet.desktop"
|
||||
WALLPAPER_DIR = ("users", "steamuser", "AppData", "Local", "DroidDeck")
|
||||
DESKTOP_KEY = "[Control Panel\\\\Desktop]"
|
||||
COLORS_KEY = "[Control Panel\\\\Colors]"
|
||||
WALLPAPER_EDGE = (4, 6, 11)
|
||||
WALLPAPER_MAX = (1280, 720)
|
||||
FEX_REQUEST = "battlenet-fex.request"
|
||||
FEX_RESULT = "battlenet-fex.result"
|
||||
FEX_WAIT = 120
|
||||
START_GRACE = 90
|
||||
POLL = 2
|
||||
STOP_WAIT = 5
|
||||
CLOSE_GRACE = 15
|
||||
HANDOFF_WAIT = 120
|
||||
GAME_SETTLE = 20
|
||||
AGENT_GONE = 30
|
||||
AGENT = "agent.exe"
|
||||
CODE = re.compile(r"[A-Za-z0-9_]{1,16}")
|
||||
GAME_UID = re.compile(r"[a-z0-9_]{1,32}")
|
||||
HANDOVER_WAIT = 1800
|
||||
CLIENT_READY = 5
|
||||
READY_SETTLE = 5
|
||||
CLIENT_WAIT = 300
|
||||
GAME_GRACE = 15
|
||||
LAUNCH_WAIT = 15
|
||||
LAUNCH_ASKS = 3
|
||||
CLIENT_PATH = re.compile(r"[a-z]:\\(program files \(x86\)|programdata)\\battle\.net\\")
|
||||
IDLE = {"agent.exe", "conhost.exe", "explorer.exe", "lsass.exe", "plugplay.exe", "rpcss.exe", "services.exe",
|
||||
"start.exe", "steam.exe", "svchost.exe", "tabtip.exe", "winedevice.exe", "wineserver"}
|
||||
NOT_GAME = IDLE | {"rundll32.exe", "wineboot.exe", "winemenubuilder.exe"}
|
||||
MIN_INSTALLER = 1 << 20
|
||||
SETUP = "Battle.net-Setup.exe"
|
||||
REQUEST = "battlenet-request"
|
||||
REQUEST_FILE = re.compile(re.escape(REQUEST) + r"\.\d+")
|
||||
LIBRARY = None
|
||||
WOW_UID = re.compile(r"--uid=wow[a-z0-9_]*", re.I)
|
||||
GAMEPAD_SETTING = re.compile(r"(?im)^\s*SET\s+GamePadEnable\s")
|
||||
GX_API_SETTING = re.compile(r"(?im)^[ \t]*SET[ \t]+gxApi[ \t].*$")
|
||||
GX_API_MARK = ".droiddeck-d3d11"
|
||||
STEAM_CLIENT = {"steam", "steamwebhelper"}
|
||||
LOG = os.path.join(CACHE, "battlenet.log")
|
||||
LOG_LIMIT = 512 << 10
|
||||
|
||||
|
||||
def say(message):
|
||||
line = "droiddeck-battlenet: %s" % message
|
||||
print(line, file=sys.stderr, flush=True)
|
||||
try:
|
||||
os.makedirs(CACHE, exist_ok=True)
|
||||
if os.path.exists(LOG) and os.path.getsize(LOG) > LOG_LIMIT:
|
||||
os.replace(LOG, LOG + ".1")
|
||||
with open(LOG, "a", encoding="utf-8") as f:
|
||||
f.write("%s [%d] %s\n" % (time.strftime("%Y-%m-%d %H:%M:%S"), os.getpid(), message))
|
||||
except OSError:
|
||||
pass
|
||||
|
||||
|
||||
def notify(title, body, icon="dialog-information"):
|
||||
if not os.environ.get("DBUS_SESSION_BUS_ADDRESS") or not shutil.which("notify-send"):
|
||||
return
|
||||
try:
|
||||
subprocess.run(["notify-send", "-a", "DroidDeck", "-i", icon, title, body],
|
||||
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=5)
|
||||
except (OSError, subprocess.SubprocessError):
|
||||
pass
|
||||
|
||||
|
||||
def steam_root():
|
||||
return os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or os.path.join(HOME, ".local", "share", "Steam")
|
||||
|
||||
|
||||
def prefix(root):
|
||||
return os.path.join(root, "steamapps", "compatdata", APP_ID)
|
||||
|
||||
|
||||
def drive_c(root):
|
||||
return os.path.join(prefix(root), "pfx", "drive_c")
|
||||
|
||||
|
||||
def client_dir(root):
|
||||
return os.path.join(drive_c(root), *CLIENT_DIR)
|
||||
|
||||
|
||||
def launcher(root):
|
||||
return os.path.join(client_dir(root), LAUNCHER)
|
||||
|
||||
|
||||
def installed(root):
|
||||
return os.path.isfile(launcher(root))
|
||||
|
||||
|
||||
def install_path(library):
|
||||
return "Z:" + library.rstrip("/")
|
||||
|
||||
|
||||
def write_config(root, library=None):
|
||||
path = os.path.join(drive_c(root), *CONFIG)
|
||||
key, value = LAUNCH_BEHAVIOR
|
||||
try:
|
||||
with open(path, encoding="utf-8-sig") as f:
|
||||
config = json.load(f)
|
||||
except FileNotFoundError:
|
||||
config = None
|
||||
except (OSError, ValueError):
|
||||
return None
|
||||
first = config is None
|
||||
if first:
|
||||
config = json.loads(json.dumps(DEFAULT_CONFIG))
|
||||
elif not (isinstance(config, dict) and isinstance(config.setdefault("Client", {}), dict)):
|
||||
return None
|
||||
client = config["Client"]
|
||||
changes = []
|
||||
if client.get(key) != value:
|
||||
client[key] = value
|
||||
changes.append("launch")
|
||||
if client.get("HardwareAcceleration") != "false":
|
||||
client["HardwareAcceleration"] = "false"
|
||||
changes.append("acceleration")
|
||||
if library and isinstance(client.setdefault("Install", {}), dict) \
|
||||
and str(client["Install"].get("DefaultInstallPath", "")).rstrip("/\\") != install_path(library):
|
||||
client["Install"]["DefaultInstallPath"] = install_path(library)
|
||||
changes.append("library")
|
||||
games = config.setdefault("Games", {})
|
||||
for uid in CLIENT_32_BIT if isinstance(games, dict) else ():
|
||||
game = games.setdefault(uid, {})
|
||||
if isinstance(game, dict) and game.get("Run64BitSet") != "true":
|
||||
game.update(Run64Bit="false", Run64BitSet="true")
|
||||
changes.append("32-bit")
|
||||
if not changes:
|
||||
return None
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path + ".tmp", "w", encoding="utf-8") as f:
|
||||
json.dump(config, f, indent=4)
|
||||
os.replace(path + ".tmp", path)
|
||||
return "first" if first else " ".join(changes)
|
||||
|
||||
|
||||
def wallpaper_bmp(width, height):
|
||||
scale = min(width / 1920.0, height / 1080.0)
|
||||
ox, oy = (width - 1920 * scale) / 2, (height - 1080 * scale) / 2
|
||||
stops = ((0.0, (20, 33, 58)), (0.5, (10, 17, 32)), (1.0, WALLPAPER_EDGE))
|
||||
glow = (26, 159, 255)
|
||||
logo_px = scale * 1.6
|
||||
|
||||
def background(u, v):
|
||||
t = min(math.hypot(u - 960, v - 540) / 1150, 1.0)
|
||||
(t0, c0), (t1, c1) = (stops[0], stops[1]) if t <= 0.5 else (stops[1], stops[2])
|
||||
f = (t - t0) / (t1 - t0)
|
||||
color = [c0[i] + (c1[i] - c0[i]) * f for i in range(3)]
|
||||
d = math.hypot(u - 947.21, v - 540) / 420
|
||||
if d < 1:
|
||||
a = 0.22 * (1 - d)
|
||||
color = [color[i] * (1 - a) + glow[i] * a for i in range(3)]
|
||||
return color
|
||||
|
||||
def box(x, y, x0, y0, x1, y1):
|
||||
dx, dy = max(x0 - x, x - x1), max(y0 - y, y - y1)
|
||||
return math.hypot(max(dx, 0), max(dy, 0)) + min(max(dx, dy), 0)
|
||||
|
||||
def white(x, y):
|
||||
half = max(math.hypot(x - 63.97, y - 111.86) - 111.86, 63.97 - x)
|
||||
shape = min(box(x, y, -31.98, 0, 63.97, 223.72), half)
|
||||
hole = min(math.hypot(x - 63.98, y - 111.86) - 71.81,
|
||||
box(x, y, 56.055, -1, 71.885, 45), box(x, y, 56.055, 178.72, 71.885, 225))
|
||||
return max(shape, -hole)
|
||||
|
||||
rows = []
|
||||
pad = b"\0" * ((4 - width * 3 % 4) % 4)
|
||||
for y in range(height - 1, -1, -1):
|
||||
v = (y + 0.5 - oy) / scale
|
||||
ly = (v - 361.02) / 1.6
|
||||
row = bytearray()
|
||||
for x in range(width):
|
||||
u = (x + 0.5 - ox) / scale
|
||||
color = background(u, v)
|
||||
lx = (u - 844.84) / 1.6
|
||||
if -40 < lx < 185 and -8 < ly < 232:
|
||||
for sd, ink in ((white(lx, ly), (255, 255, 255)), (math.hypot(lx - 63.98, ly - 111.86) - 55.98, glow)):
|
||||
cover = min(max(0.5 - sd * logo_px, 0.0), 1.0)
|
||||
if cover:
|
||||
color = [color[i] * (1 - cover) + ink[i] * cover for i in range(3)]
|
||||
row += bytes((int(color[2] + 0.5), int(color[1] + 0.5), int(color[0] + 0.5)))
|
||||
rows.append(bytes(row) + pad)
|
||||
pixels = b"".join(rows)
|
||||
header = b"BM" + (54 + len(pixels)).to_bytes(4, "little") + b"\0\0\0\0" + (54).to_bytes(4, "little")
|
||||
info = (40).to_bytes(4, "little") + width.to_bytes(4, "little") + height.to_bytes(4, "little") + \
|
||||
(1).to_bytes(2, "little") + (24).to_bytes(2, "little") + b"\0" * 4 + len(pixels).to_bytes(4, "little") + \
|
||||
(2835).to_bytes(4, "little") * 2 + b"\0" * 8
|
||||
return header + info + pixels
|
||||
|
||||
|
||||
def reg_value(reg, key, name, value):
|
||||
line = '"%s"="%s"' % (name, value.replace("\\", "\\\\").replace('"', '\\"'))
|
||||
try:
|
||||
with open(reg, encoding="utf-8", errors="replace") as f:
|
||||
rows = f.read().splitlines()
|
||||
except OSError:
|
||||
return False
|
||||
inside, last = False, None
|
||||
for row in rows:
|
||||
if row.startswith("["):
|
||||
inside = row.startswith(key + " ") or row == key
|
||||
elif inside and row.startswith('"%s"=' % name):
|
||||
last = row
|
||||
if last != line:
|
||||
with open(reg, "a", encoding="utf-8") as out:
|
||||
out.write("\n%s %d\n%s\n" % (key, int(time.time()), line))
|
||||
return True
|
||||
|
||||
|
||||
def desktop_size():
|
||||
width, height = os.environ.get("BL_WIDTH", ""), os.environ.get("BL_HEIGHT", "")
|
||||
if width.isdigit() and height.isdigit() and 0 < int(width) <= 7680 and 0 < int(height) <= 4320:
|
||||
return int(width), int(height)
|
||||
return 1280, 720
|
||||
|
||||
|
||||
def wallpaper(root):
|
||||
width, height = desktop_size()
|
||||
shrink = min(1.0, WALLPAPER_MAX[0] / width, WALLPAPER_MAX[1] / height)
|
||||
width, height = max(1, round(width * shrink)), max(1, round(height * shrink))
|
||||
name = "wallpaper-%dx%d.bmp" % (width, height)
|
||||
folder = os.path.join(drive_c(root), *WALLPAPER_DIR)
|
||||
path = os.path.join(folder, name)
|
||||
reg = os.path.join(prefix(root), "pfx", "user.reg")
|
||||
if not os.path.isfile(reg):
|
||||
return False
|
||||
if not os.path.isfile(path):
|
||||
os.makedirs(folder, exist_ok=True)
|
||||
with open(path + ".tmp", "wb") as f:
|
||||
f.write(wallpaper_bmp(width, height))
|
||||
os.replace(path + ".tmp", path)
|
||||
say("drew DroidDeck's wallpaper for Battle.net's %dx%d desktop" % (width, height))
|
||||
windows = "C:\\" + "\\".join(WALLPAPER_DIR + (name,))
|
||||
reg_value(reg, DESKTOP_KEY, "Wallpaper", windows)
|
||||
reg_value(reg, DESKTOP_KEY, "TileWallpaper", "0")
|
||||
reg_value(reg, DESKTOP_KEY, "WallpaperStyle", "2" if shrink < 1 else "0")
|
||||
reg_value(reg, COLORS_KEY, "Background", "%d %d %d" % WALLPAPER_EDGE)
|
||||
return True
|
||||
|
||||
|
||||
def windows_path(root, path):
|
||||
found = re.match(r"(?i)^([cz]):[\\/](.*)$", path.strip())
|
||||
if not found:
|
||||
return None
|
||||
parts = [part for part in re.split(r"[\\/]+", found.group(2)) if part]
|
||||
if not parts or ".." in parts:
|
||||
return None
|
||||
return os.path.join(drive_c(root) if found.group(1).lower() == "c" else "/", *parts)
|
||||
|
||||
|
||||
def wow_folders(root):
|
||||
try:
|
||||
with open(os.path.join(prefix(root), "pfx", "system.reg"), encoding="utf-8", errors="replace") as f:
|
||||
rows = f.read().splitlines()
|
||||
except OSError:
|
||||
return []
|
||||
folders, location, wow = [], None, False
|
||||
for row in rows + ["["]:
|
||||
if row.startswith("["):
|
||||
if wow and location:
|
||||
folders.append(location)
|
||||
location, wow = None, False
|
||||
elif row.startswith('"InstallLocation"='):
|
||||
location = windows_path(root, row.split("=", 1)[1].strip().strip('"').replace("\\\\", "\\"))
|
||||
elif row.startswith('"UninstallString"=') and WOW_UID.search(row):
|
||||
wow = True
|
||||
return [folder for folder in dict.fromkeys(folders) if os.path.isdir(folder)]
|
||||
|
||||
|
||||
def wow_settings(root):
|
||||
changed = []
|
||||
for folder in wow_folders(root):
|
||||
try:
|
||||
flavors = sorted(name for name in os.listdir(folder) if len(name) > 2 and name.startswith("_") and name.endswith("_"))
|
||||
except OSError:
|
||||
continue
|
||||
for name in flavors:
|
||||
if not os.path.isdir(os.path.join(folder, name)):
|
||||
continue
|
||||
wtf = os.path.join(folder, name, "WTF")
|
||||
path = os.path.join(wtf, "Config.wtf")
|
||||
mark = os.path.join(wtf, GX_API_MARK)
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
except FileNotFoundError:
|
||||
text = ""
|
||||
except OSError:
|
||||
continue
|
||||
updated, notes = text, []
|
||||
if not GAMEPAD_SETTING.search(updated):
|
||||
updated += ("\n" if updated and not updated.endswith("\n") else "") + 'SET GamePadEnable "1"\n'
|
||||
notes.append("controller support on")
|
||||
first = not os.path.exists(mark)
|
||||
if first:
|
||||
before = updated
|
||||
updated, found = GX_API_SETTING.subn('SET gxApi "D3D11"', updated)
|
||||
if not found:
|
||||
updated += ("\n" if updated and not updated.endswith("\n") else "") + 'SET gxApi "D3D11"\n'
|
||||
if updated != before:
|
||||
notes.append("DirectX 11")
|
||||
if updated == text and not first:
|
||||
continue
|
||||
try:
|
||||
os.makedirs(wtf, exist_ok=True)
|
||||
if updated != text:
|
||||
with open(path + ".tmp", "w", encoding="utf-8") as f:
|
||||
f.write(updated)
|
||||
os.replace(path + ".tmp", path)
|
||||
if first:
|
||||
with open(mark, "w", encoding="utf-8"):
|
||||
pass
|
||||
except OSError as error:
|
||||
say("World of Warcraft's settings not written in %s: %s" % (path, error))
|
||||
continue
|
||||
if notes:
|
||||
changed.append(path)
|
||||
say("World of Warcraft's settings in %s: %s" % (path, ", ".join(notes)))
|
||||
return changed
|
||||
|
||||
|
||||
def steam_running(proc="/proc"):
|
||||
try:
|
||||
pids = [p for p in os.listdir(proc) if p.isdigit()]
|
||||
except OSError:
|
||||
return False
|
||||
for pid in pids:
|
||||
try:
|
||||
with open(os.path.join(proc, pid, "cmdline"), "rb") as f:
|
||||
argv = [os.path.basename(a.decode("utf-8", "replace")) for a in f.read().split(b"\0")[:2] if a]
|
||||
except OSError:
|
||||
continue
|
||||
if argv[:1] and argv[0] in ("FEX", "FEXInterpreter"):
|
||||
argv = argv[1:]
|
||||
if argv[:1] and argv[0] in STEAM_CLIENT:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def proton_env():
|
||||
env = dict(os.environ)
|
||||
if not steam_running():
|
||||
env.setdefault("PROTON_SPOOF_STEAMINPUT_VIDPID", "1")
|
||||
return env
|
||||
|
||||
|
||||
def configure(root, library=None):
|
||||
if library:
|
||||
try:
|
||||
os.makedirs(library, exist_ok=True)
|
||||
except OSError as error:
|
||||
say("%s not made: %s" % (library, error))
|
||||
try:
|
||||
change = write_config(root, library)
|
||||
except OSError as error:
|
||||
say("Battle.net's config not written: %s" % error)
|
||||
return
|
||||
try:
|
||||
wallpaper(root)
|
||||
except OSError as error:
|
||||
say("Battle.net's desktop wallpaper not set: %s" % error)
|
||||
wow_settings(root)
|
||||
if change == "first":
|
||||
say("wrote Battle.net's first config: hardware acceleration off, streaming off, closing itself as it launches a game, "
|
||||
"StarCraft on its 32-bit client")
|
||||
elif change:
|
||||
if "launch" in change:
|
||||
say("Battle.net's config: closing itself as it launches a game")
|
||||
if "library" in change:
|
||||
say("Battle.net's config: games install to %s" % library)
|
||||
if "acceleration" in change:
|
||||
say("Battle.net's config: browser hardware acceleration off")
|
||||
if "32-bit" in change:
|
||||
say("Battle.net's config: StarCraft starts its 32-bit client")
|
||||
|
||||
|
||||
def write_menu(path=MENU):
|
||||
body = ("[Desktop Entry]\nType=Application\nName=Battle.net\nComment=Blizzard's games and launcher\n"
|
||||
"Exec=%s\nIcon=applications-games\nTerminal=false\nCategories=Network;\n"
|
||||
% os.path.join(BIN, "droiddeck-battlenet"))
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
if f.read() == body:
|
||||
return
|
||||
except OSError:
|
||||
pass
|
||||
try:
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
with open(path + ".tmp", "w", encoding="utf-8") as f:
|
||||
f.write(body)
|
||||
os.replace(path + ".tmp", path)
|
||||
except OSError as error:
|
||||
say("menu entry not written: %s" % error)
|
||||
|
||||
|
||||
def ask_fex(launch_dir, wait=FEX_WAIT):
|
||||
if not launch_dir or not os.path.isdir(launch_dir):
|
||||
say("not inside a DroidDeck session; FEX stays as Components has it")
|
||||
return None
|
||||
result = os.path.join(launch_dir, FEX_RESULT)
|
||||
request = os.path.join(launch_dir, FEX_REQUEST)
|
||||
try:
|
||||
os.unlink(result)
|
||||
except OSError:
|
||||
pass
|
||||
with open(request + ".tmp", "w", encoding="utf-8") as f:
|
||||
f.write("appid=%s\n" % APP_ID)
|
||||
os.replace(request + ".tmp", request)
|
||||
deadline = time.monotonic() + wait
|
||||
while time.monotonic() < deadline:
|
||||
try:
|
||||
with open(result, encoding="utf-8") as f:
|
||||
answer = f.read().strip()
|
||||
except OSError:
|
||||
time.sleep(0.5)
|
||||
continue
|
||||
os.unlink(result)
|
||||
return answer
|
||||
return None
|
||||
|
||||
|
||||
def wine_processes(pfx, proc="/proc"):
|
||||
want = os.path.realpath(pfx).rstrip("/")
|
||||
found = []
|
||||
try:
|
||||
pids = [p for p in os.listdir(proc) if p.isdigit()]
|
||||
except OSError:
|
||||
return found
|
||||
for pid in pids:
|
||||
try:
|
||||
with open(os.path.join(proc, pid, "environ"), "rb") as f:
|
||||
env = f.read().split(b"\0")
|
||||
with open(os.path.join(proc, pid, "cmdline"), "rb") as f:
|
||||
argv = [a.decode("utf-8", "replace") for a in f.read().split(b"\0") if a]
|
||||
except OSError:
|
||||
continue
|
||||
for item in env:
|
||||
if item.startswith(b"WINEPREFIX="):
|
||||
value = item[len(b"WINEPREFIX="):].decode("utf-8", "replace")
|
||||
if os.path.realpath(value).rstrip("/") == want:
|
||||
found.append((int(pid), argv))
|
||||
break
|
||||
return found
|
||||
|
||||
|
||||
def program(argv):
|
||||
return re.split(r"[\\/]", argv[0])[-1].lower() if argv else ""
|
||||
|
||||
|
||||
def is_client(argv):
|
||||
return program(argv) == CLIENT.lower()
|
||||
|
||||
|
||||
def idle(processes):
|
||||
return all(program(argv) in IDLE for _, argv in processes)
|
||||
|
||||
|
||||
def running(pfx):
|
||||
return any(is_client(argv) for _, argv in wine_processes(pfx))
|
||||
|
||||
|
||||
def is_battlenet(argv):
|
||||
return bool(argv) and bool(CLIENT_PATH.match(argv[0].replace("/", "\\").lower()))
|
||||
|
||||
|
||||
def is_game(argv):
|
||||
if not argv or program(argv) in NOT_GAME or not re.match(r"[A-Za-z]:[\\/]", argv[0]):
|
||||
return False
|
||||
return not is_battlenet(argv)
|
||||
|
||||
|
||||
def launched(argv):
|
||||
return is_game(argv) and "-uid" in (arg.lower() for arg in argv[1:])
|
||||
|
||||
|
||||
def shares_sign_in(argv):
|
||||
return "-sso" in (arg.lower() for arg in argv[1:])
|
||||
|
||||
|
||||
def agent_up(processes):
|
||||
return any(is_client(argv) for _, argv in processes) and any(program(argv) == AGENT for _, argv in processes)
|
||||
|
||||
|
||||
class Tidy:
|
||||
|
||||
def __init__(self, settle=None, gone=None):
|
||||
self.settle = GAME_SETTLE if settle is None else settle
|
||||
self.gone = AGENT_GONE if gone is None else gone
|
||||
self.game_since = None
|
||||
self.closed_for_game = False
|
||||
self.agent_seen = False
|
||||
self.agent_lost = None
|
||||
|
||||
def __call__(self, processes, now):
|
||||
own = [(pid, argv) for pid, argv in processes if is_battlenet(argv)]
|
||||
games = [argv for _, argv in processes if launched(argv)]
|
||||
if games:
|
||||
self.game_since = self.game_since if self.game_since is not None else now
|
||||
if own and not self.closed_for_game and now - self.game_since >= self.settle:
|
||||
self.closed_for_game, self.agent_seen, self.agent_lost = True, False, None
|
||||
if any(is_client(argv) for _, argv in own) and any(shares_sign_in(argv) for argv in games):
|
||||
say("Battle.net stayed open beside a game signing in with its token: left open")
|
||||
return False
|
||||
say("the game is up: closing what is left of Battle.net (%d process(es)) to leave it their memory" % len(own))
|
||||
stop(own)
|
||||
return True
|
||||
return False
|
||||
self.game_since, self.closed_for_game = None, False
|
||||
if not any(is_client(argv) for _, argv in processes):
|
||||
self.agent_seen, self.agent_lost = False, None
|
||||
elif agent_up(processes):
|
||||
self.agent_seen, self.agent_lost = True, None
|
||||
elif self.agent_seen:
|
||||
self.agent_lost = self.agent_lost if self.agent_lost is not None else now
|
||||
if now - self.agent_lost >= self.gone:
|
||||
say("Battle.net has outlived its Agent: closing it (%d process(es))" % len(own))
|
||||
stop(own)
|
||||
notify("Battle.net was closed", "It had lost Blizzard's update service. Open it again to reconnect.",
|
||||
"dialog-warning")
|
||||
self.agent_seen, self.agent_lost = False, None
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def proton_options():
|
||||
if os.environ.get("BL_DESKTOP") == "1":
|
||||
return ["--window"]
|
||||
width, height = os.environ.get("BL_WIDTH", ""), os.environ.get("BL_HEIGHT", "")
|
||||
options = ["--desktop", "%sx%s" % (width, height)] if width.isdigit() and height.isdigit() else []
|
||||
game = os.environ.get("SteamGameId", "")
|
||||
return options + (["--game-id", game] if game.isdigit() and game != "0" else [])
|
||||
|
||||
|
||||
def stop(processes, wait=STOP_WAIT):
|
||||
pids = [pid for pid, _ in processes]
|
||||
for sig in (signal.SIGTERM, signal.SIGKILL):
|
||||
for pid in pids:
|
||||
try:
|
||||
os.kill(pid, sig)
|
||||
except OSError:
|
||||
pass
|
||||
deadline = time.monotonic() + wait
|
||||
while time.monotonic() < deadline:
|
||||
pids = [pid for pid in pids if os.path.exists("/proc/%d" % pid)]
|
||||
if not pids:
|
||||
return
|
||||
time.sleep(0.2)
|
||||
|
||||
|
||||
def queued_requests(launch_dir):
|
||||
try:
|
||||
names = os.listdir(launch_dir)
|
||||
except OSError:
|
||||
return []
|
||||
return sorted(name for name in names if REQUEST_FILE.fullmatch(name))
|
||||
|
||||
|
||||
def serve_requests(pfx, processes=None, launch_dir=None):
|
||||
launch_dir = launch_dir or os.environ.get("BL_LAUNCH_DIR")
|
||||
names = queued_requests(launch_dir) if launch_dir else []
|
||||
if not names or not agent_up(wine_processes(pfx) if processes is None else processes):
|
||||
return False
|
||||
client = os.path.join(pfx, "drive_c", *CLIENT_DIR, CLIENT)
|
||||
served = False
|
||||
for name in names:
|
||||
path = os.path.join(launch_dir, name)
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
args = [line for line in f.read().splitlines() if line]
|
||||
os.unlink(path)
|
||||
except OSError:
|
||||
continue
|
||||
if len(args) == 2 and args[0] == "install-game" and GAME_UID.fullmatch(args[1]):
|
||||
spawn(client, "run", ["--install", "--game=%s" % args[1]])
|
||||
elif len(args) == 2 and args[0] == "launch" and CODE.fullmatch(args[1]):
|
||||
spawn(client, "run", ["--exec=launch %s" % args[1]])
|
||||
else:
|
||||
say("not a request: %s" % " ".join(args))
|
||||
continue
|
||||
say("the app asked for %s" % " ".join(args))
|
||||
served = True
|
||||
return served
|
||||
|
||||
|
||||
def wait_while_open(pfx, grace, poll=None):
|
||||
deadline = time.monotonic() + grace
|
||||
seen = False
|
||||
while True:
|
||||
serve_requests(pfx)
|
||||
if running(pfx):
|
||||
seen = True
|
||||
elif seen or time.monotonic() >= deadline:
|
||||
return seen
|
||||
time.sleep(POLL if poll is None else poll)
|
||||
|
||||
|
||||
def proton(exe, args=(), verb=None, watch=None, poll=None, close_grace=None, tidy=None):
|
||||
cmd = [PROTON_RUN] + proton_options() + ["--prefix", APP_ID] + (["--verb", verb] if verb else []) + [exe] + list(args)
|
||||
say(" ".join(cmd))
|
||||
try:
|
||||
process = subprocess.Popen(cmd, env=proton_env())
|
||||
except OSError as error:
|
||||
say("%s: %s" % (PROTON_RUN, error))
|
||||
return 127, False
|
||||
seen = False
|
||||
closed_at = None
|
||||
grace = CLOSE_GRACE if close_grace is None else close_grace
|
||||
tidy = Tidy() if tidy is None else tidy
|
||||
while True:
|
||||
try:
|
||||
status = process.wait(timeout=POLL if poll is None else poll)
|
||||
return status, seen
|
||||
except subprocess.TimeoutExpired:
|
||||
pass
|
||||
if watch is None:
|
||||
continue
|
||||
processes = wine_processes(watch)
|
||||
serve_requests(watch, processes)
|
||||
now = time.monotonic()
|
||||
if tidy(processes, now):
|
||||
seen = True
|
||||
processes = wine_processes(watch)
|
||||
if any(is_client(argv) for _, argv in processes):
|
||||
seen, closed_at = True, None
|
||||
elif seen and idle(processes):
|
||||
closed_at = closed_at if closed_at is not None else now
|
||||
if now - closed_at >= grace:
|
||||
say("Battle.net closed; stopping %d process(es) it left in its prefix" % len(processes))
|
||||
stop(processes)
|
||||
closed_at = None
|
||||
else:
|
||||
closed_at = None
|
||||
|
||||
|
||||
def setup_ready(path):
|
||||
try:
|
||||
with open(path, "rb") as f:
|
||||
return f.read(2) == b"MZ" and os.path.getsize(path) >= MIN_INSTALLER
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def download(url=INSTALLER_URL, folder=CACHE):
|
||||
os.makedirs(folder, exist_ok=True)
|
||||
dest = os.path.join(folder, SETUP)
|
||||
if setup_ready(dest):
|
||||
return dest
|
||||
part = dest + ".part"
|
||||
try:
|
||||
try:
|
||||
request = urllib.request.Request(url, headers={"User-Agent": "DroidDeck"})
|
||||
with urllib.request.urlopen(request, timeout=60) as response, open(part, "wb") as f:
|
||||
shutil.copyfileobj(response, f)
|
||||
length = response.headers.get("Content-Length", "")
|
||||
if length.isdigit() and f.tell() != int(length):
|
||||
raise OSError("the download ended early")
|
||||
except (OSError, http.client.HTTPException) as error:
|
||||
if not shutil.which("curl"):
|
||||
raise
|
||||
say("download through Python failed (%s); trying curl" % error)
|
||||
if subprocess.call(["curl", "-fsSL", "--max-time", "300", "-o", part, url]) != 0:
|
||||
raise OSError("curl could not download it")
|
||||
if not setup_ready(part):
|
||||
raise OSError("not a Windows program")
|
||||
os.replace(part, dest)
|
||||
except (OSError, http.client.HTTPException) as error:
|
||||
say("installer download failed: %s" % error)
|
||||
try:
|
||||
os.unlink(part)
|
||||
except OSError:
|
||||
pass
|
||||
return dest if os.path.isfile(dest) else None
|
||||
|
||||
|
||||
def install(root, pfx, verb=None):
|
||||
setup = download()
|
||||
if setup is None:
|
||||
notify("Battle.net could not be downloaded", "Check the connection and try again.", "dialog-error")
|
||||
return False, False
|
||||
configure(root, LIBRARY)
|
||||
notify("Installing Battle.net", "Blizzard's installer opens in a window. It can take a few minutes.")
|
||||
_, seen = proton(setup, verb=verb, watch=pfx)
|
||||
return installed(root), seen
|
||||
|
||||
|
||||
def acquire(folder=CACHE):
|
||||
os.makedirs(folder, exist_ok=True)
|
||||
handle = open(os.path.join(folder, "battlenet.lock"), "w")
|
||||
try:
|
||||
fcntl.flock(handle, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except OSError:
|
||||
handle.close()
|
||||
return None
|
||||
return handle
|
||||
|
||||
|
||||
def status(root):
|
||||
pfx = os.path.join(prefix(root), "pfx")
|
||||
return {"appid": int(APP_ID), "prefix": prefix(root), "installed": installed(root),
|
||||
"launcher": launcher(root), "running": running(pfx)}
|
||||
|
||||
|
||||
def spawn(program, verb, args=()):
|
||||
cmd = [PROTON_RUN] + proton_options() + ["--prefix", APP_ID, "--verb", verb, program] + list(args)
|
||||
say(" ".join(cmd))
|
||||
try:
|
||||
os.makedirs(CACHE, exist_ok=True)
|
||||
with open(os.path.join(CACHE, "spawned.log"), "ab") as log:
|
||||
child = subprocess.Popen(cmd, stdin=subprocess.DEVNULL, stdout=log, stderr=log, start_new_session=True, env=proton_env())
|
||||
threading.Thread(target=child.wait, daemon=True).start()
|
||||
except OSError as error:
|
||||
say("%s: %s" % (PROTON_RUN, error))
|
||||
return 127
|
||||
return 0
|
||||
|
||||
|
||||
def show(root, wait=None, poll=None, args=()):
|
||||
pfx = os.path.join(prefix(root), "pfx")
|
||||
client = os.path.join(client_dir(root), CLIENT)
|
||||
deadline = time.monotonic() + (HANDOFF_WAIT if wait is None else wait)
|
||||
while True:
|
||||
processes = wine_processes(pfx)
|
||||
if any(is_client(argv) for _, argv in processes) and os.path.isfile(client) \
|
||||
and (agent_up(processes) or time.monotonic() >= deadline):
|
||||
spawn(client, "run", args)
|
||||
return None
|
||||
lock = acquire()
|
||||
if lock is not None:
|
||||
say("the other start has ended; opening Battle.net")
|
||||
return lock
|
||||
if time.monotonic() >= deadline:
|
||||
say("the other start neither opened Battle.net nor ended")
|
||||
notify("Battle.net is busy", "Another start is still running; try again in a moment.", "dialog-warning")
|
||||
return None
|
||||
time.sleep(POLL if poll is None else poll)
|
||||
|
||||
|
||||
def stop_leftovers(pfx):
|
||||
processes = wine_processes(pfx)
|
||||
if not processes:
|
||||
return True
|
||||
if not idle(processes):
|
||||
say("the prefix is in use (%s); Battle.net starts beside it" % ", ".join(sorted({program(a) for _, a in processes} - IDLE)))
|
||||
return False
|
||||
say("stopping %d process(es) a closed Battle.net left in its prefix" % len(processes))
|
||||
stop(processes)
|
||||
return True
|
||||
|
||||
|
||||
def open_client(root, reinstall=False):
|
||||
pfx = os.path.join(prefix(root), "pfx")
|
||||
write_menu()
|
||||
answer = ask_fex(os.environ.get("BL_LAUNCH_DIR"))
|
||||
say("FEX: %s" % (answer or "no answer from the app; Components' choice stays"))
|
||||
if running(pfx):
|
||||
say("Battle.net is already running in its prefix; waiting for it to close")
|
||||
wait_while_open(pfx, grace=0)
|
||||
return 0
|
||||
verb = None if stop_leftovers(pfx) else "run"
|
||||
if reinstall or not installed(root):
|
||||
done, seen = install(root, pfx, verb)
|
||||
if not done:
|
||||
notify("Battle.net did not install", "The session's desktop.log says why.", "dialog-error")
|
||||
return 1
|
||||
if wait_while_open(pfx, grace=0 if seen else START_GRACE) or seen:
|
||||
return 0
|
||||
verb = None if stop_leftovers(pfx) else "run"
|
||||
configure(root, LIBRARY)
|
||||
status_code, seen = proton(launcher(root), verb=verb, watch=pfx)
|
||||
say("Proton returned %d; Battle.net %s" % (status_code, "ran" if seen else "has not been seen yet"))
|
||||
if not (wait_while_open(pfx, grace=0 if seen else START_GRACE) or seen):
|
||||
say("Battle.net did not start (the launcher exited with %d)" % status_code)
|
||||
notify("Battle.net did not start", "The session's desktop.log says why.", "dialog-error")
|
||||
return status_code or 1
|
||||
say("Battle.net closed")
|
||||
return 0
|
||||
|
||||
|
||||
def start(exe, verb=None):
|
||||
cmd = [PROTON_RUN] + proton_options() + ["--prefix", APP_ID] + (["--verb", verb] if verb else []) + [exe]
|
||||
say(" ".join(cmd))
|
||||
try:
|
||||
return subprocess.Popen(cmd, env=proton_env())
|
||||
except OSError as error:
|
||||
say("%s: %s" % (PROTON_RUN, error))
|
||||
return None
|
||||
|
||||
|
||||
def wait_ready(pfx, wait=None, poll=None, settle=None):
|
||||
deadline = time.monotonic() + (CLIENT_WAIT if wait is None else wait)
|
||||
while True:
|
||||
count = sum(1 for _, argv in wine_processes(pfx) if is_client(argv))
|
||||
if count >= CLIENT_READY:
|
||||
time.sleep(READY_SETTLE if settle is None else settle)
|
||||
return True
|
||||
if time.monotonic() >= deadline:
|
||||
return count > 0
|
||||
time.sleep(POLL if poll is None else poll)
|
||||
|
||||
|
||||
def follow(pfx, poll=None, grace=None, tidy=None, ask=None):
|
||||
seen, gone_at = False, None
|
||||
asked, asks = None, 1
|
||||
grace = GAME_GRACE if grace is None else grace
|
||||
tidy = Tidy() if tidy is None else tidy
|
||||
while True:
|
||||
processes = wine_processes(pfx)
|
||||
serve_requests(pfx, processes)
|
||||
now = time.monotonic()
|
||||
if tidy(processes, now):
|
||||
processes = wine_processes(pfx)
|
||||
games = sorted({program(argv) for _, argv in processes if is_game(argv)})
|
||||
if games:
|
||||
if not seen:
|
||||
say("game running: %s" % ", ".join(games))
|
||||
seen, gone_at = True, None
|
||||
elif seen or not any(is_client(argv) for _, argv in processes):
|
||||
gone_at = gone_at if gone_at is not None else now
|
||||
if now - gone_at >= grace:
|
||||
say("the game has exited" if seen else "Battle.net closed before a game started")
|
||||
return seen
|
||||
else:
|
||||
gone_at = None
|
||||
asked = now if asked is None else asked
|
||||
if ask is not None and asks < LAUNCH_ASKS and now - asked >= LAUNCH_WAIT:
|
||||
say("Battle.net has not started the game yet; asking again")
|
||||
ask()
|
||||
asked, asks = now, asks + 1
|
||||
time.sleep(POLL if poll is None else poll)
|
||||
|
||||
|
||||
def launch(root, code):
|
||||
pfx = os.path.join(prefix(root), "pfx")
|
||||
client = os.path.join(client_dir(root), CLIENT)
|
||||
if not installed(root) or not os.path.isfile(client):
|
||||
say("Battle.net is not installed; %s is not launched" % code)
|
||||
notify("Battle.net is not installed", "Install it from its tile on DroidDeck's Desktop tab.", "dialog-error")
|
||||
return 1
|
||||
lock = acquire()
|
||||
try:
|
||||
own = None
|
||||
if lock is not None and not running(pfx):
|
||||
answer = ask_fex(os.environ.get("BL_LAUNCH_DIR"))
|
||||
say("FEX: %s" % (answer or "no answer from the app; Components' choice stays"))
|
||||
verb = None if stop_leftovers(pfx) else "run"
|
||||
configure(root, LIBRARY)
|
||||
own = start(launcher(root), verb)
|
||||
if own is None:
|
||||
return 127
|
||||
if not wait_ready(pfx):
|
||||
say("Battle.net did not open; %s is not launched" % code)
|
||||
notify("Battle.net did not start", "The session's desktop.log says why.", "dialog-error")
|
||||
return 1
|
||||
if code.lower().startswith("wow"):
|
||||
wow_settings(root)
|
||||
say("launching %s" % code)
|
||||
spawn(client, "run", ["--exec=launch %s" % code])
|
||||
played = follow(pfx, ask=lambda: spawn(client, "run", ["--exec=launch %s" % code]))
|
||||
if own is not None:
|
||||
leftovers = wine_processes(pfx)
|
||||
say("stopping what the Battle.net opened for %s left: %d process(es)" % (code, len(leftovers)))
|
||||
stop(leftovers)
|
||||
try:
|
||||
own.wait(timeout=STOP_WAIT * 4)
|
||||
except subprocess.TimeoutExpired:
|
||||
say("its Proton is still ending")
|
||||
return 0 if played else 1
|
||||
finally:
|
||||
if lock is not None:
|
||||
lock.close()
|
||||
|
||||
|
||||
def hand_over(root, args, wait=None):
|
||||
if not wait_ready(os.path.join(prefix(root), "pfx"), wait=HANDOVER_WAIT if wait is None else wait):
|
||||
say("Battle.net did not come up; %s not asked for" % " ".join(args))
|
||||
return False
|
||||
spawn(os.path.join(client_dir(root), CLIENT), "run", args)
|
||||
return True
|
||||
|
||||
|
||||
def install_game(root, uid):
|
||||
args = ["--install", "--game=%s" % uid]
|
||||
if installed(root) and agent_up(wine_processes(os.path.join(prefix(root), "pfx"))):
|
||||
say("asking the open Battle.net to install %s" % uid)
|
||||
spawn(os.path.join(client_dir(root), CLIENT), "run", args)
|
||||
return 0
|
||||
lock = acquire()
|
||||
if lock is None:
|
||||
say("another start holds the lock")
|
||||
lock = show(root, args=args)
|
||||
if lock is None:
|
||||
return 0
|
||||
threading.Thread(target=hand_over, args=(root, args), daemon=True).start()
|
||||
with lock:
|
||||
return open_client(root)
|
||||
|
||||
|
||||
def main(argv):
|
||||
global LIBRARY
|
||||
argv = list(argv)
|
||||
if len(argv) >= 2 and argv[0] == "--library":
|
||||
if not argv[1].startswith("/") or "\n" in argv[1]:
|
||||
say("%s is not a folder" % argv[1])
|
||||
return 2
|
||||
LIBRARY = os.path.normpath(argv[1])
|
||||
argv = argv[2:]
|
||||
action = argv[0] if argv else "open"
|
||||
launching = action == "launch" and len(argv) == 2 and CODE.fullmatch(argv[1])
|
||||
getting = action == "install-game" and len(argv) == 2 and GAME_UID.fullmatch(argv[1])
|
||||
if not (launching or getting) and (action not in ("open", "install", "status") or len(argv) > 1):
|
||||
say("usage: droiddeck-battlenet [--library DIR] [open | install | status | launch CODE | install-game ID]")
|
||||
return 2
|
||||
root = steam_root()
|
||||
if action == "status":
|
||||
print(json.dumps(status(root)))
|
||||
return 0
|
||||
os.environ["BL_BATTLENET"] = "1"
|
||||
if launching:
|
||||
say("launch %s" % argv[1])
|
||||
return launch(root, argv[1])
|
||||
if getting:
|
||||
say("install-game %s" % argv[1])
|
||||
return install_game(root, argv[1])
|
||||
say("%s (%s)" % (action, "from the menu" if not sys.stderr.isatty() else "from a terminal"))
|
||||
lock = acquire()
|
||||
if lock is None:
|
||||
say("another start holds the lock")
|
||||
lock = show(root)
|
||||
if lock is None:
|
||||
return 0
|
||||
with lock:
|
||||
return open_client(root, reinstall=action == "install")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -8,7 +8,7 @@ X64 = os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64"
|
||||
CLIENT_HOME = (os.environ.get("BL_X64_HOME") or os.path.join(HOME, ".droiddeck-x64")) if X64 else HOME
|
||||
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(CLIENT_HOME, ".local/share/Steam")
|
||||
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/droiddeck-sd/x86-64" if X64 else "/mnt/droiddeck-sd", "SD Games"))
|
||||
NOT_GAMES = {228980, 1070560, 1391110, 1493710, 1628350, 3127680, 4183110, 4185400, 4427310, 4628740}
|
||||
NOT_GAMES = {228980, 1070560, 1161040, 1391110, 1493710, 1628350, 1826330, 3127680, 4183110, 4185400, 4427310, 4628740}
|
||||
APPS_DIR = os.path.join(HOME, ".local/share/applications")
|
||||
PREFIX = "droiddeck-game-"
|
||||
NAME = re.compile(r'^\s*"name"\s*"([^"]*)"', re.M)
|
||||
|
||||
@@ -589,7 +589,8 @@ def guest_environment(fex, env):
|
||||
result["FEX_THUNKHOSTLIBS"] = fex["host_thunks"]
|
||||
result["FEX_THUNKGUESTLIBS"] = fex["guest_thunks"]
|
||||
result["FEX_THUNKCONFIG"] = os.path.join(CONFIG_DIR, "ThunksConfig.json")
|
||||
preload = [part for part in split_paths(result.get("LD_PRELOAD")) if os.path.exists(part) and not is_arm(part)]
|
||||
preload = [part for part in split_paths(result.get("LD_PRELOAD"))
|
||||
if "/" not in part or (os.path.exists(part) and not is_arm(part))]
|
||||
library_path = [part for part in (result.get("LD_LIBRARY_PATH") or "").split(":")
|
||||
if part and "arm64" not in part and "aarch64" not in part]
|
||||
for name, parts in (("LD_PRELOAD", preload), ("LD_LIBRARY_PATH", library_path)):
|
||||
@@ -671,15 +672,26 @@ def launch(command, env, mode, decide=None):
|
||||
return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest)
|
||||
|
||||
|
||||
def game_environment(env):
|
||||
def game_environment(env, command):
|
||||
try:
|
||||
game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env"))
|
||||
env = game_env["game_gpu"](env)
|
||||
app = game_env["game_id"](env) or env.get("SteamAppId") or env.get("SteamGameId")
|
||||
if not app:
|
||||
return env
|
||||
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
|
||||
return game_env["apply_config"](env, json.load(source), str(app))
|
||||
fixes = {}
|
||||
game = game_env["Game"](resolve(command[0], env), command[1:])
|
||||
for check in game_env["FIXES"]:
|
||||
found = check(game)
|
||||
if found and found[0]:
|
||||
fixes.update(found[0])
|
||||
say(found[2])
|
||||
try:
|
||||
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
|
||||
config = json.load(source)
|
||||
except FileNotFoundError:
|
||||
config = {"version": 1}
|
||||
return game_env["apply_config"](env, config, str(app), fixes)
|
||||
except FileNotFoundError:
|
||||
return env
|
||||
except Exception as error:
|
||||
@@ -810,7 +822,7 @@ def main(argv):
|
||||
return 0
|
||||
if not command:
|
||||
return 2
|
||||
return launch(command, game_environment(dict(os.environ)), os.environ.get("DROIDDECK_FEX", "auto"))
|
||||
return launch(command, game_environment(dict(os.environ), command), os.environ.get("DROIDDECK_FEX", "auto"))
|
||||
if action == "run":
|
||||
try:
|
||||
mode, decide, command = parse_run(args)
|
||||
|
||||
@@ -3,6 +3,7 @@ set -u
|
||||
export LANG=C.UTF-8
|
||||
step() { echo "== STEP $*"; }
|
||||
fail() { echo "== FAIL $*"; exit 1; }
|
||||
[ "$(id -u)" = 0 ] || fail "needs root: install Flatpak from the launcher's Store, which runs this as root"
|
||||
|
||||
PACKAGES="flatpak ostree appstream libxmlb libmalcontent libfyaml accountsservice composefs xdg-dbus-proxy"
|
||||
while read -r pkg probe; do
|
||||
@@ -48,10 +49,13 @@ if [ ! -f /etc/pacman.d/gnupg/pubring.gpg ] && [ ! -f /etc/pacman.d/gnupg/pubrin
|
||||
fi
|
||||
|
||||
step "Reading the package lists"
|
||||
pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy >/dev/null 2>&1 \
|
||||
|| pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1 | tail -3 \
|
||||
|| fail "could not reach the Arch Linux ARM mirrors"
|
||||
[ -f "$WORK/db/sync/extra.db" ] || fail "could not reach the Arch Linux ARM mirrors"
|
||||
sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1) \
|
||||
|| sync_log=$(pacman --config "$CONF" --dbpath "$WORK/db" --noconfirm -Sy 2>&1)
|
||||
if [ ! -f "$WORK/db/sync/extra.db" ]; then
|
||||
printf '%s\n' "$sync_log" | tail -3
|
||||
reason=$(printf '%s\n' "$sync_log" | grep -m1 -i '^error' | cut -c1-160)
|
||||
fail "could not reach the Arch Linux ARM mirrors${reason:+ ($reason)}"
|
||||
fi
|
||||
|
||||
step "Downloading Flatpak"
|
||||
out=$(pacman --config "$CONF" --dbpath "$WORK/db" --cachedir "$WORK/pkg" --noconfirm -Sw -dd $PACKAGES 2>&1)
|
||||
|
||||
@@ -6,6 +6,7 @@ import re
|
||||
import runpy
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
GAME_TU_DEBUG = "DROIDDECK_GAME_TU_DEBUG"
|
||||
@@ -87,6 +88,12 @@ def dotnet_memory_ordering(game):
|
||||
return DOTNET_FEX, [], ".NET runtime: FEX with full TSO and without multiblock"
|
||||
|
||||
|
||||
@fix
|
||||
def unity_memory_ordering(game):
|
||||
if {"unityplayer.so", "gameassembly.so", "unityplayer.dll"} & game.files:
|
||||
return {"FEX_TSOENABLED": "1"}, [], "Unity: FEX with TSO"
|
||||
|
||||
|
||||
@fix
|
||||
def godot_vulkan(game):
|
||||
if is_godot(game) and not game.has_arg("--rendering-driver"):
|
||||
@@ -114,6 +121,35 @@ def arkham_city_x87(game):
|
||||
return {"FEX_X87REDUCEDPRECISION": "0"}, [], "Batman: Arkham City: FEX with full x87 precision"
|
||||
|
||||
|
||||
|
||||
@fix
|
||||
def protonfixes_off(game):
|
||||
if game.stem in ("blackops3", "darksoulsremastered"):
|
||||
return {"PROTONFIXES_DISABLE": "1"}, [], "umu-protonfixes off (its ALSA audio and VC++ installer steps fail here)"
|
||||
|
||||
|
||||
@fix
|
||||
def caravan_sandwitch_feature_level(game):
|
||||
if "caravansandwitch.exe" in game.files or game.stem == "caravansandwitch-win64-shipping":
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Caravan SandWitch: D3D12 feature level 12_1 (12_2 hands it mesh shader pipelines vkd3d-proton cannot build)"
|
||||
|
||||
|
||||
@fix
|
||||
def robocop_rogue_city_feature_level(game):
|
||||
"""vkd3d-proton turns mesh shaders off on Adreno, but 12_2 still advertises them, and UE5 then builds mesh
|
||||
pipelines with no pipeline layout that crash Turnip on launch."""
|
||||
if "robocop.exe" in game.files or game.stem == "robocop-win64-shipping":
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "RoboCop: Rogue City: D3D12 feature level 12_1"
|
||||
|
||||
|
||||
@fix
|
||||
def cyberpunk_feature_level(game):
|
||||
if game.stem == "cyberpunk2077" or (
|
||||
game.stem == "redprelauncher"
|
||||
and os.path.isfile(os.path.join(os.path.dirname(game.exe), "bin", "x64", "Cyberpunk2077.exe"))
|
||||
):
|
||||
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Cyberpunk 2077: D3D12 feature level 12_1"
|
||||
|
||||
def skip_red_launcher(command):
|
||||
"""Cyberpunk 2077's prelauncher opens REDlauncher, a Qt WebEngine window that hands over to the
|
||||
game half a minute later and then stays up beside it, well over a core busy for as long as the
|
||||
@@ -127,6 +163,61 @@ def skip_red_launcher(command):
|
||||
return command
|
||||
|
||||
|
||||
UBISOFT_LAUNCHER = "drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher"
|
||||
UBISOFT_SETTINGS = "drive_c/users/steamuser/AppData/Local/Ubisoft Game Launcher/settings.yaml"
|
||||
|
||||
|
||||
def overlay_off(text):
|
||||
lines = text.splitlines()
|
||||
try:
|
||||
start = next(i for i, line in enumerate(lines) if re.fullmatch(r"overlay:\s*(#.*)?", line))
|
||||
except StopIteration:
|
||||
if lines and not lines[-1].strip():
|
||||
lines.pop()
|
||||
return "\n".join(lines + ["overlay:", " enabled: false", " warning_enabled: false"]) + "\n"
|
||||
end = start + 1
|
||||
for index in range(start + 1, len(lines)):
|
||||
if lines[index].strip() and not lines[index].startswith(" "):
|
||||
break
|
||||
if lines[index].strip():
|
||||
end = index + 1
|
||||
block = lines[start + 1:end]
|
||||
for key in ("enabled", "warning_enabled"):
|
||||
entry = " %s: false" % key
|
||||
found = [i for i, line in enumerate(block) if line.split(":", 1)[0] == " " + key]
|
||||
if found:
|
||||
block[found[0]] = entry
|
||||
else:
|
||||
block.append(entry)
|
||||
return "\n".join(lines[:start + 1] + block + lines[end:]) + "\n"
|
||||
|
||||
|
||||
def ubisoft_overlay_off(env):
|
||||
prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx"
|
||||
if not (prefix / UBISOFT_LAUNCHER).is_dir():
|
||||
return
|
||||
settings = prefix / UBISOFT_SETTINGS
|
||||
try:
|
||||
text = settings.read_text(encoding="utf-8") if settings.exists() else ""
|
||||
updated = overlay_off(text)
|
||||
if updated == text:
|
||||
return
|
||||
settings.parent.mkdir(parents=True, exist_ok=True)
|
||||
handle, staged = tempfile.mkstemp(prefix=".settings-", dir=settings.parent)
|
||||
try:
|
||||
with os.fdopen(handle, "w", encoding="utf-8") as target:
|
||||
target.write(updated)
|
||||
if settings.exists():
|
||||
os.chmod(staged, settings.stat().st_mode & 0o7777)
|
||||
os.replace(staged, settings)
|
||||
except BaseException:
|
||||
os.unlink(staged)
|
||||
raise
|
||||
print("droiddeck-game-env: Ubisoft Connect overlay turned off", file=sys.stderr)
|
||||
except (OSError, UnicodeDecodeError) as error:
|
||||
print("droiddeck-game-env: Ubisoft Connect overlay left as is (%s)" % error, file=sys.stderr)
|
||||
|
||||
|
||||
def offline_without_anticheat(command, env):
|
||||
"""Start the configured game executable when the player opts into launching without EAC."""
|
||||
if (env.get("DROIDDECK_ANTICHEAT_OFFLINE") != "1" or len(command) <= 2
|
||||
@@ -196,6 +287,58 @@ def game_gpu(env):
|
||||
return result
|
||||
|
||||
|
||||
def vram_cap(env):
|
||||
"""Puts the session's VRAM cap ahead of the game's own DXVK settings, so a game profile can still raise it."""
|
||||
value = env.get("BL_VRAM_MB", "")
|
||||
if not re.fullmatch(r"[1-9][0-9]{0,6}", value):
|
||||
return env
|
||||
result = env.copy()
|
||||
cap = "dxgi.maxDeviceMemory = %d" % int(value)
|
||||
own = result.get("DXVK_CONFIG", "").strip().strip(";").strip()
|
||||
result["DXVK_CONFIG"] = cap + "; " + own if own else cap
|
||||
return result
|
||||
|
||||
|
||||
def parse_cores(text):
|
||||
"""CPU numbers from a list such as "0-3,6"; None when the text is not one."""
|
||||
cores = set()
|
||||
for part in text.replace(" ", "").split(","):
|
||||
match = re.fullmatch(r"(\d{1,3})(?:-(\d{1,3}))?", part)
|
||||
if not match:
|
||||
return None
|
||||
first, last = int(match.group(1)), int(match.group(2) or match.group(1))
|
||||
if last < first:
|
||||
return None
|
||||
cores.update(range(first, last + 1))
|
||||
return cores or None
|
||||
|
||||
|
||||
def online_cores():
|
||||
try:
|
||||
with open("/sys/devices/system/cpu/online") as f:
|
||||
cores = parse_cores(f.read().strip())
|
||||
except OSError:
|
||||
cores = None
|
||||
return cores or os.sched_getaffinity(0) | set(range(os.cpu_count() or 0))
|
||||
|
||||
|
||||
def game_cores(env):
|
||||
"""Pins the game to the cores its profile names, in place of the session's game cores."""
|
||||
text = env.get("DROIDDECK_GAME_CORES", "").strip()
|
||||
if not text:
|
||||
return
|
||||
cores = parse_cores(text)
|
||||
chosen = cores & online_cores() if cores else None
|
||||
if not chosen:
|
||||
print("droiddeck-game-env: ignoring game cores %r" % text, file=sys.stderr)
|
||||
return
|
||||
try:
|
||||
os.sched_setaffinity(0, chosen)
|
||||
print("droiddeck-game-env: game cores %s" % ",".join(map(str, sorted(chosen))), file=sys.stderr)
|
||||
except OSError as error:
|
||||
print("droiddeck-game-env: could not use game cores %r (%s)" % (text, error), file=sys.stderr)
|
||||
|
||||
|
||||
def apply_config(env, config, app_id, fixes=None):
|
||||
if config.get("version") != 1:
|
||||
raise ValueError("unsupported environment configuration")
|
||||
@@ -497,6 +640,7 @@ def main():
|
||||
fixes = {}
|
||||
if waiting:
|
||||
command = skip_red_launcher(command)
|
||||
ubisoft_overlay_off(env)
|
||||
fixes, extra, notes = engine_fixes(command[2], command[3:]) if len(command) > 2 else ({}, [], [])
|
||||
for note in notes:
|
||||
print("droiddeck-game-env: " + note, file=sys.stderr)
|
||||
@@ -528,7 +672,9 @@ def main():
|
||||
command = offline_without_anticheat(command, env)
|
||||
if mic_enabled == "0":
|
||||
env["BANNER_AUDIO_DIRECT_MIC"] = "0"
|
||||
env = vram_cap(env)
|
||||
env = force_ssbs(command, env)
|
||||
game_cores(env)
|
||||
try:
|
||||
xbox = runpy.run_path(str(Path(__file__).with_name("droiddeck-xbox")))
|
||||
except Exception as error:
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/python3
|
||||
"""Runs a Windows program with the Proton the Steam client has chosen for it.
|
||||
|
||||
droiddeck-proton-run [--window] PROGRAM [ARGS...]
|
||||
droiddeck-proton-run [--window] [--prefix ID] [--verb run] [--game-id ID] [--desktop WxH] PROGRAM [ARGS...]
|
||||
droiddeck-proton-run --app ID [--dir FOLDER] [--options TEXT] [PROGRAM [ARGS...]]
|
||||
|
||||
The program belongs to an installed Steam game when it sits in one's folder, to a prefix when it
|
||||
@@ -10,10 +10,15 @@ its own, under the id the client gives a new shortcut. That title's CompatToolMa
|
||||
config.vdf picks the tool, else the client's default for all other titles ("0"). The tool is
|
||||
started as the client starts it - its toolmanifest's command line, the waitforexitandrun verb and
|
||||
the STEAM_COMPAT_* environment - so its wrapper applies the game's settings, components and audio.
|
||||
--window keeps the program in the desktop's own window, drawn with WineD3D.
|
||||
--window keeps the program in the desktop's own window, drawn with WineD3D on the desktop's software
|
||||
GL (llvmpipe): KWin there composites in software, and the session's zink finds no device.
|
||||
--prefix ID puts the program in compatdata/ID whatever it is. --verb run starts it beside what already
|
||||
runs in the prefix, which waitforexitandrun would wait for; the wrapper's launch-time steps are skipped.
|
||||
--game-id ID keeps the id of the launch it runs for: gamescope shows the windows that carry the id Steam launched.
|
||||
--app starts one game without the Steam client (its Start without Steam): a Steam game's default
|
||||
Windows launch option from appinfo.vdf when no program is given, else the program in that
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options).
|
||||
shortcut's own prefix, started in --dir with the shortcut's launch options (--options). Without
|
||||
--options it takes the launch options set in the client's Properties for that game or shortcut.
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
@@ -30,7 +35,10 @@ BIN_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||
STATE = os.path.join(HOME, ".local", "share", "droiddeck-compat", "state.json")
|
||||
EXTRA_LIBRARIES = ("/mnt/droiddeck", "/mnt/droiddeck-sd")
|
||||
SYSTEM_TOOLS = ("/usr/share/steam/compatibilitytools.d", "/usr/local/share/steam/compatibilitytools.d")
|
||||
DESKTOP_GL = {"LIBGL_ALWAYS_SOFTWARE": "1", "GALLIUM_DRIVER": "llvmpipe"}
|
||||
NOT_DESKTOP_GL = ("MESA_LOADER_DRIVER_OVERRIDE", "LIBGL_KOPPER_DRI2")
|
||||
VERB = "waitforexitandrun"
|
||||
VERBS = (VERB, "run")
|
||||
SHORTCUT_BIT = 0x80000000
|
||||
STEAM_APP_LIMIT = 2 ** 31
|
||||
|
||||
@@ -185,9 +193,9 @@ def steam_game(program, libs):
|
||||
def prefix_of(program):
|
||||
for folder, below in ancestors(program):
|
||||
parent = os.path.dirname(folder)
|
||||
if below == "pfx" and os.path.basename(parent) == "compatdata" and os.path.basename(folder).isdigit():
|
||||
if below == "pfx" and os.path.basename(parent) == "compatdata" and re.fullmatch(r"-?[0-9]+", os.path.basename(folder)):
|
||||
library = os.path.dirname(os.path.dirname(parent))
|
||||
return Target(os.path.basename(folder), folder, os.path.dirname(program), library, "prefix")
|
||||
return Target(str(int(os.path.basename(folder)) % 2 ** 32), folder, os.path.dirname(program), library, "prefix")
|
||||
return None
|
||||
|
||||
|
||||
@@ -230,10 +238,68 @@ def shortcut_entries(root):
|
||||
return entries
|
||||
|
||||
|
||||
def prefix_folder(root, appid):
|
||||
"""The prefix folder the client made for [appid], under either spelling of the id."""
|
||||
folder = os.path.join(root, "steamapps", "compatdata")
|
||||
try:
|
||||
names = sorted(os.listdir(folder))
|
||||
except OSError:
|
||||
names = []
|
||||
candidates = []
|
||||
for name in names:
|
||||
if not re.fullmatch(r"-?[0-9]+", name):
|
||||
continue
|
||||
try:
|
||||
matches = int(name) % 2 ** 32 == appid % 2 ** 32
|
||||
except ValueError:
|
||||
continue
|
||||
match = os.path.join(folder, name)
|
||||
if matches and os.path.isdir(match):
|
||||
candidates.append((os.path.isdir(os.path.join(match, "pfx")),
|
||||
name == str(appid % 2 ** 32), name, match))
|
||||
if candidates:
|
||||
return min(candidates, key=lambda item: (not item[0], not item[1], item[2]))[3]
|
||||
return os.path.join(folder, str(appid % 2 ** 32))
|
||||
|
||||
|
||||
def vdf_string(token):
|
||||
return re.sub(r'\\(.)', r'\1', token[1:-1]) if token.startswith('"') else ""
|
||||
|
||||
|
||||
def steam_options(app, root):
|
||||
"""The launch options the client keeps for a game (localconfig.vdf) or a shortcut (shortcuts.vdf)."""
|
||||
try:
|
||||
tool = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-steam-shortcuts"))
|
||||
account = tool["account_dir"](root)
|
||||
if not account:
|
||||
return ""
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
with open(os.path.join(account, "config", "shortcuts.vdf"), "rb") as f:
|
||||
shortcuts = tool["parse"](f.read()).get("shortcuts", {})
|
||||
for value in shortcuts.values():
|
||||
if isinstance(value, dict) and (value.get("appid", value.get("AppId")) or 0) & 0xFFFFFFFF == int(app):
|
||||
options = value.get("LaunchOptions", value.get("launchoptions", ""))
|
||||
return options if isinstance(options, str) else ""
|
||||
return ""
|
||||
tokens = compat()["tokenize"](read_text(os.path.join(account, "config", "localconfig.vdf")) or "")
|
||||
start = compat()["find_block"](tokens, ["UserLocalConfigStore", "Software", "Valve", "Steam", "apps", app])
|
||||
if start is None:
|
||||
return ""
|
||||
end, depth = compat()["block_end"](tokens, start), 0
|
||||
for i in range(start + 1, end):
|
||||
if tokens[i] in ("{", "}"):
|
||||
depth += 1 if tokens[i] == "{" else -1
|
||||
elif depth == 0 and tokens[i].lower() == '"launchoptions"' and i + 1 < end:
|
||||
return vdf_string(tokens[i + 1])
|
||||
except (OSError, ValueError, IndexError, KeyError, TypeError, AttributeError, struct.error):
|
||||
pass
|
||||
return ""
|
||||
|
||||
|
||||
def shortcut(program, root):
|
||||
for appid, exe, start in shortcut_entries(root):
|
||||
if same_file(program, exe):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
return Target(appid, prefix_folder(root, appid),
|
||||
os.path.dirname(program), root, "shortcut", start if os.path.isdir(start) else None)
|
||||
return None
|
||||
|
||||
@@ -250,10 +316,19 @@ def locate(program, root):
|
||||
if found:
|
||||
return found
|
||||
appid = own_id(program)
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
return Target(appid, prefix_folder(root, appid),
|
||||
os.path.dirname(program), root, "own")
|
||||
|
||||
|
||||
def fixed(program, root, appid):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)),
|
||||
os.path.dirname(program), root, "fixed")
|
||||
|
||||
|
||||
def prefix_id(value):
|
||||
return value if value.isdigit() and not value.startswith("0") and int(value) <= 0xFFFFFFFF else None
|
||||
|
||||
|
||||
def split_words(text):
|
||||
try:
|
||||
return shlex.split(text or "")
|
||||
@@ -325,7 +400,8 @@ def steam_launch(appid, root):
|
||||
|
||||
|
||||
def shortcut_target(appid, program, start, root):
|
||||
return Target(appid, os.path.join(root, "steamapps", "compatdata", str(appid)), os.path.dirname(program), root,
|
||||
appid = int(appid) % 2 ** 32
|
||||
return Target(str(appid), prefix_folder(root, appid), os.path.dirname(program), root,
|
||||
"shortcut", start if start and os.path.isdir(start) else None)
|
||||
|
||||
|
||||
@@ -337,7 +413,7 @@ def steam_launches(target, program, root):
|
||||
return os.path.relpath(program, target.install).replace(os.sep, "/").lower() in entry.get("launch", ())
|
||||
|
||||
|
||||
def environment(env, target, tool_folder, root, window=False):
|
||||
def environment(env, target, tool_folder, root, window=False, game_id=None):
|
||||
env = dict(env)
|
||||
steamapps = [os.path.join(lib, "steamapps") for lib in libraries(root)]
|
||||
env.update({
|
||||
@@ -355,28 +431,52 @@ def environment(env, target, tool_folder, root, window=False):
|
||||
else:
|
||||
game = str(number << 32 | 0x02000000)
|
||||
env.update(SteamAppId="0", STEAM_COMPAT_APP_ID="0", SteamGameId=game, SteamOverlayGameId=game)
|
||||
if game_id:
|
||||
env.update(SteamGameId=game_id, SteamOverlayGameId=game_id)
|
||||
if window:
|
||||
env.setdefault("PROTON_USE_WINED3D", "1")
|
||||
env.update(DESKTOP_GL)
|
||||
for name in NOT_DESKTOP_GL:
|
||||
env.pop(name, None)
|
||||
return env
|
||||
|
||||
|
||||
def windows_path(path):
|
||||
def windows_path(path, compatdata=None):
|
||||
if compatdata:
|
||||
drive = os.path.join(compatdata, "pfx", "drive_c")
|
||||
inside = os.path.relpath(path, drive)
|
||||
if inside != "." and not inside.startswith(".."):
|
||||
return "C:\\" + inside.replace("/", "\\")
|
||||
return "Z:" + path.replace("/", "\\")
|
||||
|
||||
|
||||
def arguments(program, args):
|
||||
def arguments(program, args, desktop=None, compatdata=None):
|
||||
if program.lower().endswith(".msi"):
|
||||
return ["msiexec", "/i", windows_path(program)] + args
|
||||
if desktop:
|
||||
return ["explorer.exe", "/desktop=droiddeck,%s" % desktop, windows_path(program, compatdata)] + args
|
||||
return [program] + args
|
||||
|
||||
|
||||
def main(argv):
|
||||
window = False
|
||||
app, start, options = None, None, ""
|
||||
prefix = None
|
||||
verb = VERB
|
||||
game_id = None
|
||||
desktop = None
|
||||
app, start, options = None, None, None
|
||||
while argv and argv[0].startswith("--"):
|
||||
option = argv.pop(0)
|
||||
if option == "--window":
|
||||
window = True
|
||||
elif option == "--prefix" and argv and prefix_id(argv[0]):
|
||||
prefix = argv.pop(0)
|
||||
elif option == "--verb" and argv and argv[0] in VERBS:
|
||||
verb = argv.pop(0)
|
||||
elif option == "--game-id" and argv and argv[0].isdigit() and argv[0] != "0":
|
||||
game_id = argv.pop(0)
|
||||
elif option == "--desktop" and argv and re.fullmatch(r"[1-9][0-9]{2,4}x[1-9][0-9]{2,4}", argv[0]):
|
||||
desktop = argv.pop(0)
|
||||
elif option in ("--app", "--dir", "--options") and argv:
|
||||
value = argv.pop(0)
|
||||
if option == "--app":
|
||||
@@ -394,9 +494,11 @@ def main(argv):
|
||||
say("%s is not an app id" % app)
|
||||
return 2
|
||||
if not argv and app is None:
|
||||
say("usage: droiddeck-proton-run [--window] PROGRAM [ARGS...]")
|
||||
say("usage: droiddeck-proton-run [--window] [--prefix ID] [--verb run] [--game-id ID] [--desktop WxH] PROGRAM [ARGS...]")
|
||||
return 2
|
||||
root = os.environ.get("STEAM_COMPAT_CLIENT_INSTALL_PATH") or STEAM_ROOT
|
||||
if options is None:
|
||||
options = steam_options(app, root) if app is not None else ""
|
||||
extra, args = split_options(options)
|
||||
if not argv:
|
||||
if int(app) >= STEAM_APP_LIMIT:
|
||||
@@ -416,6 +518,8 @@ def main(argv):
|
||||
args = args + argv[1:]
|
||||
if app is not None and int(app) >= STEAM_APP_LIMIT:
|
||||
target = shortcut_target(app, program, start, root)
|
||||
elif prefix:
|
||||
target = fixed(program, root, prefix)
|
||||
else:
|
||||
target = locate(program, root)
|
||||
available = tools(root)
|
||||
@@ -425,7 +529,7 @@ def main(argv):
|
||||
return 69
|
||||
folder, command = available[name]
|
||||
os.makedirs(target.compatdata, exist_ok=True)
|
||||
env = environment(os.environ, target, folder, root, window)
|
||||
env = environment(os.environ, target, folder, root, window, game_id)
|
||||
env.update(extra)
|
||||
say("%s with %s (%s), %s prefix %s%s" % (program, name, why, target.kind, target.compatdata,
|
||||
", without the Steam client" if app is not None else ""))
|
||||
@@ -434,7 +538,7 @@ def main(argv):
|
||||
except OSError:
|
||||
os.chdir(os.path.dirname(program))
|
||||
entry = os.path.join(folder, command)
|
||||
os.execve(entry, [entry, VERB] + arguments(program, args), env)
|
||||
os.execve(entry, [entry, verb] + arguments(program, args, desktop, target.compatdata), env)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -24,7 +24,7 @@ read_scripts() { xargs -0 -r awk -v want="${1:-redists}" '
|
||||
proc[depth] = 1
|
||||
program = tolower(part[4])
|
||||
sub(/.*[\\\/]/, "", program)
|
||||
if (program ~ /vulkan/) vulkan[depth] = 1
|
||||
if (program ~ /vulkan|uplay|ubisoft/) vulkan[depth] = 1
|
||||
next
|
||||
}
|
||||
if (n == 3) pending = part[2]
|
||||
@@ -243,7 +243,7 @@ for system in "${regs[@]}"; do
|
||||
had=()
|
||||
for line in "${kept[@]}"; do had[$line]=1; done
|
||||
printf '%s\n' "${other[@]}" "${kept[@]}" >"$seeded"
|
||||
echo "== took Vulkan runtime markers out of $reg"
|
||||
echo "== took Vulkan runtime and Ubisoft Connect markers out of $reg"
|
||||
fi
|
||||
if [ ${#had[@]} -gt 0 ] && { [ -z "$id" ] || [ "$id" != "$prev" ]; }; then
|
||||
declare -A held=()
|
||||
|
||||
@@ -86,12 +86,6 @@ run_gamescope() (
|
||||
|
||||
collect_steam_logs() {
|
||||
[ -n "${BL_DEBUG_DIR:-}" ] || return 0
|
||||
local steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
|
||||
[ "${steam_x64:-0}" = 1 ] && steam_root=${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam
|
||||
mkdir -p "$BL_DEBUG_DIR/steam" 2>/dev/null || return 0
|
||||
[ -d "$steam_root/logs" ] && find "$steam_root/logs" -maxdepth 1 -type f -size -8192k \
|
||||
-exec cp {} "$BL_DEBUG_DIR/steam/" \; 2>/dev/null
|
||||
[ "${steam_x64:-0}" = 0 ] && [ -f "$HOME/.steam/steam/logs/steamwebhelper.log" ] && cp "$HOME/.steam/steam/logs/steamwebhelper.log" "$BL_DEBUG_DIR/steam/" 2>/dev/null
|
||||
local sync_store=$HOME/.local/share/droiddeck-esync sync_file
|
||||
if [ -d "$sync_store" ] && mkdir -p "$BL_DEBUG_DIR/droiddeck-esync" 2>/dev/null; then
|
||||
for sync_file in launches.log tools.tsv wanted.tsv prefixes.json; do
|
||||
@@ -102,7 +96,6 @@ collect_steam_logs() {
|
||||
if [ -d "$fex_state" ] && mkdir -p "$BL_DEBUG_DIR/droiddeck-fex" 2>/dev/null; then
|
||||
cp "$fex_state/status.json" "$fex_state/config/Config.json" "$BL_DEBUG_DIR/droiddeck-fex/" 2>/dev/null
|
||||
fi
|
||||
echo "== steam logs copied to $BL_DEBUG_DIR/steam"
|
||||
}
|
||||
trap 'collect_steam_logs 2>/dev/null || true' TERM INT HUP
|
||||
if [ -n "${BL_VK_DRIVER:-}" ]; then
|
||||
@@ -218,20 +211,31 @@ if [ -z "${BL_INSIDE:-}" ]; then
|
||||
width=${BL_WIDTH:-1280}
|
||||
height=${BL_HEIGHT:-720}
|
||||
nested=$width
|
||||
nested_h=$height
|
||||
if [ "${BL_FOLLOW_OUTPUT:-0}" = 1 ]; then
|
||||
echo "== gamescope: the output follows the screen (${width}x${height} to start)"
|
||||
elif [ "$mode" = steam ] && [ "${BL_GAMESCOPE_STRETCH_16X9:-0}" = 1 ]; then
|
||||
wide=$(( (height * 16 + 4) / 9 / 2 * 2 ))
|
||||
tall=$(( (width * 9 + 8) / 16 / 2 * 2 ))
|
||||
if [ "$wide" -gt "$width" ]; then
|
||||
nested=$wide
|
||||
echo "== gamescope: games at ${nested}x${height} stretched to the ${width}x${height} output"
|
||||
elif [ "$tall" -gt "$height" ]; then
|
||||
nested_h=$tall
|
||||
fi
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
echo "== gamescope: games at ${nested}x${nested_h} stretched to the ${width}x${height} output"
|
||||
fi
|
||||
fi
|
||||
if [ "$mode" = steam ]; then
|
||||
# Off unless Performance asks for it. Compositing the cursor here adds a second
|
||||
# plane on the phone's compositor; a controller-driven cursor is the reason to turn it on.
|
||||
if [ "$mode" = steam ] && [ "${BL_CURSOR_COMPOSITE:-0}" = 1 ]; then
|
||||
export gamescope_cursor_composite=2
|
||||
fi
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$height")
|
||||
[ "$nested" != "$width" ] && args+=(-S stretch) && export BL_STRETCHED=1
|
||||
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$nested_h")
|
||||
if [ "$nested" != "$width" ] || [ "$nested_h" != "$height" ]; then
|
||||
args+=(-S stretch)
|
||||
export BL_STRETCHED=1
|
||||
fi
|
||||
if [ "${BL_FPS:-0}" -gt 0 ]; then
|
||||
args+=(-r "$BL_FPS")
|
||||
elif [ "${BL_REFRESH:-0}" -gt 0 ]; then
|
||||
@@ -401,8 +405,14 @@ case $mode in
|
||||
steam_root=$XDG_DATA_HOME/Steam
|
||||
if [ -f "${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam/local.vdf" ]; then
|
||||
droiddeck-steam-x64 --sync-login || true
|
||||
droiddeck-steam-x64 --share || true
|
||||
fi
|
||||
steam_client=("$steam_root/steamrtarm64/steam")
|
||||
_bl_srt_shim=$HOME/.droiddeck-steamrt-shim
|
||||
if droiddeck-steamrt-shim "$steam_root/steamrtarm64" "$_bl_srt_shim"; then
|
||||
echo "== steam: Valve containerized the arm64 Steam client (it carries a Steam Runtime container); starting it through $_bl_srt_shim"
|
||||
steam_client=(env STEAM_RUNTIME_STEAMRT="$_bl_srt_shim" PATH="$_bl_srt_shim/bin:$PATH" "${steam_client[@]}")
|
||||
fi
|
||||
fi
|
||||
_bl_proton_root=$steam_root
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
@@ -445,48 +455,135 @@ case $mode in
|
||||
fi
|
||||
if [ "${BL_ZRAM:-0}" = 1 ]; then
|
||||
step "zRAM compression: on"
|
||||
[ "${BL_ZRAM_CLIENT:-1}" = 1 ] || step "zRAM: Steam is not compressed while games run (turned off in Performance)"
|
||||
_bl_ram_cap=0
|
||||
case ${BL_RAM_CAP_MB:-} in
|
||||
''|0) ;;
|
||||
*[!0-9]*|0*|???????*) step "RAM cap: ignored invalid value '$BL_RAM_CAP_MB'" ;;
|
||||
*) _bl_ram_cap=$((BL_RAM_CAP_MB * 1024)); step "RAM cap: ${BL_RAM_CAP_MB} MB" ;;
|
||||
esac
|
||||
(
|
||||
bl_zram_scan() {
|
||||
_bl_game=0 _bl_pids=()
|
||||
_bl_game=0 _bl_pids=() _bl_others=()
|
||||
for _d in /proc/[0-9]*; do
|
||||
[ "${_d#/proc/}" != "$BASHPID" ] || continue
|
||||
# Under FEX the program is FEX's first argument.
|
||||
{ IFS= read -r -d '' _c && case ${_c##*/} in FEX|FEXInterpreter) IFS= read -r -d '' _c ;; esac; } \
|
||||
2>/dev/null < "$_d/cmdline" || continue
|
||||
case ${_c##*/} in
|
||||
reaper) _bl_game=1 ;;
|
||||
steam|steamwebhelper) _bl_pids+=("${_d#/proc/}") ;;
|
||||
*) _bl_others+=("${_d#/proc/}") ;;
|
||||
esac
|
||||
done
|
||||
}
|
||||
bl_zram_usage() {
|
||||
local _p _k _v _u _rss=0 _swap=0
|
||||
for _p in "${_bl_pids[@]}"; do
|
||||
for _p in "$@"; do
|
||||
while read -r _k _v _u; do
|
||||
case $_k in VmRSS:) _rss=$((_rss + _v)) ;; VmSwap:) _swap=$((_swap + _v)) ;; esac
|
||||
done 2>/dev/null < "/proc/$_p/status"
|
||||
done
|
||||
echo "${#_bl_pids[@]} processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
_bl_rss=$_rss
|
||||
echo "$# processes, resident $((_rss / 1024)) MB, in zram $((_swap / 1024)) MB"
|
||||
}
|
||||
# Only processes that loaded libblsession are the session's own and answer SIGURG.
|
||||
bl_session_others() {
|
||||
local _p
|
||||
_bl_session=()
|
||||
for _p in "${_bl_others[@]}"; do
|
||||
grep -q -m1 '/libblsession\.so$' "/proc/$_p/maps" 2>/dev/null && _bl_session+=("$_p")
|
||||
done
|
||||
}
|
||||
bl_zram_pick() {
|
||||
if [ "$1" = session ]; then
|
||||
bl_session_others
|
||||
_pids=("${_bl_session[@]}")
|
||||
else
|
||||
_pids=("${_bl_pids[@]}")
|
||||
fi
|
||||
}
|
||||
# Same protocol as SessionSuspendController: an empty ack when the page-out starts, a byte when it is done.
|
||||
# A process whose SIGURG handler was replaced never acks, so it is not waited for after the first 2 s.
|
||||
bl_zram_wait() {
|
||||
local _p _left _start=$SECONDS
|
||||
while [ $((SECONDS - _start)) -lt 12 ]; do
|
||||
_left=0
|
||||
for _p in "$@"; do
|
||||
[ -s "/tmp/.bl-zram.ack.$_p" ] && continue
|
||||
[ -d "/proc/$_p" ] || continue
|
||||
[ $((SECONDS - _start)) -ge 2 ] && [ ! -e "/tmp/.bl-zram.ack.$_p" ] && continue
|
||||
_left=1
|
||||
done
|
||||
[ "$_left" = 1 ] || break
|
||||
nap 0.2
|
||||
done
|
||||
for _p in "$@"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
}
|
||||
bl_zram_send() {
|
||||
step "zRAM: $2 ($(bl_zram_usage))"
|
||||
printf '%s' "$1" > /tmp/.bl-zram
|
||||
[ "${#_bl_pids[@]}" = 0 ] || kill -URG "${_bl_pids[@]}" 2>/dev/null
|
||||
nap 5
|
||||
local _mode=$1 _what=$2 _which=$3 _pids _p
|
||||
bl_zram_pick "$_which"
|
||||
step "zRAM: $_what ($(bl_zram_usage "${_pids[@]}"))"
|
||||
for _p in "${_pids[@]}"; do rm -f "/tmp/.bl-zram.ack.$_p"; done
|
||||
printf '%s' "$_mode" > /tmp/.bl-zram
|
||||
[ "${#_pids[@]}" = 0 ] || kill -URG "${_pids[@]}" 2>/dev/null
|
||||
if [ "$_mode" = 1 ]; then bl_zram_wait "${_pids[@]}"; else nap 5; fi
|
||||
bl_zram_scan
|
||||
step "zRAM: done ($(bl_zram_usage))"
|
||||
bl_zram_pick "$_which"
|
||||
step "zRAM: done ($(bl_zram_usage "${_pids[@]}"))"
|
||||
}
|
||||
_bl_since=-1 _bl_packed=-1
|
||||
bl_over_cap() {
|
||||
[ "$_bl_ram_cap" -gt 0 ] || return 1
|
||||
_bl_measured=$SECONDS
|
||||
bl_session_others
|
||||
bl_zram_usage "${_bl_pids[@]}" "${_bl_session[@]}" > /dev/null
|
||||
[ "$_bl_rss" -gt "$_bl_ram_cap" ]
|
||||
}
|
||||
bl_cap_due() {
|
||||
[ "$_bl_ram_cap" -gt 0 ] && { [ "$_bl_measured" -lt 0 ] || [ $((SECONDS - _bl_measured)) -ge 30 ]; }
|
||||
}
|
||||
_bl_since=-1 _bl_packed=-1 _bl_measured=-1 _bl_unpack=0 _bl_capped=-1 _bl_backoff=30
|
||||
while kill -0 $$ 2>/dev/null; do
|
||||
bl_zram_scan
|
||||
if bl_cap_due; then
|
||||
if bl_over_cap; then
|
||||
# A cap below the game's working set cannot be met; paging out again every 30 s only churns.
|
||||
if [ "$_bl_capped" -lt 0 ] || [ $((SECONDS - _bl_capped)) -ge "$_bl_backoff" ]; then
|
||||
bl_zram_usage "${_bl_pids[@]}" > /dev/null
|
||||
if [ "$_bl_rss" -ge $((512 * 1024)) ]; then
|
||||
bl_zram_send 1 "over the ${BL_RAM_CAP_MB} MB RAM cap, compressing the client" client
|
||||
[ "$_bl_game" = 1 ] && _bl_packed=$SECONDS
|
||||
else
|
||||
step "RAM cap: over, client already small ($((_bl_rss / 1024)) MB resident), skipping it"
|
||||
fi
|
||||
bl_over_cap && bl_zram_send 1 "still over the RAM cap, compressing the rest of the session" session
|
||||
if bl_over_cap; then
|
||||
_bl_backoff=$((_bl_backoff * 2 > 600 ? 600 : _bl_backoff * 2))
|
||||
step "RAM cap: still over after paging out, next try in ${_bl_backoff} s"
|
||||
else
|
||||
_bl_backoff=30
|
||||
fi
|
||||
_bl_capped=$SECONDS
|
||||
fi
|
||||
else
|
||||
_bl_backoff=30
|
||||
if [ "$_bl_unpack" = 1 ] && [ "$_bl_game" = 0 ]; then
|
||||
bl_zram_send 0 "back under the RAM cap, reading the client back" client
|
||||
_bl_unpack=0
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ "$_bl_game" = 1 ]; then
|
||||
[ "$_bl_since" -ge 0 ] || _bl_since=$SECONDS
|
||||
if [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] &&
|
||||
if [ "${BL_ZRAM_CLIENT:-1}" = 1 ] && [ $((SECONDS - _bl_since)) -ge 20 ] && [ "${#_bl_pids[@]}" -gt 0 ] &&
|
||||
{ [ "$_bl_packed" -lt 0 ] || [ $((SECONDS - _bl_packed)) -ge 300 ]; }; then
|
||||
bl_zram_send 1 "compressing the client"
|
||||
bl_zram_send 1 "compressing the client" client
|
||||
_bl_packed=$SECONDS
|
||||
fi
|
||||
elif [ "$_bl_since" -ge 0 ]; then
|
||||
[ "$_bl_packed" -lt 0 ] || bl_zram_send 0 "game closed, reading the client back"
|
||||
if [ "$_bl_packed" -ge 0 ]; then
|
||||
if bl_over_cap; then _bl_unpack=1; else bl_zram_send 0 "game closed, reading the client back" client; _bl_unpack=0; fi
|
||||
fi
|
||||
_bl_since=-1 _bl_packed=-1
|
||||
fi
|
||||
nap 5
|
||||
@@ -526,6 +623,11 @@ case $mode in
|
||||
fi
|
||||
droiddeck-seed-redists "$steam_root" || true
|
||||
fi
|
||||
if [ -n "${BL_SHADER_PRECACHE:-}" ]; then
|
||||
droiddeck-steam-shaders "$BL_SHADER_PRECACHE" "$XDG_DATA_HOME/Steam" \
|
||||
"${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam" &&
|
||||
echo "$BL_SHADER_PRECACHE" > "$HOME/.bl-shader-precache-applied" || true
|
||||
fi
|
||||
if [ "$steam_x64" = 0 ] && [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
|
||||
step "asking the client to fetch the ARM64 Proton"
|
||||
set -- "$@" steam://install/4427310
|
||||
@@ -746,10 +848,13 @@ BUSCONF
|
||||
fi
|
||||
|
||||
# The UI bridge launches SteamVR, which needs the guest agent's library environment.
|
||||
_bl_compat_env=(env -u LD_LIBRARY_PATH -u STEAM_RUNTIME)
|
||||
_bl_compat_env=(env -u LD_LIBRARY_PATH -u STEAM_RUNTIME -u STEAM_STEAMRT_RECURSION_GUARD)
|
||||
[ "${LD_LIBRARY_PATH+x}" ] && _bl_compat_env+=("LD_LIBRARY_PATH=$LD_LIBRARY_PATH")
|
||||
[ "${STEAM_RUNTIME+x}" ] && _bl_compat_env+=("STEAM_RUNTIME=$STEAM_RUNTIME")
|
||||
[ "${STEAM_STEAMRT_RECURSION_GUARD+x}" ] && _bl_compat_env+=("STEAM_STEAMRT_RECURSION_GUARD=$STEAM_STEAMRT_RECURSION_GUARD")
|
||||
export STEAM_RUNTIME=1
|
||||
# A containerized client re-executes itself through pressure-vessel-wrap (bwrap) unless told it is already inside.
|
||||
export STEAM_STEAMRT_RECURSION_GUARD=1
|
||||
export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
||||
export SDL_VIDEO_X11_DGAMOUSE=0
|
||||
decky_loader=$HOME/homebrew/services/PluginLoader
|
||||
@@ -799,7 +904,11 @@ BUSCONF
|
||||
echo "== steam: devtools port $BL_CDP_PORT, guest processes only"
|
||||
fi
|
||||
[ -n "${BL_LAUNCH_DIR:-}" ] && mkdir -p "$BL_LAUNCH_DIR/agent" && echo "$BL_CDP_PORT" > "$BL_LAUNCH_DIR/agent/cdp-port"
|
||||
[ "$steam_x64" = 1 ] || "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 &
|
||||
if [ "$steam_x64" = 1 ]; then
|
||||
{ droiddeck-steam-compat --files-only "$steam_root" 2>&1 & }
|
||||
else
|
||||
{ "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 & }
|
||||
fi
|
||||
_bl_ui=(-gamepadui)
|
||||
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
|
||||
_bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle=vulkan)
|
||||
@@ -829,6 +938,9 @@ BUSCONF
|
||||
unset _stale _f
|
||||
fi
|
||||
steam_channel=steamdeck_publicbeta
|
||||
if [ "$steam_x64" = 0 ]; then
|
||||
steam_channel=$(droiddeck-steam-install --channel 2>/dev/null || echo steamdeck_publicbeta)
|
||||
fi
|
||||
_bl_lang=()
|
||||
[ -n "${BL_STEAM_LANGUAGE:-}" ] && _bl_lang=(-language "$BL_STEAM_LANGUAGE")
|
||||
steam_beta=$steam_root/package/beta
|
||||
|
||||
@@ -196,6 +196,51 @@ TOUR_JS = r"""
|
||||
return "off";
|
||||
})()
|
||||
"""
|
||||
FILE_BINDING = "droiddeckOpenFileDialog"
|
||||
FILE_JS = r"""
|
||||
(() => {
|
||||
const cancelled = () => ({ result: 2, message: "" });
|
||||
if (window.__droiddeckFiles) {
|
||||
window.__droiddeckFiles.cancelAll();
|
||||
return "present";
|
||||
}
|
||||
const self = { next: 0, pending: new Map() };
|
||||
const open = function (options) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (typeof window.__BINDING__ !== "function") { reject(cancelled()); return; }
|
||||
const id = ++self.next;
|
||||
self.pending.set(id, { resolve, reject });
|
||||
try { window.__BINDING__(JSON.stringify({ id, options: options || {} })); }
|
||||
catch (e) { self.pending.delete(id); reject(cancelled()); }
|
||||
});
|
||||
};
|
||||
self.done = (id, path) => {
|
||||
const item = self.pending.get(id);
|
||||
if (!item) return false;
|
||||
self.pending.delete(id);
|
||||
if (typeof path === "string" && path) item.resolve(path); else item.reject(cancelled());
|
||||
return true;
|
||||
};
|
||||
self.cancelAll = () => {
|
||||
const items = Array.from(self.pending.values());
|
||||
self.pending.clear();
|
||||
for (const item of items) item.reject(cancelled());
|
||||
};
|
||||
const patch = (w) => {
|
||||
const system = w?.SteamClient?.System;
|
||||
if (system && system.OpenFileDialog !== open) system.OpenFileDialog = open;
|
||||
};
|
||||
patch(window);
|
||||
if (SteamClient.System.OpenFileDialog !== open) throw new Error("Steam OpenFileDialog could not be redirected");
|
||||
const popups = window.g_PopupManager;
|
||||
if (popups) {
|
||||
for (const popup of popups.GetPopups?.() || []) patch(popup.window);
|
||||
popups.AddPopupCreatedCallback?.((popup) => patch(popup.window));
|
||||
}
|
||||
window.__droiddeckFiles = self;
|
||||
return "installed";
|
||||
})()
|
||||
""".replace("__BINDING__", FILE_BINDING)
|
||||
VR_BINDING = "droiddeckLaunchSteamVr"
|
||||
VR_HELPER = "/usr/local/bin/droiddeck-steamvr"
|
||||
VR_JS = r"""
|
||||
@@ -274,6 +319,62 @@ def launch_steamvr():
|
||||
say("SteamVR library launch failed: %s" % e)
|
||||
|
||||
|
||||
def choose_file(options):
|
||||
import gi
|
||||
gi.require_version("Gdk", "3.0")
|
||||
gi.require_version("Gtk", "3.0")
|
||||
from gi.repository import Gdk, Gtk
|
||||
directory = bool(options.get("bChooseDirectory"))
|
||||
save = bool(options.get("bSaveMode")) and not directory
|
||||
action = (Gtk.FileChooserAction.SELECT_FOLDER if directory else
|
||||
Gtk.FileChooserAction.SAVE if save else Gtk.FileChooserAction.OPEN)
|
||||
dialog = Gtk.FileChooserDialog(title=str(options.get("strTitle") or ""), action=action)
|
||||
dialog.add_buttons("gtk-cancel", Gtk.ResponseType.CANCEL,
|
||||
"gtk-save" if save else "gtk-open", Gtk.ResponseType.ACCEPT)
|
||||
dialog.set_default_response(Gtk.ResponseType.ACCEPT)
|
||||
dialog.set_local_only(True)
|
||||
dialog.set_do_overwrite_confirmation(True)
|
||||
for folder in ("/root/Storage", "/mnt/droiddeck-sd"):
|
||||
if os.path.isdir(folder):
|
||||
try:
|
||||
dialog.add_shortcut_folder(folder)
|
||||
except Exception:
|
||||
pass
|
||||
if not directory:
|
||||
for entry in options.get("rgFilters") or []:
|
||||
patterns = [str(p) for p in entry.get("rFilePatterns") or [] if p]
|
||||
if not patterns:
|
||||
continue
|
||||
chosen = Gtk.FileFilter()
|
||||
chosen.set_name(str(entry.get("strFileTypeName") or ", ".join(patterns)))
|
||||
for pattern in patterns:
|
||||
pattern = "*" if pattern == "*.*" else pattern
|
||||
chosen.add_pattern(pattern)
|
||||
if pattern.lower() != pattern.upper():
|
||||
chosen.add_pattern(pattern.upper())
|
||||
dialog.add_filter(chosen)
|
||||
if entry.get("bUseAsDefault"):
|
||||
dialog.set_filter(chosen)
|
||||
initial = str(options.get("strInitialFile") or "").strip('"')
|
||||
if initial:
|
||||
if os.path.isdir(initial):
|
||||
dialog.set_current_folder(initial)
|
||||
elif save:
|
||||
if os.path.isdir(os.path.dirname(initial)):
|
||||
dialog.set_current_folder(os.path.dirname(initial))
|
||||
dialog.set_current_name(os.path.basename(initial))
|
||||
elif os.path.exists(initial):
|
||||
dialog.set_filename(initial)
|
||||
elif os.path.isdir(os.path.dirname(initial)):
|
||||
dialog.set_current_folder(os.path.dirname(initial))
|
||||
screen = Gdk.Screen.get_default()
|
||||
if screen is not None:
|
||||
dialog.set_default_size(screen.get_width(), screen.get_height())
|
||||
chosen_path = dialog.get_filename() if dialog.run() == Gtk.ResponseType.ACCEPT else None
|
||||
dialog.destroy()
|
||||
return chosen_path
|
||||
|
||||
|
||||
class Closed(Exception):
|
||||
pass
|
||||
|
||||
@@ -519,10 +620,11 @@ class Watcher:
|
||||
|
||||
|
||||
class Helper:
|
||||
def __init__(self, steam_root, port, steamos=False):
|
||||
def __init__(self, steam_root, port, steamos=False, files_only=False):
|
||||
self.steam_root = steam_root
|
||||
self.port = port
|
||||
self.steamos = steamos
|
||||
self.files_only = files_only
|
||||
self.page = None
|
||||
self.known = set()
|
||||
self.installed = None
|
||||
@@ -530,6 +632,70 @@ class Helper:
|
||||
self.tools_asked = {}
|
||||
self.tools_checked = None
|
||||
self.vr_launch = None
|
||||
self.chooser = None
|
||||
|
||||
def open_chooser(self, payload):
|
||||
try:
|
||||
request = json.loads(payload)
|
||||
ident = int(request["id"])
|
||||
options = request.get("options", {})
|
||||
if not isinstance(options, dict):
|
||||
raise ValueError("options are not an object")
|
||||
except (ValueError, KeyError, TypeError) as e:
|
||||
say("ignored a file dialog request (%s)" % e)
|
||||
return
|
||||
if self.chooser is not None:
|
||||
self.finish_chooser(ident, None)
|
||||
return
|
||||
command = [sys.executable, os.path.realpath(__file__), "--choose-file"]
|
||||
# Gamescope shows the dialog over the client by the AppId on a reaper above it; the x86-64 client has no
|
||||
# native reaper, so the arm64 client's is borrowed when it is installed.
|
||||
data = os.environ.get("XDG_DATA_HOME") or os.path.join(os.path.expanduser("~"), ".local", "share")
|
||||
for root in (self.steam_root, os.path.join(data, "Steam")):
|
||||
reaper = os.path.join(root, "steamrtarm64", "reaper")
|
||||
if os.access(reaper, os.X_OK):
|
||||
command = [reaper, "SteamLaunch", "AppId=769", "--"] + command
|
||||
break
|
||||
try:
|
||||
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||
stderr=subprocess.DEVNULL, start_new_session=True)
|
||||
proc.stdin.write(json.dumps(options).encode("utf-8"))
|
||||
proc.stdin.close()
|
||||
except OSError as e:
|
||||
say("could not open a file dialog (%s)" % e)
|
||||
self.finish_chooser(ident, None)
|
||||
return
|
||||
say("file dialog open: %s" % (options.get("strTitle") or "untitled"))
|
||||
self.chooser = (ident, proc)
|
||||
|
||||
def chooser_done(self):
|
||||
ident, proc = self.chooser
|
||||
self.chooser = None
|
||||
out = proc.stdout.read().decode("utf-8", "replace")
|
||||
proc.stdout.close()
|
||||
proc.wait()
|
||||
if proc.returncode == 2:
|
||||
say("file dialog needs GTK 3 and PyGObject, which come with the desktop")
|
||||
try:
|
||||
path = json.loads(out) if proc.returncode == 0 else None
|
||||
except ValueError:
|
||||
path = None
|
||||
self.finish_chooser(ident, path if isinstance(path, str) and path else None)
|
||||
|
||||
def finish_chooser(self, ident, path):
|
||||
say("file dialog %s" % ("chose " + path if path else "cancelled"))
|
||||
self.page.evaluate("window.__droiddeckFiles?.done(%d, %s)" % (ident, json.dumps(path)))
|
||||
|
||||
def close_chooser(self):
|
||||
if self.chooser is not None:
|
||||
_, proc = self.chooser
|
||||
self.chooser = None
|
||||
try:
|
||||
os.killpg(proc.pid, signal.SIGTERM)
|
||||
except OSError:
|
||||
pass
|
||||
proc.stdout.close()
|
||||
proc.wait()
|
||||
|
||||
def attach(self):
|
||||
path = shared_context(self.port)
|
||||
@@ -539,9 +705,16 @@ class Helper:
|
||||
try:
|
||||
if page.evaluate("typeof SteamClient === 'object' && typeof SteamClient.WebUITransport === 'object'") is not True:
|
||||
raise LookupError("SteamClient is not ready")
|
||||
if self.files_only:
|
||||
page.call("Runtime.addBinding", {"name": FILE_BINDING})
|
||||
page.evaluate(FILE_JS)
|
||||
self.page = page
|
||||
return True
|
||||
page.call("Runtime.addBinding", {"name": BINDING})
|
||||
page.call("Runtime.addBinding", {"name": VR_BINDING})
|
||||
page.evaluate(VR_JS)
|
||||
page.call("Runtime.addBinding", {"name": FILE_BINDING})
|
||||
page.evaluate(FILE_JS)
|
||||
try:
|
||||
page.evaluate(TOUR_JS)
|
||||
except RuntimeError:
|
||||
@@ -583,9 +756,8 @@ class Helper:
|
||||
picked = COMPAT["picked_apps"](state)
|
||||
runnable = {t["name"].lower() for t in live}
|
||||
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices, key=COMPAT["app_order"])
|
||||
overrides = COMPAT["requested_games"](
|
||||
COMPAT["game_requests"](), catalog, [t["name"] for t in live])
|
||||
apps = sorted(set(apps) | set(overrides), key=COMPAT["app_order"])
|
||||
asked = [app for app, request in COMPAT["game_requests"]().items() if COMPAT["valid_game_request"](app, request)]
|
||||
apps = sorted(set(apps) | set(asked), key=COMPAT["app_order"])
|
||||
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
|
||||
refused = set(apps) - set(current)
|
||||
refused_native = native_choices & refused
|
||||
@@ -597,7 +769,6 @@ class Helper:
|
||||
if isinstance(state.get("auto"), dict):
|
||||
state["auto"] = prior_auto
|
||||
native_choices -= refused
|
||||
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
|
||||
current["0"] = top["selected"]
|
||||
native = COMPAT["native_targets"](self.steam_root, apps)
|
||||
raw_mapping = COMPAT["read_config_mapping"](
|
||||
@@ -619,6 +790,9 @@ class Helper:
|
||||
current[app] = ""
|
||||
elif not current.get(app):
|
||||
current.pop(app, None)
|
||||
requests = COMPAT["settled_game_requests"](state, current, catalog)
|
||||
overrides = COMPAT["requested_games"](requests or {}, catalog, [t["name"] for t in live])
|
||||
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
|
||||
changes, auto = COMPAT["plan_mapping"](
|
||||
current, installed, [t["name"] for t in live], default,
|
||||
COMPAT["followers"](state, current), native, picks, overrides,
|
||||
@@ -630,7 +804,8 @@ class Helper:
|
||||
state.update(
|
||||
auto={app: tool for app, tool in auto.items() if tool is not COMPAT["NATIVE_CHOICE"]},
|
||||
native_choices=sorted(refused_native | {app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]}),
|
||||
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True)
|
||||
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True,
|
||||
games_applied=COMPAT["applied_game_requests"](requests, overrides, state))
|
||||
state.pop("native", None)
|
||||
if waiting:
|
||||
state["pending"] = wanted
|
||||
@@ -678,9 +853,27 @@ class Helper:
|
||||
if vr_games and (self.vr_launch is None or self.vr_launch.poll() is not None):
|
||||
say("preparing SteamVR for library app(s): " + ", ".join(sorted(vr_games)))
|
||||
self.vr_launch = launch_steamvr()
|
||||
for e in events:
|
||||
if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str):
|
||||
self.open_chooser(e["params"]["payload"])
|
||||
return events
|
||||
|
||||
def serve_files(self):
|
||||
say("attached to the client on port %d for its file dialogs" % self.port)
|
||||
while True:
|
||||
sources = [self.page.ws] + ([self.chooser[1].stdout] if self.chooser is not None else [])
|
||||
queued = self.page.ws.pending() or bool(self.page.events)
|
||||
ready = [self.page.ws] if queued else select.select(sources, [], [], 30)[0]
|
||||
if self.chooser is not None and self.chooser[1].stdout in ready:
|
||||
self.chooser_done()
|
||||
if self.page.ws in ready or self.page.events:
|
||||
for e in self.page.drain():
|
||||
if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str):
|
||||
self.open_chooser(e["params"]["payload"])
|
||||
|
||||
def serve(self, watcher):
|
||||
if self.files_only:
|
||||
return self.serve_files()
|
||||
with open(COMPAT["state_path"]("live.pid"), "w") as f:
|
||||
f.write("%d\n" % os.getpid())
|
||||
say("attached to the client on port %d" % self.port)
|
||||
@@ -688,7 +881,11 @@ class Helper:
|
||||
self.ensure_tools()
|
||||
while True:
|
||||
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
|
||||
if self.chooser is not None:
|
||||
sources.append(self.chooser[1].stdout)
|
||||
ready = [self.page.ws] if self.page.ws.pending() else select.select(sources, [], [], 30 if watcher.fileno() >= 0 else 2)[0]
|
||||
if self.chooser is not None and self.chooser[1].stdout in ready:
|
||||
self.chooser_done()
|
||||
due = False
|
||||
if self.page.ws in ready:
|
||||
due = any(called(e, BINDING) for e in self.drain())
|
||||
@@ -716,13 +913,45 @@ def detach():
|
||||
COMPAT["write_json"](state_file, state)
|
||||
|
||||
|
||||
def chooser_main():
|
||||
try:
|
||||
options = json.load(sys.stdin)
|
||||
except ValueError:
|
||||
return 1
|
||||
try:
|
||||
path = choose_file(options if isinstance(options, dict) else {})
|
||||
except (ImportError, ValueError):
|
||||
return 2
|
||||
if not path:
|
||||
return 1
|
||||
print(json.dumps(path))
|
||||
return 0
|
||||
|
||||
|
||||
def main():
|
||||
steam_root = sys.argv[1]
|
||||
files_only = sys.argv[1:2] == ["--files-only"]
|
||||
steam_root = sys.argv[2 if files_only else 1]
|
||||
try:
|
||||
port = int(os.environ.get("BL_CDP_PORT", ""))
|
||||
except ValueError:
|
||||
say("no devtools port for this session; the client's mapping is kept through config.vdf")
|
||||
return 0
|
||||
if files_only:
|
||||
helper = Helper(steam_root, port, files_only=True)
|
||||
failures = 0
|
||||
while True:
|
||||
try:
|
||||
helper.attach()
|
||||
failures = 0
|
||||
helper.serve(None)
|
||||
except Exception as e:
|
||||
helper.close_chooser()
|
||||
if helper.page is not None:
|
||||
say("lost the client (%s); reattaching" % e)
|
||||
helper.page.ws.close()
|
||||
helper.page = None
|
||||
failures += 1
|
||||
time.sleep(min(2 * max(failures, 1), 10))
|
||||
os.makedirs(COMPAT["COMPAT_DIR"], exist_ok=True)
|
||||
watcher = Watcher([COMPAT["state_path"]("request.json"), COMPAT["state_path"]("games.json")] +
|
||||
[os.path.join(lib, "steamapps", "libraryfolders.vdf") for lib in (steam_root, COMPAT["LIBRARY"] + "-sd")])
|
||||
@@ -737,6 +966,7 @@ def main():
|
||||
last = None
|
||||
helper.serve(watcher)
|
||||
except Exception as e:
|
||||
helper.close_chooser()
|
||||
if helper.page is not None:
|
||||
say("lost the client (%s); reattaching" % e)
|
||||
helper.page.ws.close()
|
||||
@@ -750,8 +980,11 @@ def main():
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if sys.argv[1:2] == ["--choose-file"]:
|
||||
sys.exit(chooser_main())
|
||||
signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))
|
||||
try:
|
||||
sys.exit(main())
|
||||
finally:
|
||||
detach()
|
||||
if sys.argv[1:2] != ["--files-only"]:
|
||||
detach()
|
||||
@@ -1,25 +1,57 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
cdn_list="https://client-update.steamstatic.com https://client-update.akamai.steamstatic.com https://client-update.fastly.steamstatic.com"
|
||||
steam_channel=steamdeck_publicbeta
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
beta_channel=steamdeck_publicbeta
|
||||
stable_channel=steamdeck_stable
|
||||
steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
|
||||
channel_state=$steam_root/package/droiddeck-channel
|
||||
pinned=1
|
||||
wanted=${BL_STEAM_CHANNEL:-$(cat "$HOME/.config/droiddeck/steam-channel" 2>/dev/null || true)}
|
||||
case $wanted in
|
||||
stable|"$stable_channel") steam_channel=$stable_channel ;;
|
||||
beta|"$beta_channel") steam_channel=$beta_channel ;;
|
||||
*)
|
||||
pinned=
|
||||
steam_channel=$beta_channel
|
||||
[ "$(cat "$channel_state" 2>/dev/null)" = "$stable_channel" ] && steam_channel=$stable_channel
|
||||
;;
|
||||
esac
|
||||
if [ "${1:-}" = --channel ]; then
|
||||
echo "$steam_channel"
|
||||
exit 0
|
||||
fi
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
stamp=$steam_root/package/droiddeck-installed
|
||||
legacy_stamp=$steam_root/package/bannerlator-installed
|
||||
unconfirmed=$steam_root/package/droiddeck-unconfirmed
|
||||
repair_request=$HOME/.bl-steam-repair
|
||||
parts=$steam_root/package/droiddeck-download
|
||||
if [ -f "$legacy_stamp" ] && [ ! -f "$stamp" ]; then
|
||||
mv -f "$legacy_stamp" "$stamp" || true
|
||||
fi
|
||||
repair=""
|
||||
fallback=""
|
||||
starts=0
|
||||
[ -f "$unconfirmed" ] && starts=$(grep -cx start "$unconfirmed" || true)
|
||||
if [ -e "$repair_request" ]; then
|
||||
repair="requested"
|
||||
elif [ -f "$unconfirmed" ] && ! grep -qx repaired "$unconfirmed" \
|
||||
&& [ "$(grep -cx start "$unconfirmed")" -ge 2 ]; then
|
||||
repair="the client was started $(grep -cx start "$unconfirmed") times without showing anything"
|
||||
elif [ "$starts" -ge 2 ] && ! grep -qx repaired "$unconfirmed"; then
|
||||
repair="the client was started $starts times without showing anything"
|
||||
elif [ "$starts" -ge 2 ] && [ -z "$pinned" ] && [ "$steam_channel" = "$beta_channel" ] && [ "${1:-}" != --sync ]; then
|
||||
repair="the repaired $beta_channel client was started $starts more times without showing anything"
|
||||
fallback=1
|
||||
fi
|
||||
if [ -n "$fallback" ]; then
|
||||
echo "== STEP $(date -u +%H:%M:%S) falling back to Valve's $stable_channel Steam client: $repair"
|
||||
steam_channel=$stable_channel
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
fi
|
||||
if [ -n "$repair" ]; then
|
||||
echo "== STEP $(date -u +%H:%M:%S) repairing the Steam client ($repair)"
|
||||
if [ ! -f "$parts/.repair" ]; then
|
||||
rm -rf "$parts"
|
||||
mkdir -p "$parts" && : > "$parts/.repair"
|
||||
fi
|
||||
rm -f "$stamp" "$legacy_stamp" "$steam_root/.crash" "$steam_root/steam.pid" \
|
||||
"$steam_root"/package/steam_client_*.manifest "$steam_root"/package/steam_client_*.installed
|
||||
for part in "$steam_root"/package/*.zip.*; do
|
||||
@@ -42,20 +74,99 @@ fi
|
||||
|
||||
work=$(mktemp -d)
|
||||
trap 'rm -rf "$work"' EXIT
|
||||
cdn=""
|
||||
for candidate in $cdn_list; do
|
||||
if curl -fsSL --connect-timeout 10 --max-time 30 --retry 2 --retry-connrefused --retry-delay 3 \
|
||||
"$candidate/$manifest" -o "$work/manifest"; then
|
||||
cdn=$candidate
|
||||
break
|
||||
|
||||
nap() {
|
||||
[ -n "${nap_fd:-}" ] || exec {nap_fd}<> <(:)
|
||||
read -r -t "$1" -u "$nap_fd" _ 2>/dev/null || :
|
||||
}
|
||||
size_of() {
|
||||
local n=0
|
||||
[ -f "$1" ] && n=$(wc -c < "$1")
|
||||
echo $((n))
|
||||
}
|
||||
limits=(--connect-timeout 30 --speed-limit 4096 --speed-time 60)
|
||||
read -r -a delays <<< "${BL_STEAM_RETRY_DELAYS:-5 10 20 30 30}"
|
||||
|
||||
step() { echo "== STEP $(date -u +%H:%M:%S) $*"; }
|
||||
progress() {
|
||||
local mb=$(( (done_bytes + $(size_of "$1")) / 1000000 ))
|
||||
[ -z "${3:-}" ] && [ "$mb" = "${shown_mb:-}" ] && [ "$2" = "${shown_part:-}" ] && return 0
|
||||
shown_mb=$mb shown_part=$2
|
||||
step "downloading Steam: $2 ($i/$total), $mb of $((total_bytes / 1000000)) MB${3:+ - $3}"
|
||||
}
|
||||
|
||||
fetch() {
|
||||
local url=$1 dest=$2 size=$3 sum=$4 part=$5 failures=0 bad=0 finished=0 before rc fd wait
|
||||
while :; do
|
||||
if [ -f "$dest" ] && { [ "$finished" = 1 ] || { [ "$size" -gt 0 ] && [ "$(size_of "$dest")" -ge "$size" ]; }; }; then
|
||||
echo "$sum $dest" | sha256sum -c --quiet 2>/dev/null && return 0
|
||||
rm -f "$dest"
|
||||
finished=0 bad=$((bad + 1))
|
||||
[ "$bad" -lt 3 ] || { echo "droiddeck-steam-install: $part does not match its checksum" >&2; return 1; }
|
||||
fi
|
||||
before=$(size_of "$dest")
|
||||
exec {fd}< <(code=$(curl -fsSL "${limits[@]}" -w '%{http_code}' -C - -o "$dest" "$url") && echo "0 $code" || echo "$? $code")
|
||||
until read -r -t 5 -u "$fd" rc http; do
|
||||
if [ $? -le 128 ]; then rc=1; break; fi
|
||||
progress "$dest" "$part"
|
||||
done
|
||||
exec {fd}<&-
|
||||
if [ "$rc" = 0 ]; then finished=1; continue; fi
|
||||
case "$rc:${http:-}" in
|
||||
22:416 | 33:*) rm -f "$dest" ;;
|
||||
22:4??)
|
||||
echo "droiddeck-steam-install: $part: HTTP $http from ${url%/*}" >&2
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
if [ "$(size_of "$dest")" -gt "$before" ]; then failures=0; else failures=$((failures + 1)); fi
|
||||
if [ "$failures" -gt "${#delays[@]}" ]; then
|
||||
echo "droiddeck-steam-install: could not download $part (curl exit $rc); what arrived is kept for the next try" >&2
|
||||
return 1
|
||||
fi
|
||||
wait=${delays[$((failures > 0 ? failures - 1 : 0))]}
|
||||
progress "$dest" "$part" "interrupted (curl exit $rc), trying again in ${wait} s"
|
||||
nap "$wait"
|
||||
done
|
||||
}
|
||||
|
||||
fetch_manifest() {
|
||||
cdn=""
|
||||
for candidate in $cdn_list; do
|
||||
if curl -fsSL --connect-timeout 10 --max-time 30 --retry 2 --retry-connrefused --retry-delay 3 \
|
||||
"$candidate/$manifest" -o "$work/manifest"; then
|
||||
cdn=$candidate
|
||||
break
|
||||
fi
|
||||
done
|
||||
[ -n "$cdn" ] || { echo "droiddeck-steam-install: no Steam client CDN answered for $manifest" >&2; exit 1; }
|
||||
cdn_order=("$cdn")
|
||||
for candidate in $cdn_list; do
|
||||
[ "$candidate" = "$cdn" ] || cdn_order+=("$candidate")
|
||||
done
|
||||
version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest")
|
||||
awk -F'"' '
|
||||
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
|
||||
$2 == "file" { file[block] = $4 }
|
||||
$2 == "sha2" { sha[block] = $4 }
|
||||
$2 == "size" { size[block] = $4 }
|
||||
END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b], size[b] + 0 }
|
||||
' "$work/manifest" | sort > "$work/parts"
|
||||
[ -s "$work/parts" ] && return 0
|
||||
echo "droiddeck-steam-install: no client components in $manifest; its blocks are:" \
|
||||
"$(awk -F'"' '/^\t"/ && NF >= 3 && $4 == "" { printf "%s ", $2 }' "$work/manifest")" >&2
|
||||
return 1
|
||||
}
|
||||
if ! fetch_manifest; then
|
||||
if [ -n "$sync" ] || [ -n "$pinned" ] || [ "$steam_channel" = "$stable_channel" ]; then
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
[ -n "$cdn" ] || { echo "droiddeck-steam-install: no Steam client CDN answered for $manifest" >&2; exit 1; }
|
||||
cdn_order=("$cdn")
|
||||
for candidate in $cdn_list; do
|
||||
[ "$candidate" = "$cdn" ] || cdn_order+=("$candidate")
|
||||
done
|
||||
version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest")
|
||||
echo "== STEP $(date -u +%H:%M:%S) falling back to Valve's $stable_channel Steam client: $manifest has no arm64 client"
|
||||
steam_channel=$stable_channel
|
||||
manifest=steam_client_${steam_channel}_linuxarm64
|
||||
fallback=1
|
||||
fetch_manifest || exit 1
|
||||
fi
|
||||
if [ -n "$sync" ]; then
|
||||
installed=$(awk -F'"' '$2 == "version" { print $4; exit }' "$steam_root/package/$manifest.manifest" 2>/dev/null || true)
|
||||
if [ -x "$steam_root/steamrtarm64/steam" ] && [ "$installed" = "$version" ]; then
|
||||
@@ -64,31 +175,36 @@ if [ -n "$sync" ]; then
|
||||
fi
|
||||
echo "== STEP $(date -u +%H:%M:%S) updating the arm64 Steam client to $version (was ${installed:-none}) for the x86-64 client"
|
||||
fi
|
||||
awk -F'"' '
|
||||
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
|
||||
$2 == "file" { file[block] = $4 }
|
||||
$2 == "sha2" { sha[block] = $4 }
|
||||
END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b] }
|
||||
' "$work/manifest" | sort > "$work/parts"
|
||||
[ -s "$work/parts" ] || { echo "droiddeck-steam-install: no client components in $manifest" >&2; exit 1; }
|
||||
total=$(grep -c . "$work/parts" 2>/dev/null || echo 0)
|
||||
total_bytes=$(awk '{ n += $4 } END { print n + 0 }' "$work/parts")
|
||||
|
||||
mkdir -p "$steam_root/package"
|
||||
while read -r block file sum; do
|
||||
mkdir -p "$parts"
|
||||
for left in "$parts"/*; do
|
||||
[ -e "$left" ] || continue
|
||||
name=${left##*/}
|
||||
name=${name%.unpacked}
|
||||
grep -qF " $name " "$work/parts" || rm -rf "$left"
|
||||
done
|
||||
done_bytes=0
|
||||
while read -r block file sum size; do
|
||||
i=$((${i:-0} + 1))
|
||||
echo "== STEP $(date -u +%H:%M:%S) downloading Steam: $block ($i/$total)"
|
||||
if [ -f "$parts/$file.unpacked" ]; then
|
||||
done_bytes=$((done_bytes + size))
|
||||
continue
|
||||
fi
|
||||
progress "$parts/$file" "$block"
|
||||
fetched=""
|
||||
for host in "${cdn_order[@]}"; do
|
||||
if curl -fsSL --connect-timeout 10 --speed-limit 1024 --speed-time 60 --max-time 1800 \
|
||||
"$host/$file" -o "$work/$file" && echo "$sum $work/$file" | sha256sum -c --quiet; then
|
||||
if fetch "$host/$file" "$parts/$file" "$size" "$sum" "$block"; then
|
||||
fetched=$host
|
||||
break
|
||||
fi
|
||||
rm -f "$work/$file"
|
||||
done
|
||||
[ -n "$fetched" ] || { echo "droiddeck-steam-install: $file failed on every CDN" >&2; exit 1; }
|
||||
unzip -qo "$work/$file" -d "$steam_root"
|
||||
rm -f "$work/$file"
|
||||
unzip -qo "$parts/$file" -d "$steam_root"
|
||||
: > "$parts/$file.unpacked"
|
||||
rm -f "$parts/$file"
|
||||
done_bytes=$((done_bytes + size))
|
||||
done < "$work/parts"
|
||||
find "$steam_root" -depth -name '*\\*' | while read -r odd; do
|
||||
fixed=${odd//\\//}
|
||||
@@ -117,6 +233,11 @@ ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdkarm64"
|
||||
ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/binarm64"
|
||||
ln -sfn "$steam_root/linux32" "$HOME/.steam/sdk32"
|
||||
echo "$version" > "$stamp"
|
||||
rm -rf "$parts"
|
||||
if [ -n "$fallback" ]; then
|
||||
echo "$stable_channel" > "$channel_state"
|
||||
echo "== STEP $(date -u +%H:%M:%S) the Steam client now follows $stable_channel (beta in ~/.config/droiddeck/steam-channel returns to $beta_channel)"
|
||||
fi
|
||||
if [ -n "$repair" ]; then
|
||||
echo repaired > "$unconfirmed"
|
||||
rm -f "$repair_request"
|
||||
|
||||
@@ -12,6 +12,10 @@ case $target in
|
||||
esac
|
||||
|
||||
if [ "$ui" = desktop ] && [ "${BL_DESKTOP:-}" = 1 ]; then
|
||||
case ",${MESA_VK_WSI_DEBUG:-}," in
|
||||
*,sw,*) ;;
|
||||
*) export MESA_VK_WSI_DEBUG=${MESA_VK_WSI_DEBUG:+$MESA_VK_WSI_DEBUG,}sw ;;
|
||||
esac
|
||||
if [ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ]; then
|
||||
client_home=${BL_X64_HOME:-${HOME:-/root}/.droiddeck-x64}
|
||||
client=(/usr/local/bin/droiddeck-steam-x64 --exec)
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
#!/usr/bin/python3
|
||||
"""Sets the Steam client's shader pre-caching (Settings > Downloads), before the client starts.
|
||||
|
||||
droiddeck-steam-shaders <0|1> <steam root>...
|
||||
|
||||
The client stores the toggle as InstallConfigStore/Software/Valve/Steam/ShaderCacheManager/
|
||||
DisableShaderCache in config/config.vdf: "1" when off, "0" when on. It keeps the setting in memory
|
||||
and writes config.vdf back on exit, so this runs only while the client is stopped. The launcher
|
||||
passes a value only after its own toggle changes; otherwise the client's toggle stays the user's."""
|
||||
from pathlib import Path
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
|
||||
VDF = runpy.run_path(str(Path(__file__).with_name("droiddeck-steam-ui-scale")))
|
||||
PATH = ("Software", "Valve", "Steam", "ShaderCacheManager", "DisableShaderCache")
|
||||
|
||||
|
||||
def set_text(text, enabled):
|
||||
value = "0" if enabled else "1"
|
||||
updated, changed = VDF["seed_value"](text, PATH, value)
|
||||
if changed:
|
||||
return updated, True
|
||||
block = VDF["parse"](text).get("InstallConfigStore")
|
||||
for section in PATH[:-1]:
|
||||
block = block.get(section)
|
||||
current = block.get(PATH[-1])
|
||||
if isinstance(current, VDF["Block"]):
|
||||
raise ValueError("invalid DisableShaderCache setting")
|
||||
if current == value:
|
||||
return text, False
|
||||
at = block.offset(PATH[-1])
|
||||
end = VDF["TOKEN"].match(text, at).end()
|
||||
return text[:at] + f'"{value}"' + text[end:], True
|
||||
|
||||
|
||||
def apply(steam_root, enabled):
|
||||
config = Path(steam_root) / "config/config.vdf"
|
||||
text = config.read_text() if config.exists() else '"InstallConfigStore"\n{\n}\n'
|
||||
updated, changed = set_text(text, enabled)
|
||||
if changed:
|
||||
VDF["atomic_write"](config, updated)
|
||||
return changed
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
if len(sys.argv) < 3 or sys.argv[1] not in ("0", "1"):
|
||||
print("usage: droiddeck-steam-shaders <0|1> <steam root>...", file=sys.stderr)
|
||||
sys.exit(2)
|
||||
enabled = sys.argv[1] == "1"
|
||||
status = 0
|
||||
for root in sys.argv[2:]:
|
||||
if not Path(root).is_dir():
|
||||
continue
|
||||
try:
|
||||
if apply(root, enabled):
|
||||
print(f"== steam: shader pre-caching {'on' if enabled else 'off'} in {root}")
|
||||
except (OSError, ValueError, RecursionError) as error:
|
||||
print(f"== steam: left shader pre-caching unchanged in {root}: {error}", file=sys.stderr)
|
||||
status = 1
|
||||
sys.exit(status)
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
#!/usr/bin/python3
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import runpy
|
||||
import sys
|
||||
|
||||
NOT_GAMES = frozenset((
|
||||
"228980", "1070560", "1391110", "1628350", "1493710", "3127680",
|
||||
"4183110", "4185400", "4427310", "4628740",
|
||||
))
|
||||
TOOL_DIR = re.compile(r"(steam ?linux ?runtime.*|proton.*|steamworks shared|fex|steamvr)", re.I)
|
||||
AUTOMATIC = ("", "droiddeck-direct", "droiddeck-fex", "droiddeck-proton-arm64", "droiddeck-proton-11-arm64")
|
||||
LINUX_TOOLS = ("droiddeck-direct", "droiddeck-fex")
|
||||
STATE = ".droiddeck-shared.json"
|
||||
LABELS = {"arm64": "ARM64 client games", "x86-64": "x86-64 client games"}
|
||||
|
||||
|
||||
def say(message):
|
||||
print("droiddeck-steam-share: " + message)
|
||||
|
||||
|
||||
def read(path):
|
||||
try:
|
||||
with open(path, encoding="utf-8", errors="surrogateescape") as f:
|
||||
return f.read()
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
|
||||
def write(path, text):
|
||||
staged = path + ".droiddeck-new"
|
||||
with open(staged, "w", encoding="utf-8", errors="surrogateescape") as f:
|
||||
f.write(text)
|
||||
os.replace(staged, path)
|
||||
|
||||
|
||||
def field(text, key):
|
||||
m = re.search(r'"%s"\s+"([^"]*)"' % re.escape(key), text or "", re.I)
|
||||
return m.group(1) if m else None
|
||||
|
||||
|
||||
def number(text, key):
|
||||
value = field(text, key)
|
||||
return int(value) if value and value.isdigit() else 0
|
||||
|
||||
|
||||
def same(a, b):
|
||||
return os.path.realpath(a) == os.path.realpath(b)
|
||||
|
||||
|
||||
def libraries(root, skip):
|
||||
found = [root] + [p.replace("\\\\", "\\") for p in
|
||||
re.findall(r'"path"\s+"((?:[^"\\]|\\.)*)"', read(os.path.join(root, "steamapps", "libraryfolders.vdf")) or "")]
|
||||
return [p for p in dict.fromkeys(found) if not any(same(p, s) for s in skip)]
|
||||
|
||||
|
||||
def installs(libs):
|
||||
games = {}
|
||||
for library in libs:
|
||||
steamapps = os.path.join(library, "steamapps")
|
||||
try:
|
||||
names = sorted(os.listdir(steamapps))
|
||||
except OSError:
|
||||
continue
|
||||
for name in names:
|
||||
m = re.fullmatch(r"appmanifest_(\d+)\.acf", name)
|
||||
if not m or m.group(1) in NOT_GAMES or m.group(1) in games:
|
||||
continue
|
||||
text = read(os.path.join(steamapps, name))
|
||||
folder = field(text, "installdir")
|
||||
if (not folder or folder in (".", "..") or "/" in folder or TOOL_DIR.fullmatch(folder)
|
||||
or not number(text, "StateFlags") & 4
|
||||
or not os.path.isdir(os.path.join(steamapps, "common", folder))):
|
||||
continue
|
||||
games[m.group(1)] = (steamapps, text, folder)
|
||||
return games
|
||||
|
||||
|
||||
def link(path, target):
|
||||
if os.path.islink(path):
|
||||
if os.readlink(path) == target:
|
||||
return True
|
||||
os.unlink(path)
|
||||
elif os.path.lexists(path):
|
||||
return False
|
||||
os.symlink(target, path)
|
||||
return True
|
||||
|
||||
|
||||
def unlink(path):
|
||||
if os.path.islink(path):
|
||||
os.unlink(path)
|
||||
|
||||
|
||||
def emptied(src, folder):
|
||||
path = os.path.join(src, "common", folder)
|
||||
return not os.path.isdir(path) or not os.listdir(path)
|
||||
|
||||
|
||||
def sync(view, source, own):
|
||||
steamapps = os.path.join(view, "steamapps")
|
||||
for sub in ("common", "compatdata"):
|
||||
os.makedirs(os.path.join(steamapps, sub), exist_ok=True)
|
||||
state = {}
|
||||
try:
|
||||
state = json.loads(read(os.path.join(view, STATE)) or "{}")
|
||||
except ValueError:
|
||||
pass
|
||||
managed = {app: tuple(v) for app, v in state.get("shared", {}).items() if isinstance(v, list) and len(v) == 2}
|
||||
hidden = state.get("hidden", {})
|
||||
shared, back = {}, []
|
||||
for app, (src, folder) in managed.items():
|
||||
if app in source and app not in own:
|
||||
continue
|
||||
manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app)
|
||||
if app not in own and not os.path.isfile(manifest) and emptied(src, folder) and os.path.isfile(os.path.join(src, "appmanifest_%s.acf" % app)):
|
||||
os.unlink(os.path.join(src, "appmanifest_%s.acf" % app))
|
||||
unlink(os.path.join(steamapps, "common", folder))
|
||||
unlink(os.path.join(steamapps, "compatdata", app))
|
||||
if os.path.isfile(manifest):
|
||||
os.unlink(manifest)
|
||||
for app, (src, text, folder) in sorted(source.items(), key=lambda item: int(item[0])):
|
||||
if app in own:
|
||||
continue
|
||||
stamp = number(text, "LastUpdated")
|
||||
if hidden.get(app) == stamp:
|
||||
continue
|
||||
hidden.pop(app, None)
|
||||
manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app)
|
||||
mine = read(manifest)
|
||||
if app in managed and mine is None:
|
||||
unlink(os.path.join(steamapps, "common", folder))
|
||||
unlink(os.path.join(steamapps, "compatdata", app))
|
||||
if emptied(src, folder):
|
||||
os.unlink(os.path.join(src, "appmanifest_%s.acf" % app))
|
||||
else:
|
||||
hidden[app] = stamp
|
||||
continue
|
||||
if not link(os.path.join(steamapps, "common", folder), os.path.join(src, "common", folder)):
|
||||
continue
|
||||
if os.path.isdir(os.path.join(src, "compatdata", app)):
|
||||
link(os.path.join(steamapps, "compatdata", app), os.path.join(src, "compatdata", app))
|
||||
if mine is not None and number(mine, "LastUpdated") > stamp:
|
||||
write(os.path.join(src, "appmanifest_%s.acf" % app), mine)
|
||||
back.append(app)
|
||||
elif mine != text:
|
||||
write(manifest, text)
|
||||
shared[app] = [src, folder]
|
||||
state = {"shared": shared, "hidden": hidden}
|
||||
write(os.path.join(view, STATE), json.dumps(state, indent=1, sort_keys=True) + "\n")
|
||||
return shared, back
|
||||
|
||||
|
||||
def tools(root):
|
||||
names = set()
|
||||
folder = os.path.join(root, "compatibilitytools.d")
|
||||
try:
|
||||
entries = os.listdir(folder)
|
||||
except OSError:
|
||||
return names
|
||||
for entry in entries:
|
||||
text = read(os.path.join(folder, entry, "compatibilitytool.vdf")) or ""
|
||||
m = re.search(r'"compat_tools"\s*\{\s*"([^"]+)"', text)
|
||||
if m:
|
||||
names.add(m.group(1))
|
||||
return names
|
||||
|
||||
|
||||
def mapping_block(text):
|
||||
m = re.search(r'"CompatToolMapping"\s*\{', text)
|
||||
if not m:
|
||||
return None
|
||||
depth, k = 1, m.end()
|
||||
while depth and k < len(text):
|
||||
depth += {"{": 1, "}": -1}.get(text[k], 0)
|
||||
k += 1
|
||||
return m.end(), k - 1
|
||||
|
||||
|
||||
def entries(text):
|
||||
span = mapping_block(text)
|
||||
found = {}
|
||||
if not span:
|
||||
return found
|
||||
inner = text[span[0]:span[1]]
|
||||
for m in re.finditer(r'"(\d+)"\s*\{([^{}]*)\}', inner):
|
||||
name = re.search(r'"name"\s*"([^"]*)"', m.group(2))
|
||||
found.setdefault(m.group(1), name.group(1) if name else "")
|
||||
return found
|
||||
|
||||
|
||||
def set_tools(config, wanted):
|
||||
text = read(config)
|
||||
if text is None or not wanted:
|
||||
return []
|
||||
span = mapping_block(text)
|
||||
if not span:
|
||||
return []
|
||||
inner = text[span[0]:span[1]]
|
||||
changed = []
|
||||
for app, tool in sorted(wanted.items(), key=lambda item: int(item[0])):
|
||||
m = re.search(r'"%s"\s*\{([^{}]*)\}' % app, inner)
|
||||
if m:
|
||||
name = re.search(r'"name"\s*"([^"]*)"', m.group(1))
|
||||
name = name.group(1) if name else ""
|
||||
if name == tool or not (canonical(name) in map(canonical, AUTOMATIC) or name.startswith("proton_")):
|
||||
continue
|
||||
if name and (name in LINUX_TOOLS) == (tool in LINUX_TOOLS):
|
||||
continue
|
||||
inner = inner[:m.start()] + inner[m.end():]
|
||||
inner = ('\n\t\t\t\t\t"%s"\n\t\t\t\t\t{\n\t\t\t\t\t\t"name"\t\t"%s"\n\t\t\t\t\t\t"config"\t\t""\n'
|
||||
'\t\t\t\t\t\t"priority"\t\t"250"\n\t\t\t\t\t}' % (app, tool)) + inner
|
||||
changed.append(app)
|
||||
if changed:
|
||||
write(config, text[:span[0]] + inner + text[span[1]:])
|
||||
return changed
|
||||
|
||||
|
||||
def canonical(name):
|
||||
return re.sub(r"arm64|aarch64", "a64", name)
|
||||
|
||||
|
||||
def translate(name, here, available):
|
||||
if name == "droiddeck-fex" and here == "x86-64":
|
||||
return "droiddeck-direct"
|
||||
if name == "droiddeck-direct" and here == "arm64":
|
||||
return "droiddeck-fex"
|
||||
return {canonical(a): a for a in available}.get(canonical(name))
|
||||
|
||||
|
||||
def library_helper():
|
||||
sibling = os.path.join(os.path.dirname(os.path.realpath(__file__)), "droiddeck-steam-library")
|
||||
return runpy.run_path(sibling if os.path.isfile(sibling) else "/usr/local/bin/droiddeck-steam-library")
|
||||
|
||||
|
||||
def main(argv):
|
||||
if len(argv) != 5 or argv[0] not in LABELS:
|
||||
say("usage: droiddeck-steam-share arm64|x86-64 ARM_STEAM X64_STEAM X64_CARD SHARED_DIR")
|
||||
return 2
|
||||
here, arm, x64, x64_card, shared_dir = argv
|
||||
views = {name: os.path.join(shared_dir, name) for name in LABELS}
|
||||
roots = {"arm64": arm, "x86-64": x64}
|
||||
other = "x86-64" if here == "arm64" else "arm64"
|
||||
skip = list(views.values()) + [x64, x64_card]
|
||||
arm_libs = libraries(arm, skip)
|
||||
x64_libs = [x64] + [p for p in libraries(x64, list(views.values()) + [arm]) if not same(p, x64)]
|
||||
games = {"arm64": installs(arm_libs), "x86-64": installs(x64_libs)}
|
||||
view = views[other]
|
||||
shared, back = sync(view, games[other], games[here])
|
||||
helper = library_helper()
|
||||
if not any(re.fullmatch(r"appmanifest_\d+\.acf", n) for n in os.listdir(os.path.join(view, "steamapps"))):
|
||||
helper["forget"](roots[here], view)
|
||||
return 0
|
||||
helper["register"](roots[here], view, LABELS[other])
|
||||
helper["relabel"](roots[here], view, LABELS[other])
|
||||
picks = entries(read(os.path.join(roots[other], "config", "config.vdf")) or "")
|
||||
available = tools(roots[here]) | {"droiddeck-direct" if here == "x86-64" else "droiddeck-fex"}
|
||||
wanted = {}
|
||||
for app in shared:
|
||||
tool = translate(picks.get(app) or picks.get("0", ""), here, available)
|
||||
if tool:
|
||||
wanted[app] = tool
|
||||
changed = set_tools(os.path.join(roots[here], "config", "config.vdf"), wanted)
|
||||
say("%d game(s) from the %s client%s%s" % (
|
||||
len(shared), other,
|
||||
"; tools set for %s" % " ".join(changed) if changed else "",
|
||||
"; manifests sent back for %s" % " ".join(back) if back else ""))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main(sys.argv[1:]))
|
||||
@@ -18,13 +18,17 @@ TAG = "droiddeck-app"
|
||||
def account_dir(steam_root):
|
||||
"""The most recent account's userdata folder, else the only one that is not 0."""
|
||||
users = os.path.join(steam_root, "config", "loginusers.vdf")
|
||||
recent = None
|
||||
recent, best = None, None
|
||||
try:
|
||||
with open(users, encoding="utf-8", errors="replace") as f:
|
||||
text = f.read()
|
||||
for block in re.finditer(r'"(\d{5,})"\s*\{([^}]*)\}', text):
|
||||
if re.search(r'"MostRecent"\s*"1"', block.group(2)):
|
||||
recent = int(block.group(1))
|
||||
stamp = re.search(r'"timestamp"\s*"(\d+)"', block.group(2))
|
||||
rank = (bool(re.search(r'"MostRecent"\s*"1"', block.group(2))),
|
||||
bool(re.search(r'"AutoLogin"\s*"1"', block.group(2))),
|
||||
int(stamp.group(1)) if stamp else 0)
|
||||
if any(rank) and (best is None or rank >= best):
|
||||
recent, best = int(block.group(1)), rank
|
||||
except OSError:
|
||||
pass
|
||||
userdata = os.path.join(steam_root, "userdata")
|
||||
|
||||
@@ -26,9 +26,10 @@ TOKEN = re.compile(r'\s+|//[^\n]*|"(?:\\.|[^"\\])*"|[{}]')
|
||||
|
||||
|
||||
class Block:
|
||||
def __init__(self, pairs, end):
|
||||
def __init__(self, pairs, end, offsets=()):
|
||||
self.pairs = pairs
|
||||
self.end = end
|
||||
self.offsets = offsets
|
||||
|
||||
def get(self, name):
|
||||
matches = [value for key, value in self.pairs if key.lower() == name.lower()]
|
||||
@@ -36,6 +37,9 @@ class Block:
|
||||
raise ValueError("duplicate UI setting")
|
||||
return matches[0] if matches else None
|
||||
|
||||
def offset(self, name):
|
||||
return next(at for (key, _), at in zip(self.pairs, self.offsets) if key.lower() == name.lower())
|
||||
|
||||
|
||||
def parse(text):
|
||||
tokens = []
|
||||
@@ -51,17 +55,17 @@ def parse(text):
|
||||
raise ValueError("invalid config.vdf")
|
||||
|
||||
def block(index, nested=False):
|
||||
pairs = []
|
||||
pairs, offsets = [], []
|
||||
while index < len(tokens):
|
||||
token, offset = tokens[index]
|
||||
if token == '}':
|
||||
if not nested:
|
||||
raise ValueError("unexpected closing brace")
|
||||
return Block(pairs, offset), index + 1
|
||||
return Block(pairs, offset, offsets), index + 1
|
||||
if not token.startswith('"') or index + 1 == len(tokens):
|
||||
raise ValueError("missing config value")
|
||||
key = token[1:-1]
|
||||
value = tokens[index + 1][0]
|
||||
value, at = tokens[index + 1]
|
||||
index += 2
|
||||
if value == '{':
|
||||
value, index = block(index, True)
|
||||
@@ -70,9 +74,10 @@ def parse(text):
|
||||
else:
|
||||
raise ValueError("invalid config value")
|
||||
pairs.append((key, value))
|
||||
offsets.append(at)
|
||||
if nested:
|
||||
raise ValueError("unclosed config block")
|
||||
return Block(pairs, len(text)), index
|
||||
return Block(pairs, len(text), offsets), index
|
||||
|
||||
return block(0)[0]
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ x64_map_direct() {
|
||||
[ -f "$STEAM_X64/config/config.vdf" ] || return 0
|
||||
if [ "$mode" = write ] && pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then return 0; fi
|
||||
python3 - "$mode" "$STEAM_X64/config/config.vdf" "$STEAM_X64/appcache/appinfo.vdf" "$X64_HOME/direct-auto.json" \
|
||||
"$X64_HOME/direct-sniper" "$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps" "$(x64_default_tool)" \
|
||||
"$X64_HOME/direct-sniper" "$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps:$X64_HOME/shared/arm64/steamapps" "$(x64_default_tool)" \
|
||||
"$REAL_HOME/.bl-compat-pending" ${BL_X64_DIRECT_APPS:-550} \
|
||||
<<'PY' || { [ "$mode" = live ] || step "could not map titles to DroidDeck direct"; }
|
||||
# Steam does not swap an installed build when the tool changes: a title installed for Windows stays on Proton.
|
||||
@@ -520,39 +520,8 @@ ln -sfn "$STEAM_X64/ubuntu12_32" "$X64_HOME/.steam/bin32"
|
||||
ln -sfn "$STEAM_X64/ubuntu12_64" "$X64_HOME/.steam/bin64"
|
||||
ln -sfn "$STEAM_X64/linux32" "$X64_HOME/.steam/sdk32"
|
||||
ln -sfn "$STEAM_X64/linux64" "$X64_HOME/.steam/sdk64"
|
||||
# The client's bwrap probe (steam-runtime-check-requirements) needs user namespaces, which no Android app has.
|
||||
srt_real=$STEAM_X64/steamrt64/pv-runtime/steam-runtime-steamrt
|
||||
srt_shim=$X64_HOME/steamrt-shim
|
||||
if [ -d "$srt_real" ]; then
|
||||
rm -rf "$srt_shim"
|
||||
mkdir -p "$srt_shim/bin"
|
||||
for e in "$srt_real"/* "$srt_real"/.[!.]*; do
|
||||
[ -e "$e" ] || continue
|
||||
[ "$(basename "$e")" = bin ] || ln -s "$e" "$srt_shim/$(basename "$e")"
|
||||
done
|
||||
for e in "$srt_real"/bin/*; do ln -s "$e" "$srt_shim/bin/$(basename "$e")"; done
|
||||
rm -f "$srt_shim/bin/steam-runtime-check-requirements"
|
||||
printf '#!/bin/sh
|
||||
exit 0
|
||||
' > "$srt_shim/bin/steam-runtime-check-requirements"
|
||||
chmod 755 "$srt_shim/bin/steam-runtime-check-requirements"
|
||||
rm -f "$srt_shim/bin/steam-runtime-launch-client"
|
||||
cat > "$srt_shim/bin/steam-runtime-launch-client" <<'LAUNCH'
|
||||
#!/bin/sh
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--) shift; break ;;
|
||||
--directory=*) cd "${1#--directory=}" || exit 127 ;;
|
||||
--env=*) export "${1#--env=}" ;;
|
||||
--unset-env=*) unset "${1#--unset-env=}" ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
[ $# -gt 0 ] || exit 0
|
||||
exec "$@"
|
||||
LAUNCH
|
||||
chmod 755 "$srt_shim/bin/steam-runtime-launch-client"
|
||||
fi
|
||||
# Valve's Steam Runtime container needs user namespaces and a session-bus launcher; steamrt-shim stands in for both.
|
||||
droiddeck-steamrt-shim "$STEAM_X64/steamrt64" "$X64_HOME/steamrt-shim" || rm -rf "$X64_HOME/steamrt-shim"
|
||||
# Valve's platform libraries ship without soname links (pressure-vessel makes them); ldconfig adds them here.
|
||||
srt_libs=$X64_HOME/steamrt-libs
|
||||
rm -rf "$srt_libs"
|
||||
@@ -641,6 +610,7 @@ RUN
|
||||
printf '"InstallConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n\t\t\t"Steam"\n\t\t\t{\n\t\t\t\t"CompatToolMapping"\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n' \
|
||||
> "$STEAM_X64/config/config.vdf"
|
||||
fi
|
||||
x64_share x86-64
|
||||
x64_map_direct
|
||||
# Each wrapper execs droiddeck-x64-arm-proton through an arm64 binary, which FEX hands straight to the CPU.
|
||||
arm_tools=$ARM_STEAM/compatibilitytools.d
|
||||
@@ -690,9 +660,9 @@ VDF
|
||||
# Each client keeps its own libraries; written only while no x86 client runs, as it rewrites these on exit.
|
||||
if ! pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then
|
||||
listing_ok=0
|
||||
if python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then
|
||||
if BL_X64_SHARED=$X64_HOME/shared/arm64 python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then
|
||||
import json, os, re, sys
|
||||
keep = {os.path.realpath(sys.argv[1])}
|
||||
keep = {os.path.realpath(sys.argv[1]), os.path.realpath(os.environ["BL_X64_SHARED"])}
|
||||
# Without the session's list nothing is known about the card: leave the folders as they are.
|
||||
if not sys.argv[2]:
|
||||
sys.exit(3)
|
||||
@@ -942,6 +912,14 @@ x64_exec() {
|
||||
exec "${BL_FEX:-/usr/local/bin/FEX}" "$STEAM_X64/steamrt64/steam" "$@"
|
||||
}
|
||||
|
||||
x64_share() {
|
||||
pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0
|
||||
pgrep -f 'steamrtarm64/steam( |$)' >/dev/null 2>&1 && return 0
|
||||
[ -d "$STEAM_X64/steamapps" ] && [ -d "$ARM_STEAM/steamapps" ] || return 0
|
||||
droiddeck-steam-share "$1" "$ARM_STEAM" "$STEAM_X64" /mnt/droiddeck-sd/x86-64 "$X64_HOME/shared" ||
|
||||
step "could not share the games between the clients"
|
||||
}
|
||||
|
||||
# Steam renews its token every few days and refuses old copies: copy the newest every start, never while a client runs.
|
||||
x64_sync_login() {
|
||||
pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0
|
||||
@@ -1058,6 +1036,7 @@ PY
|
||||
|
||||
case "${1:-}" in
|
||||
--sync-login) x64_sync_login; exit 0 ;;
|
||||
--share) x64_share arm64; exit 0 ;;
|
||||
--prepare) x64_prepare; exit 0 ;;
|
||||
--exec) shift; x64_exec "$@" ;;
|
||||
--gpu) x64_gpu; exit $? ;;
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#!/bin/bash
|
||||
# droiddeck-steamrt-shim <client runtime dir> <shim dir>
|
||||
# Builds <shim dir> from the Steam Runtime container the client carries and exits 0, or removes it and exits 1
|
||||
# when the client carries none.
|
||||
set -eu
|
||||
client=$1
|
||||
shim=$2
|
||||
srt_real=$client/pv-runtime/steam-runtime-steamrt
|
||||
if [ ! -d "$srt_real" ]; then
|
||||
probe=$(find "$client" -maxdepth 4 -name steam-runtime-check-requirements -path '*/bin/*' -print -quit 2>/dev/null || true)
|
||||
srt_real=${probe:+${probe%/bin/*}}
|
||||
fi
|
||||
if [ -z "$srt_real" ] || [ ! -d "$srt_real" ]; then
|
||||
rm -rf "$shim"
|
||||
exit 1
|
||||
fi
|
||||
rm -rf "$shim"
|
||||
trap 'rm -rf "$shim"' ERR
|
||||
mkdir -p "$shim/bin"
|
||||
for e in "$srt_real"/* "$srt_real"/.[!.]*; do
|
||||
[ -e "$e" ] || continue
|
||||
[ "$(basename "$e")" = bin ] || ln -s "$e" "$shim/$(basename "$e")"
|
||||
done
|
||||
for e in "$srt_real"/bin/*; do
|
||||
[ -e "$e" ] || continue
|
||||
ln -s "$e" "$shim/bin/$(basename "$e")"
|
||||
done
|
||||
# The client's bwrap probe (steam-runtime-check-requirements) needs user namespaces, which no Android app has.
|
||||
rm -f "$shim/bin/steam-runtime-check-requirements"
|
||||
printf '#!/bin/sh
|
||||
exit 0
|
||||
' > "$shim/bin/steam-runtime-check-requirements"
|
||||
chmod 755 "$shim/bin/steam-runtime-check-requirements"
|
||||
# Valve's launcher asks a service on the session bus; proot is already the container, so the command runs here.
|
||||
rm -f "$shim/bin/steam-runtime-launch-client"
|
||||
cat > "$shim/bin/steam-runtime-launch-client" <<'LAUNCH'
|
||||
#!/bin/sh
|
||||
while [ $# -gt 0 ]; do
|
||||
case $1 in
|
||||
--) shift; break ;;
|
||||
--directory=*) cd "${1#--directory=}" || exit 127 ;;
|
||||
--env=*) export "${1#--env=}" ;;
|
||||
--unset-env=*) unset "${1#--unset-env=}" ;;
|
||||
--directory|--env|--unset-env)
|
||||
[ $# -ge 2 ] || exit 127
|
||||
case $1 in
|
||||
--directory) cd "$2" || exit 127 ;;
|
||||
--env) export "$2" ;;
|
||||
--unset-env) unset "$2" ;;
|
||||
esac
|
||||
shift ;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
[ $# -gt 0 ] || exit 0
|
||||
exec "$@"
|
||||
LAUNCH
|
||||
chmod 755 "$shim/bin/steam-runtime-launch-client"
|
||||
@@ -25,6 +25,8 @@ Android: an EOS sign-in step that falls back to a browser (a consent Epic asks f
|
||||
is finished there. An EOS overlay pointer (HKCU\Software\Epic Games\EOS "OverlayPath") an earlier
|
||||
build wrote is removed - with it the game exited while loading.
|
||||
|
||||
Battle.net.exe in Battle.net's prefix is handed to droiddeck-battlenet, which runs the whole launch.
|
||||
|
||||
droiddeck-store-launch <the arguments Steam gave the compat tool>
|
||||
"""
|
||||
|
||||
@@ -291,6 +293,27 @@ def create_prefix(compat_data, proton, timeout=120):
|
||||
CLOUD_TIMEOUT = 15.0
|
||||
CLOUD_STORES = ("gog", "epic")
|
||||
STORE_GAME = 10
|
||||
RAN = 11
|
||||
RAN_FAILED = 12
|
||||
BATTLENET = "/usr/local/bin/droiddeck-battlenet"
|
||||
BATTLENET_EXE = re.compile(r"(?i)/compatdata/2596113170/pfx/drive_c/Program Files \(x86\)/Battle\.net/Battle\.net\.exe$")
|
||||
BATTLENET_LAUNCH = re.compile(r'(?i)^--exec=\s*"?launch\s+([A-Za-z0-9_]{1,16})"?$')
|
||||
|
||||
|
||||
def battlenet(argv, env=os.environ):
|
||||
if env.get("BL_BATTLENET"):
|
||||
return None
|
||||
exe, code = False, None
|
||||
for raw in argv:
|
||||
arg = raw.strip().strip('"').strip("'")
|
||||
if BATTLENET_EXE.search(arg.replace("\\", "/")):
|
||||
exe = True
|
||||
found = BATTLENET_LAUNCH.match(arg)
|
||||
if found:
|
||||
code = found.group(1)
|
||||
if not exe:
|
||||
return None
|
||||
return [BATTLENET, "launch", code] if code else [BATTLENET, "open"]
|
||||
|
||||
|
||||
def cloud_on(sidecar):
|
||||
@@ -511,6 +534,10 @@ def main(argv):
|
||||
pass
|
||||
rest = rest[2:]
|
||||
return exited(rest, code)
|
||||
command = battlenet(argv)
|
||||
if command is not None:
|
||||
log("battlenet " + " ".join(command[1:]))
|
||||
return RAN if subprocess.call(command) == 0 else RAN_FAILED
|
||||
found = find_store_game(argv)
|
||||
if found is None:
|
||||
return 0
|
||||
|
||||
@@ -15,7 +15,18 @@ import threading
|
||||
|
||||
BIN = Path(__file__).resolve().parent
|
||||
RUNTIME = Path('/usr/local/lib/droiddeck-xbox')
|
||||
DLLS = ('xgameruntime.dll', 'winhttp.dll', 'windows.web.dll', 'twinapi.appcore.dll', 'libnghttp2.dll')
|
||||
DLLS = ('xgameruntime.dll', 'winhttp.dll', 'windows.web.dll', 'twinapi.appcore.dll', 'wintypes.dll', 'libnghttp2.dll')
|
||||
CLASSES = {
|
||||
'twinapi.appcore.dll': ('Windows.ApplicationModel.DataTransfer.DataTransferManager',
|
||||
'Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation',
|
||||
'Windows.System.Profile.AnalyticsInfo', 'Windows.System.UserProfile.AdvertisingManager',
|
||||
'Windows.UI.ViewManagement.ApplicationView'),
|
||||
'windows.web.dll': ('Windows.Data.Json.JsonArray', 'Windows.Data.Json.JsonObject', 'Windows.Data.Json.JsonValue'),
|
||||
'wintypes.dll': ('Windows.Foundation.PropertyValue', 'Windows.Foundation.Collections.PropertySet',
|
||||
'Windows.Foundation.Metadata.ApiInformation', 'Windows.Storage.Streams.Buffer',
|
||||
'Windows.Storage.Streams.DataWriter'),
|
||||
}
|
||||
CLASS_KEY = 'Software\\Microsoft\\WindowsRuntime\\ActivatableClassId\\'
|
||||
|
||||
|
||||
def bridge(upstream):
|
||||
@@ -102,6 +113,30 @@ def bridge(upstream):
|
||||
return server.getsockname()[1], key.decode('ascii'), close
|
||||
|
||||
|
||||
def register_classes(proton, prefix, env):
|
||||
try:
|
||||
registry = (prefix / 'system.reg').read_text(encoding='utf-8', errors='replace')
|
||||
except OSError:
|
||||
return
|
||||
missing = [(name, dll) for dll, names in CLASSES.items() for name in names
|
||||
if '[%s]' % (CLASS_KEY + name).replace('\\', '\\\\') not in registry]
|
||||
if not missing:
|
||||
return
|
||||
text = 'Windows Registry Editor Version 5.00\r\n\r\n' + ''.join(
|
||||
'[HKEY_LOCAL_MACHINE\\%s%s]\r\n"DllPath"="C:\\\\windows\\\\system32\\\\%s"\r\n\r\n' % (CLASS_KEY, name, dll)
|
||||
for name, dll in missing)
|
||||
with tempfile.TemporaryDirectory(prefix='droiddeck-xbox-') as temporary:
|
||||
source = Path(temporary) / 'classes.reg'
|
||||
source.write_bytes(b'\xff\xfe' + text.encode('utf-16-le'))
|
||||
try:
|
||||
failed = subprocess.run([proton, 'run', 'reg.exe', 'import', 'Z:' + str(source).replace('/', '\\')],
|
||||
stdout=sys.stderr, env=env, timeout=90).returncode != 0
|
||||
except subprocess.TimeoutExpired:
|
||||
failed = True
|
||||
if failed:
|
||||
print('droiddeck-xbox: Windows Runtime class registration failed; launching without it', file=sys.stderr)
|
||||
|
||||
|
||||
def wine(argv, source_env=None):
|
||||
source_env = os.environ if source_env is None else source_env
|
||||
with open(source_env['DROIDDECK_XBOX_COMMAND_FILE'], encoding='utf-8') as file:
|
||||
@@ -109,7 +144,8 @@ def wine(argv, source_env=None):
|
||||
if len(command) < 3 or command[1] != 'waitforexitandrun' or len(argv) != 1:
|
||||
raise ValueError('Invalid Xbox Proton invocation')
|
||||
env = dict(source_env)
|
||||
env.pop('DROIDDECK_XBOX_CREDENTIAL_SOCKET', None)
|
||||
for name in ('DROIDDECK_XBOX_CREDENTIAL_SOCKET', 'DROIDDECK_XBOX_CREDENTIAL_PORT', 'DROIDDECK_XBOX_CREDENTIAL_KEY'):
|
||||
env.pop(name, None)
|
||||
env.pop('DROIDDECK_XBOX_COMMAND_FILE', None)
|
||||
prefix = Path(source_env['STEAM_COMPAT_DATA_PATH']) / 'pfx'
|
||||
prefix.parent.mkdir(parents=True, exist_ok=True)
|
||||
@@ -124,6 +160,7 @@ def wine(argv, source_env=None):
|
||||
if target.is_symlink():
|
||||
target.unlink()
|
||||
shutil.copyfile(RUNTIME / 'windows' / name, target)
|
||||
register_classes(command[0], prefix, env)
|
||||
overrides = ';'.join(name[:-4] + '=n' for name in DLLS if name != 'libnghttp2.dll')
|
||||
env['WINEDLLOVERRIDES'] = overrides + ';' + env.get('WINEDLLOVERRIDES', '')
|
||||
return subprocess.call([*command[:2], argv[0], *command[3:]], env=env)
|
||||
@@ -171,7 +208,8 @@ def launch(command, env):
|
||||
owned_env = dict(env, DROIDDECK_XBOX_ACTIVE='1', DROIDDECK_XBOX_COMMAND_FILE=str(context),
|
||||
XODUS_SOCKET=reply['socket'], XODUS_BRIDGE_PORT=str(port), XODUS_BRIDGE_KEY=key,
|
||||
XODUS_LOG='off', RUST_LOG='off', XODUS_SAVE_SYNC='auto' if sidecar.get('cloud', True) else 'off')
|
||||
owned_env.pop('DROIDDECK_XBOX_CREDENTIAL_SOCKET', None)
|
||||
for name in ('DROIDDECK_XBOX_CREDENTIAL_SOCKET', 'DROIDDECK_XBOX_CREDENTIAL_PORT', 'DROIDDECK_XBOX_CREDENTIAL_KEY'):
|
||||
owned_env.pop(name, None)
|
||||
if reply.get('playfab'):
|
||||
owned_env['XODUS_XSTS_PLAYFAB'] = reply['playfab']
|
||||
content = folder / '.xbox-content'
|
||||
|
||||
@@ -69,7 +69,10 @@ bl_store_launch() {
|
||||
fi
|
||||
[ -x /usr/local/bin/droiddeck-store-launch ] || return 0
|
||||
/usr/local/bin/droiddeck-store-launch "$@"
|
||||
[ $? -eq 10 ] && BL_STORE_EXIT=1
|
||||
rc=$?
|
||||
[ $rc -eq 10 ] && BL_STORE_EXIT=1
|
||||
[ $rc -eq 11 ] && exit 0
|
||||
[ $rc -eq 12 ] && exit 1
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -1113,10 +1116,89 @@ def requested_tool(request, catalog):
|
||||
|
||||
|
||||
def game_requests(directory=None):
|
||||
value = read_json(state_path("games.json", directory))
|
||||
if value.get("version") != 1 or not isinstance(value.get("games"), dict):
|
||||
return {}
|
||||
return value["games"]
|
||||
return read_game_requests(directory)[0]
|
||||
|
||||
|
||||
def read_game_requests(directory=None):
|
||||
try:
|
||||
with open(state_path("games.json", directory), encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
value = json.loads(text)
|
||||
except (OSError, ValueError):
|
||||
return {}, None
|
||||
if not isinstance(value, dict) or value.get("version") != 1 or not isinstance(value.get("games"), dict):
|
||||
return {}, text
|
||||
return value["games"], text
|
||||
|
||||
|
||||
def write_game_requests(requests, original, directory=None):
|
||||
path = state_path("games.json", directory)
|
||||
try:
|
||||
with open(path, encoding="utf-8") as f:
|
||||
if f.read() != original:
|
||||
return False
|
||||
except OSError:
|
||||
if original is not None:
|
||||
return False
|
||||
return write_json(path, {"version": 1, "games": requests})
|
||||
|
||||
|
||||
def valid_game_request(app, request):
|
||||
return (isinstance(app, str) and re.fullmatch(r"[1-9][0-9]*", app) is not None and int(app) <= 0xFFFFFFFF and
|
||||
(request is None or isinstance(request, dict) and isinstance(request.get("dir"), str) and
|
||||
request["dir"] != "" and isinstance(request.get("valve"), bool)))
|
||||
|
||||
|
||||
def settle_game_requests(requests, state, current, catalog, missing_is_cleared=False):
|
||||
recorded = state.get("games_applied")
|
||||
if isinstance(recorded, dict):
|
||||
applied = dict(recorded)
|
||||
else:
|
||||
applied = dict(requests) if "tools" in state else {}
|
||||
by_name = {t["name"]: t for t in catalog}
|
||||
out = dict(requests)
|
||||
for app, request in requests.items():
|
||||
if not valid_game_request(app, request) or app not in applied or applied[app] != request:
|
||||
continue
|
||||
if request is None:
|
||||
del out[app]
|
||||
continue
|
||||
wanted = requested_tool(request, catalog)
|
||||
if wanted is None:
|
||||
continue
|
||||
if app in current:
|
||||
picked = current[app]
|
||||
elif missing_is_cleared:
|
||||
picked = ""
|
||||
else:
|
||||
continue
|
||||
if picked == wanted:
|
||||
continue
|
||||
tool = by_name.get(picked)
|
||||
if tool and tool["dir"]:
|
||||
out[app] = {"valve": tool["valve"], "dir": tool["dir"]}
|
||||
else:
|
||||
del out[app]
|
||||
return out, out != requests
|
||||
|
||||
|
||||
def settled_game_requests(state, current, catalog, missing_is_cleared=False, directory=None):
|
||||
for _ in range(2):
|
||||
requests, text = read_game_requests(directory)
|
||||
settled, moved = settle_game_requests(requests, state, current, catalog, missing_is_cleared)
|
||||
if not moved or write_game_requests(settled, text, directory):
|
||||
return settled
|
||||
return None
|
||||
|
||||
|
||||
def applied_game_requests(requests, overrides, state):
|
||||
recorded = state.get("games_applied")
|
||||
before = recorded if isinstance(recorded, dict) else {}
|
||||
if requests is None:
|
||||
return dict(before)
|
||||
return {app: request if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL else before[app]
|
||||
for app, request in requests.items()
|
||||
if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL or app in before}
|
||||
|
||||
|
||||
def requested_games(requests, catalog, runnable=None):
|
||||
@@ -1140,6 +1222,32 @@ def requested_games(requests, catalog, runnable=None):
|
||||
return resolved
|
||||
|
||||
|
||||
OWN_PROTON = "DroidDeck-Proton"
|
||||
ARCH_WORDS = re.compile(r"(?i)aarch64|arm64|x86_64|x86-64|amd64")
|
||||
|
||||
|
||||
def own_builds(tools):
|
||||
return [t for t in tools if isinstance(t, dict) and not t.get("valve") and
|
||||
isinstance(t.get("dir"), str) and t["dir"].startswith(OWN_PROTON) and t.get("name")]
|
||||
|
||||
|
||||
def build_key(name):
|
||||
return [int(n) for n in re.findall(r"\d+", ARCH_WORDS.sub(" ", name))]
|
||||
|
||||
|
||||
def own_proton_moves(state, catalog):
|
||||
names = {t["name"] for t in catalog}
|
||||
before = state.get("tools") if isinstance(state.get("tools"), list) else ()
|
||||
seen = state.get("own_builds") if isinstance(state.get("own_builds"), list) else []
|
||||
known = {n for n in seen if isinstance(n, str)} | {t["name"] for t in own_builds(before)} | {t["name"] for t in own_builds(catalog)}
|
||||
state["own_builds"] = sorted(known)
|
||||
builds = own_builds(catalog)
|
||||
if not builds:
|
||||
return None, set()
|
||||
newest = max(builds, key=lambda t: (build_key(t["dir"]), t["dir"]))["name"]
|
||||
return newest, known - names
|
||||
|
||||
|
||||
def now_ms():
|
||||
import time
|
||||
return int(time.time() * 1000)
|
||||
@@ -1300,13 +1408,29 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
catalog = tool_catalog(os.path.dirname(os.path.dirname(os.path.abspath(config_path))),
|
||||
dict(protect) if isinstance(protect, dict) else {name: name for name in protect})
|
||||
names = [t["name"] for t in catalog]
|
||||
newest, gone = own_proton_moves(state, catalog)
|
||||
previous, applied, chosen = state.get("default"), state.get("applied"), state.get("seq")
|
||||
if default is None:
|
||||
if settle:
|
||||
default, state = choose_default(current.get("0", ""), state, read_json(state_path("request.json", directory)), catalog)
|
||||
else:
|
||||
default = state.get("default") if state.get("default") in names else TOOL
|
||||
if settle and newest and default == TOOL and state.get("applied") == applied and state.get("seq") == chosen and (
|
||||
previous in gone or not state.get("own_proton")):
|
||||
default = newest
|
||||
state.update(default=newest, seq=now_ms(), source="update")
|
||||
if settle and newest:
|
||||
state["own_proton"] = True
|
||||
if newest:
|
||||
for app, name in list(current.items()):
|
||||
if app != "0" and name in gone:
|
||||
set_mapping(tokens, mapping, app, newest)
|
||||
current[app] = newest
|
||||
if isinstance(state.get("auto"), dict):
|
||||
state["auto"] = {app: newest if name in gone else name for app, name in state["auto"].items()}
|
||||
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
|
||||
overrides = requested_games(game_requests(directory), catalog)
|
||||
requests = settled_game_requests(state, current, catalog, not steam_running(), directory)
|
||||
overrides = requested_games(requests or {}, catalog)
|
||||
managed = state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else ()
|
||||
native_choices = state.get("native_choices", ())
|
||||
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
|
||||
@@ -1325,6 +1449,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
|
||||
state["auto"] = {app: tool for app, tool in auto.items() if tool is not NATIVE_CHOICE}
|
||||
state["native_choices"] = sorted(app for app, tool in auto.items() if tool is NATIVE_CHOICE)
|
||||
state["picked"] = picked_after(current, changes)
|
||||
state["games_applied"] = applied_game_requests(requests, overrides, state)
|
||||
state.pop("native", None)
|
||||
state["tools"] = catalog
|
||||
state.setdefault("default", default)
|
||||
|
||||
+279
-74
@@ -17,6 +17,7 @@
|
||||
#include <sys/syscall.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <time.h>
|
||||
#include <ucontext.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct ns_sem_args {
|
||||
@@ -68,12 +69,13 @@ struct ns_wait_args {
|
||||
#define NS_PROCS 256u
|
||||
#define NS_FDS 65536
|
||||
#define NS_DEVS 8
|
||||
#define NS_VERSION 1u
|
||||
#define NS_VERSION 2u
|
||||
#define NS_HEAD_MAGIC 0x31434e5953544e44ull
|
||||
#define NS_DEV_MAGIC 0x4e54445600000000ull
|
||||
#define NS_OBJ_MAGIC 0x27ull
|
||||
#define NS_WAITERS 0x80000000u
|
||||
#define NS_SWEEP_NS 2000000000ull
|
||||
#define NS_SPIN_NS 4000ull
|
||||
#define NS_DEAD 0xffffffffu
|
||||
|
||||
#ifndef CLOSE_RANGE_CLOEXEC
|
||||
@@ -144,6 +146,7 @@ struct ns_q {
|
||||
uint32_t waiting;
|
||||
uint32_t inuse;
|
||||
uint32_t next_free;
|
||||
uint32_t sleeping;
|
||||
struct ns_ent ent[NS_ENTS];
|
||||
};
|
||||
|
||||
@@ -168,6 +171,7 @@ struct ns_tls {
|
||||
struct ns_dev *d;
|
||||
uint32_t q;
|
||||
int waiting;
|
||||
int sleep;
|
||||
};
|
||||
|
||||
static struct ns_dev ns_devs[NS_DEVS];
|
||||
@@ -255,19 +259,148 @@ static void ns_unlock(uint32_t *w) {
|
||||
}
|
||||
}
|
||||
|
||||
static void ns_block(sigset_t *old) {
|
||||
sigset_t s;
|
||||
sigfillset(&s);
|
||||
sigdelset(&s, SIGSEGV);
|
||||
sigdelset(&s, SIGBUS);
|
||||
sigdelset(&s, SIGILL);
|
||||
sigdelset(&s, SIGFPE);
|
||||
sigdelset(&s, SIGTRAP);
|
||||
pthread_sigmask(SIG_BLOCK, &s, old);
|
||||
#define NS_DEFER 4
|
||||
#define NS_LEVELS 8
|
||||
|
||||
struct ns_cs {
|
||||
int depth;
|
||||
int count;
|
||||
int level;
|
||||
unsigned held_levels;
|
||||
int sigs[NS_DEFER];
|
||||
siginfo_t info[NS_DEFER];
|
||||
sigset_t held[NS_LEVELS];
|
||||
};
|
||||
|
||||
static __thread struct ns_cs ns_cs;
|
||||
static uintptr_t ns_handlers[_NSIG];
|
||||
static uint8_t ns_siginfo[_NSIG];
|
||||
|
||||
int bl_from_ntdll(const void *caller) __attribute__((visibility("hidden")));
|
||||
|
||||
static int ns_deferrable(int sig) {
|
||||
return sig > 0 && sig < _NSIG && sig != SIGKILL && sig != SIGSTOP && sig != SIGSEGV && sig != SIGBUS && sig != SIGILL
|
||||
&& sig != SIGFPE && sig != SIGTRAP && sig != SIGSYS;
|
||||
}
|
||||
|
||||
static void ns_restore(const sigset_t *old) {
|
||||
pthread_sigmask(SIG_SETMASK, old, NULL);
|
||||
static int ns_defer(int sig, const siginfo_t *si) {
|
||||
struct ns_cs *cs = &ns_cs;
|
||||
if (sig < SIGRTMIN)
|
||||
for (int i = 0; i < NS_DEFER; i++)
|
||||
if (__atomic_load_n(&cs->sigs[i], __ATOMIC_RELAXED) == sig) return 1;
|
||||
int i = __atomic_fetch_add(&cs->count, 1, __ATOMIC_RELAXED);
|
||||
if (i >= NS_DEFER) {
|
||||
__atomic_fetch_sub(&cs->count, 1, __ATOMIC_RELAXED);
|
||||
return 0;
|
||||
}
|
||||
if (si) memcpy(&cs->info[i], si, sizeof(*si));
|
||||
else memset(&cs->info[i], 0, sizeof(*si));
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
__atomic_store_n(&cs->sigs[i], sig, __ATOMIC_RELAXED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int ns_park(int sig, const siginfo_t *si, ucontext_t *uc) {
|
||||
int level = ns_cs.level;
|
||||
if (level < 0 || level >= NS_LEVELS) return 0;
|
||||
sigset_t one;
|
||||
sigemptyset(&one);
|
||||
sigaddset(&one, sig);
|
||||
int saved = errno;
|
||||
pthread_sigmask(SIG_BLOCK, &one, NULL);
|
||||
pid_t pid = getpid(), tid = (pid_t)ns_self();
|
||||
int ok = (si && syscall(SYS_rt_tgsigqueueinfo, pid, tid, sig, si) == 0) || syscall(SYS_tgkill, pid, tid, sig) == 0;
|
||||
if (!ok) pthread_sigmask(SIG_UNBLOCK, &one, NULL);
|
||||
errno = saved;
|
||||
if (!ok) return 0;
|
||||
sigaddset(&uc->uc_sigmask, sig);
|
||||
unsigned long *words = (unsigned long *)&ns_cs.held[level];
|
||||
unsigned bits = 8 * sizeof(unsigned long);
|
||||
__atomic_fetch_or(&words[(unsigned)(sig - 1) / bits], 1ul << ((unsigned)(sig - 1) % bits), __ATOMIC_RELAXED);
|
||||
__atomic_fetch_or(&ns_cs.held_levels, 1u << level, __ATOMIC_RELAXED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void ns_trampoline(int sig, siginfo_t *si, void *uc) {
|
||||
if (__atomic_load_n(&ns_cs.depth, __ATOMIC_RELAXED) > 0 && (ns_defer(sig, si) || (uc && ns_park(sig, si, uc)))) return;
|
||||
uintptr_t h = __atomic_load_n(&ns_handlers[sig], __ATOMIC_ACQUIRE);
|
||||
if (!h) return;
|
||||
ns_cs.level++;
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
if (__atomic_load_n(&ns_siginfo[sig], __ATOMIC_RELAXED)) ((void (*)(int, siginfo_t *, void *))h)(sig, si, uc);
|
||||
else ((void (*)(int))h)(sig);
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
ns_cs.level--;
|
||||
}
|
||||
|
||||
static void ns_flush(void) {
|
||||
struct ns_cs *cs = &ns_cs;
|
||||
sigset_t all, mask;
|
||||
sigfillset(&all);
|
||||
int saved = errno;
|
||||
pthread_sigmask(SIG_BLOCK, &all, &mask);
|
||||
int n = cs->count < NS_DEFER ? cs->count : NS_DEFER;
|
||||
pid_t pid = getpid(), tid = (pid_t)ns_self();
|
||||
for (int i = 0; i < n; i++)
|
||||
if (cs->sigs[i] > 0 && syscall(SYS_rt_tgsigqueueinfo, pid, tid, cs->sigs[i], &cs->info[i]) != 0) syscall(SYS_tgkill, pid, tid, cs->sigs[i]);
|
||||
memset(cs->sigs, 0, sizeof(cs->sigs));
|
||||
cs->count = 0;
|
||||
int level = cs->level;
|
||||
if (level >= 0 && level < NS_LEVELS && (cs->held_levels & (1u << level))) {
|
||||
for (int sig = 1; sig < _NSIG; sig++)
|
||||
if (sigismember(&cs->held[level], sig) == 1) sigdelset(&mask, sig);
|
||||
sigemptyset(&cs->held[level]);
|
||||
cs->held_levels &= ~(1u << level);
|
||||
}
|
||||
pthread_sigmask(SIG_SETMASK, &mask, NULL);
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static void ns_block(void) {
|
||||
ns_cs.depth++;
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
}
|
||||
|
||||
static void ns_restore(void) {
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
if (--ns_cs.depth == 0) {
|
||||
__atomic_signal_fence(__ATOMIC_SEQ_CST);
|
||||
if (ns_cs.count || (ns_cs.held_levels && ns_cs.level >= 0 && ns_cs.level < NS_LEVELS && (ns_cs.held_levels & (1u << ns_cs.level))))
|
||||
ns_flush();
|
||||
}
|
||||
}
|
||||
|
||||
int sigaction(int sig, const struct sigaction *act, struct sigaction *old) {
|
||||
static int (*real)(int, const struct sigaction *, struct sigaction *);
|
||||
if (!real) real = (int (*)(int, const struct sigaction *, struct sigaction *))dlsym(RTLD_NEXT, "sigaction");
|
||||
if (!real) {
|
||||
errno = ENOSYS;
|
||||
return -1;
|
||||
}
|
||||
if (!ns_deferrable(sig) || !ns_on()) return real(sig, act, old);
|
||||
uintptr_t prev = __atomic_load_n(&ns_handlers[sig], __ATOMIC_ACQUIRE);
|
||||
uint8_t prev_info = __atomic_load_n(&ns_siginfo[sig], __ATOMIC_RELAXED);
|
||||
struct sigaction mine;
|
||||
const struct sigaction *use = act;
|
||||
if (act && act->sa_handler != SIG_DFL && act->sa_handler != SIG_IGN && !(act->sa_flags & SA_RESETHAND) &&
|
||||
bl_from_ntdll(__builtin_return_address(0))) {
|
||||
mine = *act;
|
||||
mine.sa_sigaction = ns_trampoline;
|
||||
mine.sa_flags |= SA_SIGINFO;
|
||||
__atomic_store_n(&ns_siginfo[sig], (act->sa_flags & SA_SIGINFO) ? 1 : 0, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&ns_handlers[sig], (uintptr_t)act->sa_sigaction, __ATOMIC_RELEASE);
|
||||
use = &mine;
|
||||
}
|
||||
int r = real(sig, use, old);
|
||||
if (r != 0 && use == &mine) {
|
||||
__atomic_store_n(&ns_siginfo[sig], prev_info, __ATOMIC_RELAXED);
|
||||
__atomic_store_n(&ns_handlers[sig], prev, __ATOMIC_RELEASE);
|
||||
}
|
||||
if (r == 0 && old && old->sa_sigaction == ns_trampoline) {
|
||||
old->sa_sigaction = (void (*)(int, siginfo_t *, void *))prev;
|
||||
if (!prev_info) old->sa_flags &= ~SA_SIGINFO;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline struct ns_obj *ns_obj(struct ns_head *h, uint32_t s) {
|
||||
@@ -378,10 +511,11 @@ static int ns_claim(struct ns_q *q, int32_t index) {
|
||||
if (dead) return 0;
|
||||
}
|
||||
int32_t want = -1;
|
||||
return __atomic_compare_exchange_n(&q->signaled, &want, index, 0, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED);
|
||||
return __atomic_compare_exchange_n(&q->signaled, &want, index, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static void ns_wake(struct ns_q *q) {
|
||||
if (!__atomic_load_n(&q->sleeping, __ATOMIC_SEQ_CST)) return;
|
||||
int saved = errno;
|
||||
ns_futex(&q->signaled, FUTEX_WAKE, 1, NULL, 0);
|
||||
errno = saved;
|
||||
@@ -618,14 +752,13 @@ static void ns_dev_put_locked(struct ns_dev *d) {
|
||||
|
||||
static void ns_dev_put(struct ns_dev *d) {
|
||||
if (__atomic_sub_fetch(&d->refs, 1, __ATOMIC_ACQ_REL)) return;
|
||||
sigset_t old;
|
||||
int saved = errno;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
uint32_t zero = 0;
|
||||
if (d->h && __atomic_compare_exchange_n(&d->refs, &zero, NS_DEAD, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) ns_release(d);
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
@@ -682,20 +815,18 @@ static void ns_forget_locked(int fd) {
|
||||
}
|
||||
|
||||
static void ns_forget(int fd) {
|
||||
sigset_t old;
|
||||
int saved = errno;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
ns_forget_locked(fd);
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static uint64_t ns_adopt(struct ns_dev *d, uint32_t tag, int fd, uint32_t gen, uint32_t s) {
|
||||
uint64_t e = 0;
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
if (!d->h || d->tag != tag || !ns_table() || ns_attach(d) < 0 || s >= NS_SLOTS) goto out;
|
||||
if ((e = __atomic_load_n(&ns_fdt[fd], __ATOMIC_ACQUIRE))) goto out;
|
||||
@@ -710,7 +841,7 @@ static uint64_t ns_adopt(struct ns_dev *d, uint32_t tag, int fd, uint32_t gen, u
|
||||
ns_unlock(&o->lock);
|
||||
out:
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -719,8 +850,7 @@ static uint64_t ns_note_device(int fd) {
|
||||
uint64_t e = 0;
|
||||
if (syscall(SYS_fstat, fd, &st) != 0 || !S_ISREG(st.st_mode)) return 0;
|
||||
if (((uint64_t)st.st_size & ~0xffffull) != NS_DEV_MAGIC) return 0;
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
struct ns_dev *d = ns_table() ? ns_map(fd, (uint32_t)st.st_size & 0xffff, (uint64_t)st.st_ino) : NULL;
|
||||
if (d) {
|
||||
@@ -732,7 +862,7 @@ static uint64_t ns_note_device(int fd) {
|
||||
}
|
||||
}
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return e;
|
||||
}
|
||||
|
||||
@@ -773,15 +903,14 @@ static int ns_ready(struct ns_dev *d) {
|
||||
|
||||
static void ns_thread_gone(void *p) {
|
||||
struct ns_tls *t = p;
|
||||
if (!t || !t->d || !t->q) return;
|
||||
sigset_t old;
|
||||
if (!t || !t->d) return;
|
||||
struct ns_dev *d = t->d;
|
||||
ns_block(&old);
|
||||
ns_free_q(d->h, t->q - 1);
|
||||
ns_block();
|
||||
if (t->q) ns_free_q(d->h, t->q - 1);
|
||||
t->q = 0;
|
||||
t->waiting = 0;
|
||||
t->d = NULL;
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
ns_dev_put(d);
|
||||
}
|
||||
|
||||
@@ -789,24 +918,28 @@ static void ns_key_init(void) {
|
||||
pthread_key_create(&ns_key, ns_thread_gone);
|
||||
}
|
||||
|
||||
static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_head *h = d->h;
|
||||
if (ns_tq.d && ns_tq.q && ns_tq.waiting) {
|
||||
ns_drop_q(ns_tq.d->h, ns_tq.q - 1);
|
||||
ns_tq.waiting = 0;
|
||||
}
|
||||
if (ns_tq.d == d && ns_tq.q) {
|
||||
*qi = ns_tq.q - 1;
|
||||
return ns_q(h, *qi);
|
||||
}
|
||||
if (ns_tq.d && ns_tq.q) {
|
||||
struct ns_dev *old = ns_tq.d;
|
||||
ns_free_q(old->h, ns_tq.q - 1);
|
||||
static int ns_hold(struct ns_dev *d) {
|
||||
if (ns_tq.d == d) return 1;
|
||||
if (!ns_dev_get(d)) return 0;
|
||||
if (ns_tq.sleep) return 2;
|
||||
struct ns_dev *old = ns_tq.d;
|
||||
if (old) {
|
||||
ns_block();
|
||||
if (ns_tq.q) ns_free_q(old->h, ns_tq.q - 1);
|
||||
ns_tq.q = 0;
|
||||
ns_tq.waiting = 0;
|
||||
ns_tq.d = NULL;
|
||||
ns_restore();
|
||||
ns_dev_put(old);
|
||||
}
|
||||
pthread_once(&ns_once, ns_key_init);
|
||||
ns_tq.d = d;
|
||||
pthread_setspecific(ns_key, &ns_tq);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static struct ns_q *ns_new_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_head *h = d->h;
|
||||
uint32_t i;
|
||||
if (!ns_pop(h, &h->q_free, 0, &i) && !ns_grow(&h->q_hwm, NS_QS, &i)) {
|
||||
ns_sweep_dead(h);
|
||||
@@ -815,22 +948,35 @@ static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_q *q = ns_q(h, i);
|
||||
q->proc = (uint32_t)d->proc;
|
||||
q->waiting = 0;
|
||||
q->sleeping = 0;
|
||||
q->inuse = 1;
|
||||
__atomic_add_fetch(&d->refs, 1, __ATOMIC_ACQ_REL);
|
||||
ns_tq.d = d;
|
||||
ns_tq.q = i + 1;
|
||||
ns_tq.waiting = 0;
|
||||
pthread_setspecific(ns_key, &ns_tq);
|
||||
*qi = i;
|
||||
return q;
|
||||
}
|
||||
|
||||
static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
|
||||
struct ns_head *h = d->h;
|
||||
if (ns_tq.d != d) return NULL;
|
||||
if (ns_tq.q && ns_tq.waiting) {
|
||||
ns_drop_q(h, ns_tq.q - 1);
|
||||
ns_tq.waiting = 0;
|
||||
}
|
||||
if (ns_tq.q) {
|
||||
*qi = ns_tq.q - 1;
|
||||
return ns_q(h, *qi);
|
||||
}
|
||||
struct ns_q *q = ns_new_q(d, qi);
|
||||
if (!q) return NULL;
|
||||
ns_tq.q = *qi + 1;
|
||||
ns_tq.waiting = 0;
|
||||
return q;
|
||||
}
|
||||
|
||||
static int ns_create(struct ns_dev *d, int type, uint32_t a, uint32_t b) {
|
||||
struct ns_head *h = d->h;
|
||||
sigset_t old;
|
||||
int fd = -1, err = 0;
|
||||
uint32_t s = 0;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
pthread_mutex_lock(&ns_mx);
|
||||
if (!ns_table() || ns_attach(d) < 0) {
|
||||
err = ENOMEM;
|
||||
@@ -879,7 +1025,7 @@ static int ns_create(struct ns_dev *d, int type, uint32_t a, uint32_t b) {
|
||||
ns_unlock(&o->lock);
|
||||
out:
|
||||
pthread_mutex_unlock(&ns_mx);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
if (fd < 0) errno = err;
|
||||
return fd;
|
||||
}
|
||||
@@ -890,6 +1036,20 @@ static int ns_expired(const struct ns_wait_args *args) {
|
||||
return (uint64_t)now.tv_sec * 1000000000ull + (uint64_t)now.tv_nsec >= args->timeout;
|
||||
}
|
||||
|
||||
static uint64_t ns_now(void) {
|
||||
struct timespec now;
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
return (uint64_t)now.tv_sec * 1000000000ull + (uint64_t)now.tv_nsec;
|
||||
}
|
||||
|
||||
static void ns_spin(struct ns_q *q) {
|
||||
uint64_t end = ns_now() + NS_SPIN_NS;
|
||||
for (unsigned i = 1; __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1; i++) {
|
||||
ns_relax();
|
||||
if (!(i & 63) && ns_now() >= end) return;
|
||||
}
|
||||
}
|
||||
|
||||
static int ns_sleep(struct ns_q *q, const struct ns_wait_args *args) {
|
||||
struct timespec ts, *tsp = NULL;
|
||||
int op = FUTEX_WAIT_BITSET | ((args->flags & NS_WAIT_REALTIME) ? FUTEX_CLOCK_REALTIME : 0);
|
||||
@@ -898,14 +1058,45 @@ static int ns_sleep(struct ns_q *q, const struct ns_wait_args *args) {
|
||||
ts.tv_nsec = (long)(args->timeout % 1000000000ull);
|
||||
tsp = &ts;
|
||||
}
|
||||
while (__atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1) {
|
||||
if (tsp && ns_expired(args)) return ETIMEDOUT;
|
||||
if (ns_futex(&q->signaled, op, (uint32_t)-1, tsp, FUTEX_BITSET_MATCH_ANY) == -1) {
|
||||
if (errno == ETIMEDOUT) return ETIMEDOUT;
|
||||
if (errno == EINTR) return EINTR;
|
||||
}
|
||||
ns_spin(q);
|
||||
int ret = 0;
|
||||
__atomic_store_n(&q->sleeping, 1, __ATOMIC_SEQ_CST);
|
||||
while (!ret && __atomic_load_n(&q->signaled, __ATOMIC_SEQ_CST) == -1) {
|
||||
if (tsp && ns_expired(args)) ret = ETIMEDOUT;
|
||||
else if (ns_futex(&q->signaled, op, (uint32_t)-1, tsp, FUTEX_BITSET_MATCH_ANY) == -1 && (errno == ETIMEDOUT || errno == EINTR))
|
||||
ret = errno;
|
||||
}
|
||||
return 0;
|
||||
__atomic_store_n(&q->sleeping, 0, __ATOMIC_RELAXED);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int ns_try_any(struct ns_head *h, const uint32_t *slots, const uint32_t *gens, uint32_t total, uint32_t owner, int *dead) {
|
||||
for (uint32_t i = 0; i < total; i++) {
|
||||
struct ns_obj *o = ns_obj(h, slots[i]);
|
||||
ns_lock(&o->lock);
|
||||
int busy = o->type == NS_FREE || o->gen != gens[i] || o->any_head || o->all_hint;
|
||||
if (!busy && ns_signaled(o, owner)) {
|
||||
switch (o->type) {
|
||||
case NS_SEM:
|
||||
o->a--;
|
||||
break;
|
||||
case NS_MUTEX:
|
||||
*dead = (int)o->ownerdead;
|
||||
o->ownerdead = 0;
|
||||
o->a++;
|
||||
o->b = owner;
|
||||
break;
|
||||
case NS_EVENT:
|
||||
if (!o->a) o->b = 0;
|
||||
break;
|
||||
}
|
||||
ns_unlock(&o->lock);
|
||||
return (int)i;
|
||||
}
|
||||
ns_unlock(&o->lock);
|
||||
if (busy) return -1;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
|
||||
static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
@@ -927,12 +1118,24 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
for (uint32_t j = 0; j < i; j++)
|
||||
if (slots[j] == slots[i]) return EINVAL;
|
||||
}
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
int nested = ns_tq.sleep > 0;
|
||||
ns_block();
|
||||
if (!all && (nested || !ns_tq.waiting)) {
|
||||
int dead = 0, got = ns_try_any(h, slots, gens, total, args.owner, &dead);
|
||||
if (got >= 0) {
|
||||
ns_restore();
|
||||
ua->index = (uint32_t)got;
|
||||
return dead ? EOWNERDEAD : 0;
|
||||
}
|
||||
if (got == -2 && args.timeout != UINT64_MAX && ns_expired(&args)) {
|
||||
ns_restore();
|
||||
return ETIMEDOUT;
|
||||
}
|
||||
}
|
||||
uint32_t qi;
|
||||
struct ns_q *q = ns_ready(d) ? ns_thread_q(d, &qi) : NULL;
|
||||
struct ns_q *q = !ns_ready(d) ? NULL : nested ? ns_new_q(d, &qi) : ns_thread_q(d, &qi);
|
||||
if (!q) {
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return ENOMEM;
|
||||
}
|
||||
ns_maybe_sweep(h);
|
||||
@@ -952,7 +1155,7 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
}
|
||||
q->total = total;
|
||||
q->waiting = 1;
|
||||
ns_tq.waiting = 1;
|
||||
if (!nested) ns_tq.waiting = 1;
|
||||
int bad = 0;
|
||||
if (!all) {
|
||||
for (uint32_t i = 0; i < total && !bad; i++) {
|
||||
@@ -1004,16 +1207,18 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
|
||||
}
|
||||
int ret = 0;
|
||||
if (!bad && __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1) {
|
||||
sigset_t held;
|
||||
ns_restore(&old);
|
||||
ns_tq.sleep++;
|
||||
ns_restore();
|
||||
ret = ns_sleep(q, &args);
|
||||
ns_block(&held);
|
||||
ns_block();
|
||||
ns_tq.sleep--;
|
||||
}
|
||||
ns_drop_q(h, qi);
|
||||
ns_tq.waiting = 0;
|
||||
if (!nested) ns_tq.waiting = 0;
|
||||
int32_t got = __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE);
|
||||
int dead = (int)q->ownerdead;
|
||||
ns_restore(&old);
|
||||
if (nested) ns_free_q(h, qi);
|
||||
ns_restore();
|
||||
if (bad) return EINVAL;
|
||||
if (got != -1) {
|
||||
ua->index = (uint32_t)got;
|
||||
@@ -1061,12 +1266,11 @@ static int ns_obj_ioctl(struct ns_dev *d, uint64_t e, unsigned long req, void *a
|
||||
return ENOTTY;
|
||||
}
|
||||
if (type != (uint32_t)want) return EINVAL;
|
||||
sigset_t old;
|
||||
ns_block(&old);
|
||||
ns_block();
|
||||
int all = ns_lock_obj(h, o);
|
||||
if (o->type != (uint32_t)want || o->gen != gen) {
|
||||
ns_unlock_obj(h, o, all);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
return EINVAL;
|
||||
}
|
||||
switch (req) {
|
||||
@@ -1133,7 +1337,7 @@ static int ns_obj_ioctl(struct ns_dev *d, uint64_t e, unsigned long req, void *a
|
||||
}
|
||||
}
|
||||
ns_unlock_obj(h, o, all);
|
||||
ns_restore(&old);
|
||||
ns_restore();
|
||||
if (ret) return ret;
|
||||
if (req == NS_SEM_RELEASE || req == NS_EVENT_SET || req == NS_EVENT_RESET || req == NS_EVENT_PULSE)
|
||||
memcpy(arg, &prev, sizeof(prev));
|
||||
@@ -1176,9 +1380,10 @@ int bl_ntsync_ioctl(int fd, unsigned long req, void *arg, int *rc) {
|
||||
uint64_t e = ns_lookup(fd);
|
||||
if (!e) return 0;
|
||||
struct ns_dev *d = &ns_devs[(e >> 56) & 7];
|
||||
if (!ns_dev_get(d)) return 0;
|
||||
int held = ns_hold(d);
|
||||
if (!held) return 0;
|
||||
int out = 0, err = (e & NS_E_DEVICE) ? ns_dev_ioctl(d, req, arg, &out) : ns_obj_ioctl(d, e, req, arg);
|
||||
ns_dev_put(d);
|
||||
if (held == 2) ns_dev_put(d);
|
||||
if (err) {
|
||||
errno = err;
|
||||
*rc = -1;
|
||||
|
||||
@@ -51,9 +51,16 @@ static void rt_send(void *dpy, uint32_t action) {
|
||||
}
|
||||
}
|
||||
|
||||
static void *rt_xtst(const char *name) {
|
||||
void *fn = dlsym(RTLD_NEXT, name);
|
||||
if (fn) return fn;
|
||||
void *lib = dlopen("libXtst.so.6", RTLD_LAZY | RTLD_NOLOAD);
|
||||
return lib ? dlsym(lib, name) : NULL;
|
||||
}
|
||||
|
||||
int XTestFakeMotionEvent(void *dpy, int screen, int x, int y, unsigned long delay) {
|
||||
static int (*real)(void *, int, int, int, unsigned long);
|
||||
if (!real) real = (int (*)(void *, int, int, int, unsigned long))dlsym(RTLD_NEXT, "XTestFakeMotionEvent");
|
||||
if (!real) real = (int (*)(void *, int, int, int, unsigned long))rt_xtst("XTestFakeMotionEvent");
|
||||
if (rt_enabled()) {
|
||||
pthread_mutex_lock(&rt_lock);
|
||||
rt_x = x;
|
||||
@@ -69,7 +76,7 @@ int XTestFakeMotionEvent(void *dpy, int screen, int x, int y, unsigned long dela
|
||||
|
||||
int XTestFakeButtonEvent(void *dpy, unsigned int button, int press, unsigned long delay) {
|
||||
static int (*real)(void *, unsigned int, int, unsigned long);
|
||||
if (!real) real = (int (*)(void *, unsigned int, int, unsigned long))dlsym(RTLD_NEXT, "XTestFakeButtonEvent");
|
||||
if (!real) real = (int (*)(void *, unsigned int, int, unsigned long))rt_xtst("XTestFakeButtonEvent");
|
||||
if (button == 1) {
|
||||
pthread_mutex_lock(&rt_lock);
|
||||
int handled = 0;
|
||||
|
||||
@@ -25,14 +25,7 @@ trap 'rm -rf "$work"' EXIT
|
||||
sha256() { if command -v sha256sum >/dev/null; then sha256sum "$1" | cut -d' ' -f1; else shasum -a 256 "$1" | cut -d' ' -f1; fi; }
|
||||
|
||||
fetch() {
|
||||
local url=$1 expected=$2 dest=$3
|
||||
curl -fsSL --retry 4 -o "$dest" "$url"
|
||||
local actual
|
||||
actual=$(sha256 "$dest")
|
||||
if [ "$actual" != "$expected" ]; then
|
||||
echo "checksum mismatch for $url: $actual" >&2
|
||||
exit 1
|
||||
fi
|
||||
bash "$here/fetch-verified.sh" "$@"
|
||||
}
|
||||
|
||||
pack() {
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
url=${1:?URL required}
|
||||
expected=${2:?SHA-256 required}
|
||||
destination=${3:?destination required}
|
||||
[[ "$expected" =~ ^[a-f0-9]{64}$ ]] || { echo 'Invalid download SHA-256' >&2; exit 1; }
|
||||
cache=${DROIDDECK_PACK_CACHE:-"$HOME/.cache/droiddeck-pack-inputs"}
|
||||
mkdir -p "$cache" "$(dirname "$destination")"
|
||||
kept="$cache/$expected"
|
||||
verify() {
|
||||
if command -v sha256sum >/dev/null; then
|
||||
echo "$expected $1" | sha256sum -c - >/dev/null 2>&1
|
||||
else
|
||||
echo "$expected $1" | shasum -a 256 -c - >/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
if [ -f "$kept" ] && verify "$kept"; then
|
||||
echo "Verified pack input cache hit: $expected"
|
||||
else
|
||||
part=$(mktemp "$cache/$expected.part.XXXXXX")
|
||||
trap 'rm -f "$part"' EXIT
|
||||
curl -fsSL --retry 4 --retry-all-errors --connect-timeout 15 --max-time 180 --retry-max-time 240 \
|
||||
-o "$part" "$url"
|
||||
verify "$part" || { echo "Checksum mismatch for $url" >&2; exit 1; }
|
||||
if [ -d "$kept" ]; then
|
||||
rm -rf -- "$kept"
|
||||
fi
|
||||
mv -f "$part" "$kept"
|
||||
echo "Downloaded and verified pack input: $expected"
|
||||
fi
|
||||
cp "$kept" "$destination"
|
||||
verify "$destination" || { echo 'Copied pack input checksum mismatch' >&2; exit 1; }
|
||||
@@ -124,3 +124,11 @@ Old kernel fixes:
|
||||
by the kernel instead. The original clone flags are preserved. When the kernel supplies a valid
|
||||
ID in the notification, normal setup is unchanged. No timers or background polling are added.
|
||||
Completely missing notifications and ambiguous matches for separate processes are not recovered.
|
||||
|
||||
Development diagnostics:
|
||||
|
||||
- `0018-syscall-handler-profile.patch` - `PROOT_PROFILE=1` enables per-syscall entry/exit handler
|
||||
counts, wall/CPU time, periodic cumulative JSON totals, and bounded slow-handler samples on
|
||||
stderr. `profile.h` is copied into the source tree by `build.sh`. It adds no ptrace stops;
|
||||
handler timing excludes tracee kernel time and scheduling before handler entry. See
|
||||
`docs/development/proot-performance.md` for the capture and library-override workflow.
|
||||
@@ -31,6 +31,7 @@ fetch() {
|
||||
fetch proot.tar.gz "https://github.com/termux/proot/archive/${PROOT_COMMIT}.tar.gz" "$PROOT_SHA256"
|
||||
fetch talloc.tar.gz "https://www.samba.org/ftp/talloc/talloc-${TALLOC_VERSION}.tar.gz" "$TALLOC_SHA256"
|
||||
cp "$HERE/statx_mnt_id.h" "$WORK/proot/src/tracee/statx_mnt_id.h"
|
||||
cp "$HERE/profile.h" "$WORK/proot/src/syscall/profile.h"
|
||||
for patch in "$HERE"/patches/*.patch; do
|
||||
patch -d "$WORK/proot" -p1 --forward --quiet < "$patch"
|
||||
done
|
||||
|
||||
@@ -875,19 +875,84 @@ int __fxstat(int ver, int fd, struct stat *st) {
|
||||
}
|
||||
int __fxstat64(int ver, int fd, struct stat64 *st) { return __fxstat(ver, fd, (struct stat *)st); }
|
||||
|
||||
#ifndef STATX__RESERVED
|
||||
#define STATX__RESERVED 0x80000000U
|
||||
#endif
|
||||
|
||||
static int statx_missing;
|
||||
|
||||
static unsigned int dev_major(unsigned long long dev) {
|
||||
return ((dev >> 8) & 0xfff) | ((unsigned int)(dev >> 32) & ~0xfffU);
|
||||
}
|
||||
static unsigned int dev_minor(unsigned long long dev) {
|
||||
return (dev & 0xff) | ((unsigned int)(dev >> 12) & ~0xffU);
|
||||
}
|
||||
|
||||
static void fill_statx(struct statx *out, const struct stat *st) {
|
||||
memset(out, 0, sizeof *out);
|
||||
out->stx_mask = STATX_BASIC_STATS;
|
||||
out->stx_blksize = st->st_blksize;
|
||||
out->stx_nlink = st->st_nlink;
|
||||
out->stx_uid = st->st_uid;
|
||||
out->stx_gid = st->st_gid;
|
||||
out->stx_mode = st->st_mode;
|
||||
out->stx_ino = st->st_ino;
|
||||
out->stx_size = st->st_size;
|
||||
out->stx_blocks = st->st_blocks;
|
||||
out->stx_atime.tv_sec = st->st_atim.tv_sec;
|
||||
out->stx_atime.tv_nsec = st->st_atim.tv_nsec;
|
||||
out->stx_ctime.tv_sec = st->st_ctim.tv_sec;
|
||||
out->stx_ctime.tv_nsec = st->st_ctim.tv_nsec;
|
||||
out->stx_mtime.tv_sec = st->st_mtim.tv_sec;
|
||||
out->stx_mtime.tv_nsec = st->st_mtim.tv_nsec;
|
||||
out->stx_rdev_major = dev_major(st->st_rdev);
|
||||
out->stx_rdev_minor = dev_minor(st->st_rdev);
|
||||
out->stx_dev_major = dev_major(st->st_dev);
|
||||
out->stx_dev_minor = dev_minor(st->st_dev);
|
||||
}
|
||||
|
||||
/* Emulate statx on older kernels < 4.11 */
|
||||
static long statx_call(int dirfd, const char *path, int flags, unsigned mask, struct statx *out) {
|
||||
struct stat st;
|
||||
long rs;
|
||||
if ((flags & ~(AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_STATX_SYNC_TYPE)) ||
|
||||
(flags & AT_STATX_SYNC_TYPE) == AT_STATX_SYNC_TYPE)
|
||||
return -EINVAL;
|
||||
if (!statx_missing) {
|
||||
rs = sc(SYS_statx, dirfd, (long)path, flags, mask, (long)out);
|
||||
if (rs != -ENOSYS) return rs;
|
||||
statx_missing = 1;
|
||||
}
|
||||
if (flags & AT_STATX_SYNC_TYPE) return -ENOSYS;
|
||||
rs = sc(SYS_newfstatat, dirfd, (long)path, (long)&st,
|
||||
flags & (AT_EMPTY_PATH | AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT), 0);
|
||||
if (rs < 0) return rs;
|
||||
fill_statx(out, &st);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int statx(int dirfd, const char *path, int flags, unsigned mask, struct statx *out) {
|
||||
REAL(statx, int (*)(int, const char *, int, unsigned, struct statx *));
|
||||
struct res r;
|
||||
long rs;
|
||||
if (mask & STATX__RESERVED) { errno = EINVAL; return -1; }
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wnonnull-compare"
|
||||
if (!out) { errno = EFAULT; return -1; }
|
||||
if (!path) {
|
||||
if (!(flags & AT_EMPTY_PATH)) { errno = EFAULT; return -1; }
|
||||
return real_statx ? real_statx(dirfd, path, flags, mask, out) : ret(sc(SYS_statx, dirfd, (long)path, flags, mask, (long)out));
|
||||
}
|
||||
#pragma GCC diagnostic pop
|
||||
if ((flags & AT_EMPTY_PATH) && !path[0] && fp_ready()) {
|
||||
hits++;
|
||||
return ret(sc(SYS_statx, dirfd, (long)"", flags, mask, (long)out));
|
||||
return ret(statx_call(dirfd, "", flags, mask, out));
|
||||
}
|
||||
rs = (flags & ~(AT_SYMLINK_NOFOLLOW | AT_NO_AUTOMOUNT | AT_STATX_SYNC_TYPE)) ? FP_SLOW
|
||||
: resolve(dirfd, path, (flags & AT_SYMLINK_NOFOLLOW ? 0 : 1) | MAY_BE_UNSEEN, &r);
|
||||
if (rs == 1) rs = -ENOENT;
|
||||
if (rs == 0 || rs == UNSEEN)
|
||||
rs = sc(SYS_statx, AT_FDCWD, (long)r.host, flags | (rs == 0 && !r.magic ? AT_SYMLINK_NOFOLLOW : 0), mask, (long)out);
|
||||
rs = statx_call(AT_FDCWD, r.host, flags | (rs == 0 && !r.magic ? AT_SYMLINK_NOFOLLOW : 0), mask, out);
|
||||
ANSWER(rs, dirfd, path, real_statx(dirfd, path, flags, mask, out));
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
--- a/src/syscall/syscall.c
|
||||
+++ b/src/syscall/syscall.c
|
||||
@@ -32,6 +32,7 @@
|
||||
#include "tracee/reg.h"
|
||||
#include "tracee/mem.h"
|
||||
#include "cli/note.h"
|
||||
+#include "syscall/profile.h"
|
||||
|
||||
/**
|
||||
* Copy in @path a C string (PATH_MAX bytes max.) from the @tracee's
|
||||
@@ -100,7 +101,7 @@
|
||||
return set_sysarg_data(tracee, path, strlen(path) + 1, reg);
|
||||
}
|
||||
|
||||
-void translate_syscall(Tracee *tracee)
|
||||
+static void translate_syscall_impl(Tracee *tracee)
|
||||
{
|
||||
const bool is_enter_stage = IS_IN_SYSENTER(tracee);
|
||||
int status;
|
||||
@@ -283,3 +284,18 @@
|
||||
else
|
||||
print_current_regs(tracee, 4, "sysexit end");
|
||||
}
|
||||
+
|
||||
+void translate_syscall(Tracee *tracee)
|
||||
+{
|
||||
+ if (!dd_profile_enabled()) {
|
||||
+ translate_syscall_impl(tracee);
|
||||
+ return;
|
||||
+ }
|
||||
+ int saved = errno;
|
||||
+ const bool entering = IS_IN_SYSENTER(tracee);
|
||||
+ uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
+ uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
+ errno = saved;
|
||||
+ translate_syscall_impl(tracee);
|
||||
+ dd_profile_record(get_sysnum(tracee, ORIGINAL), entering, tracee->pid, wall, cpu);
|
||||
+}
|
||||
@@ -0,0 +1,99 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#ifndef DROIDDECK_PROOT_PROFILE_H
|
||||
#define DROIDDECK_PROOT_PROFILE_H
|
||||
|
||||
#include <errno.h>
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct dd_profile_counter {
|
||||
uint64_t calls, wall_ns, cpu_ns, max_ns;
|
||||
};
|
||||
static struct dd_profile_counter dd_profile_counts[PR_NB_SYSNUM][2];
|
||||
static int dd_profile_on = -1;
|
||||
static uint64_t dd_profile_id, dd_profile_next, dd_profile_slow_ns = 1000000;
|
||||
static unsigned dd_profile_samples;
|
||||
|
||||
static uint64_t dd_profile_clock(clockid_t clock)
|
||||
{
|
||||
struct timespec ts;
|
||||
if (clock_gettime(clock, &ts) != 0) return 0;
|
||||
return (uint64_t)ts.tv_sec * 1000000000 + ts.tv_nsec;
|
||||
}
|
||||
|
||||
static void dd_profile_flush(void)
|
||||
{
|
||||
int saved = errno;
|
||||
for (unsigned nr = 0; nr < PR_NB_SYSNUM; nr++) {
|
||||
for (unsigned stage = 0; stage < 2; stage++) {
|
||||
const struct dd_profile_counter *c = &dd_profile_counts[nr][stage];
|
||||
if (!c->calls) continue;
|
||||
fprintf(stderr, "proot-profile {\"type\":\"total\",\"tracer\":%d,\"id\":%" PRIu64
|
||||
",\"syscall\":\"%s\",\"stage\":\"%s\",\"calls\":%" PRIu64
|
||||
",\"wall_ns\":%" PRIu64 ",\"cpu_ns\":%" PRIu64 ",\"max_ns\":%" PRIu64 "}\n",
|
||||
getpid(), dd_profile_id, stringify_sysnum(nr), stage ? "exit" : "enter",
|
||||
c->calls, c->wall_ns, c->cpu_ns, c->max_ns);
|
||||
}
|
||||
}
|
||||
errno = saved;
|
||||
}
|
||||
|
||||
static int dd_profile_enabled(void)
|
||||
{
|
||||
if (dd_profile_on >= 0) return dd_profile_on;
|
||||
int saved = errno;
|
||||
const char *value = getenv("PROOT_PROFILE");
|
||||
dd_profile_on = value && strcmp(value, "1") == 0;
|
||||
if (dd_profile_on) {
|
||||
value = getenv("PROOT_PROFILE_SLOW_US");
|
||||
if (value && *value) {
|
||||
char *end;
|
||||
unsigned long long us = strtoull(value, &end, 10);
|
||||
if (!*end && us > 0 && us <= 1000000000ULL) dd_profile_slow_ns = us * 1000;
|
||||
}
|
||||
dd_profile_id = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
dd_profile_next = dd_profile_id + 5000000000ULL;
|
||||
atexit(dd_profile_flush);
|
||||
fprintf(stderr, "proot-profile {\"type\":\"start\",\"tracer\":%d,\"id\":%" PRIu64
|
||||
",\"slow_ns\":%" PRIu64 ",\"sample_limit\":32,\"sample_window_ms\":5000,\"scope\":\"syscall-handler\"}\n",
|
||||
getpid(), dd_profile_id, dd_profile_slow_ns);
|
||||
}
|
||||
errno = saved;
|
||||
return dd_profile_on;
|
||||
}
|
||||
|
||||
static void dd_profile_record(unsigned nr, int entering, pid_t pid,
|
||||
uint64_t start_wall, uint64_t start_cpu)
|
||||
{
|
||||
int saved = errno;
|
||||
uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
if (nr >= PR_NB_SYSNUM) nr = PR_void;
|
||||
if (!start_wall || !start_cpu || wall < start_wall || cpu < start_cpu) goto done;
|
||||
uint64_t elapsed = wall - start_wall, used = cpu - start_cpu;
|
||||
struct dd_profile_counter *c = &dd_profile_counts[nr][!entering];
|
||||
c->calls++;
|
||||
c->wall_ns += elapsed;
|
||||
c->cpu_ns += used;
|
||||
if (elapsed > c->max_ns) c->max_ns = elapsed;
|
||||
if (wall >= dd_profile_next) {
|
||||
dd_profile_flush();
|
||||
dd_profile_next = wall + 5000000000ULL;
|
||||
dd_profile_samples = 0;
|
||||
}
|
||||
if (elapsed >= dd_profile_slow_ns && dd_profile_samples < 32) {
|
||||
dd_profile_samples++;
|
||||
fprintf(stderr, "proot-profile {\"type\":\"slow\",\"tracer\":%d,\"id\":%" PRIu64
|
||||
",\"pid\":%d,\"syscall\":\"%s\",\"stage\":\"%s\",\"wall_ns\":%" PRIu64
|
||||
",\"cpu_ns\":%" PRIu64 "}\n", getpid(), dd_profile_id, pid,
|
||||
stringify_sysnum(nr), entering ? "enter" : "exit", elapsed, used);
|
||||
}
|
||||
done:
|
||||
errno = saved;
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,56 @@
|
||||
"""Read cumulative PRoot handler counters from a session log without double counting snapshots."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
from collections import deque
|
||||
from pathlib import Path
|
||||
|
||||
PREFIX = "proot-profile "
|
||||
|
||||
|
||||
def report(path: Path, sort: str = "wall", limit: int = 20) -> dict:
|
||||
latest = {}
|
||||
starts = set()
|
||||
samples = deque(maxlen=128)
|
||||
malformed = 0
|
||||
with path.open(errors="replace") as stream:
|
||||
for line in stream:
|
||||
if PREFIX not in line:
|
||||
continue
|
||||
try:
|
||||
row = json.loads(line.split(PREFIX, 1)[1])
|
||||
identity = (int(row["tracer"]), int(row["id"]))
|
||||
if row["type"] == "start":
|
||||
starts.add(identity)
|
||||
elif row["type"] in {"total", "slow"}:
|
||||
if row["stage"] not in {"enter", "exit"} or not isinstance(row["syscall"], str):
|
||||
raise ValueError("invalid syscall/stage")
|
||||
fields = ("calls", "wall_ns", "cpu_ns", "max_ns") if row["type"] == "total" else ("wall_ns", "cpu_ns", "pid")
|
||||
if any(type(row[key]) is not int or row[key] < 0 for key in fields):
|
||||
raise ValueError("invalid counter")
|
||||
if row["type"] == "total":
|
||||
latest[identity + (row["syscall"], row["stage"])] = row
|
||||
else:
|
||||
samples.append(row)
|
||||
except (ValueError, TypeError, KeyError):
|
||||
malformed += 1
|
||||
groups = {}
|
||||
for (_, _, syscall, stage), row in latest.items():
|
||||
total = groups.setdefault((syscall, stage), dict(syscall=syscall, stage=stage, calls=0, wall_ns=0, cpu_ns=0, max_ns=0))
|
||||
for key in ("calls", "wall_ns", "cpu_ns"):
|
||||
total[key] += row[key]
|
||||
total["max_ns"] = max(total["max_ns"], row["max_ns"])
|
||||
for row in groups.values():
|
||||
row["wallMs"] = round(row["wall_ns"] / 1_000_000, 3)
|
||||
row["cpuMs"] = round(row["cpu_ns"] / 1_000_000, 3)
|
||||
row["meanUs"] = round(row["wall_ns"] / max(row["calls"], 1) / 1000, 3)
|
||||
row["maxUs"] = round(row["max_ns"] / 1000, 3)
|
||||
rows = sorted(groups.values(), key=lambda row: row[{"wall": "wall_ns", "cpu": "cpu_ns", "calls": "calls"}[sort]], reverse=True)
|
||||
return dict(ok=True, command="proot-profile", scope="syscall-handler",
|
||||
note="Handler wall time includes tracer descheduling and filesystem waits; it excludes tracee kernel time and wake-up/queue delay before the handler. Counts are handler visits, including chained calls, not unique syscalls.",
|
||||
path=str(path), tracers=len(starts | {key[:2] for key in latest}),
|
||||
handlerCalls=sum(row["calls"] for row in rows),
|
||||
handlerWallNs=sum(row["wall_ns"] for row in rows),
|
||||
handlerCpuNs=sum(row["cpu_ns"] for row in rows),
|
||||
malformedRecords=malformed, totals=rows[:limit], slowSamples=list(samples),
|
||||
hasCounters=bool(latest))
|
||||
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
if [ -z "$WEBHOOK" ]; then
|
||||
echo "::notice::No DISCORD_BUILDS_WEBHOOK secret; nothing posted"
|
||||
exit 0
|
||||
fi
|
||||
commit=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA")
|
||||
subject=$(jq -r '.commit.message | split("\n")[0]' <<<"$commit")
|
||||
title=$(jq -r '.commit.message | split("\n") | map(select(length > 0)) | .[1] // ""' <<<"$commit")
|
||||
pr=$(sed -n 's/^Merge pull request #\([0-9]*\).*/\1/p' <<<"$subject")
|
||||
if [ -n "$pr" ]; then
|
||||
what="[#$pr]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$pr): ${title:-$subject}"
|
||||
else
|
||||
what="[\`${GITHUB_SHA::7}\`]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA): $subject"
|
||||
fi
|
||||
get=$(printf 'Download: [standard APK](<%s>) · [all variants](<%s>)' "$APK" "$RELEASE")
|
||||
content=$(printf '**New signed Preview build** `main-%s`\n%s\nIn the app: **Updates → Preview**\n%s' "${GITHUB_SHA::7}" "$what" "$get")
|
||||
jq -n --arg content "$content" '{content: $content, allowed_mentions: {parse: []}}' |
|
||||
curl -fsS -H 'Content-Type: application/json' -d @- "$WEBHOOK" -o /dev/null
|
||||
echo "Posted: $content"
|
||||
@@ -0,0 +1,22 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
pr=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA/pulls" \
|
||||
--jq '[.[] | select(.merged_at != null and .base.ref == "main")] | first // empty')
|
||||
if [ -n "$pr" ]; then
|
||||
number=$(jq -r .number <<<"$pr")
|
||||
title=$(jq -r .title <<<"$pr")
|
||||
merged=$(jq -r '.merged_at[:10]' <<<"$pr")
|
||||
summary=$(jq -r '.body // ""' <<<"$pr" | tr -d '\r' | { grep -v '^🤖' || true; } |
|
||||
awk '!p && /^#/ { next } NF { p = 1; print; next } p { exit }' | head -n 6 | cut -c1-400)
|
||||
{
|
||||
echo "**Merged to main** - [PR #$number]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/pull/$number): $title (merged $merged)"
|
||||
if [ -n "$summary" ]; then
|
||||
echo
|
||||
echo "$summary"
|
||||
fi
|
||||
} > notes-head.md
|
||||
else
|
||||
subject=$(gh api "repos/$GITHUB_REPOSITORY/commits/$GITHUB_SHA" --jq '.commit.message | split("\n")[0]')
|
||||
echo "**Pushed to main** without a PR - $subject" > notes-head.md
|
||||
fi
|
||||
cat notes-head.md
|
||||
@@ -0,0 +1,39 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
tag=main-${GITHUB_SHA::7}
|
||||
cat signed/SHA256SUMS-*.txt > signed/SHA256SUMS.txt
|
||||
rm signed/SHA256SUMS-*.txt
|
||||
notes="$(cat notes-head.md)
|
||||
|
||||
Signed build of $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/commit/$GITHUB_SHA - in main, not yet in a DroidDeck release; for testing.
|
||||
Commit: $GITHUB_SHA
|
||||
VersionCode: $(sed -n 's/^ *versionCode \([0-9][0-9]*\)$/\1/p' app/build.gradle)
|
||||
Each apk installs over a DroidDeck release and keeps its data. \`standard\` is the normal app; the others are the same app under another package name, installed beside it.
|
||||
|
||||
SHA-256:
|
||||
\`\`\`
|
||||
$(cat signed/SHA256SUMS.txt)
|
||||
\`\`\`"
|
||||
gh release delete "$tag" -R "$CI_REPO" --yes --cleanup-tag 2>/dev/null || true
|
||||
gh release create "$tag" -R "$CI_REPO" --target main --prerelease \
|
||||
--title "main ${GITHUB_SHA::7}" --notes "$notes" signed/*
|
||||
gh release list -R "$CI_REPO" -L 200 --json tagName,publishedAt \
|
||||
--jq '[.[] | select(.tagName | startswith("main-"))] | sort_by(.publishedAt) | reverse | .['"$KEEP"':][] | .tagName' |
|
||||
while IFS= read -r old; do
|
||||
if [ "$old" = "$tag" ]; then
|
||||
continue
|
||||
fi
|
||||
if ! gh release delete "$old" -R "$CI_REPO" --yes --cleanup-tag 2>/dev/null; then
|
||||
if gh release view "$old" -R "$CI_REPO" >/dev/null 2>&1; then
|
||||
echo "::error::Could not delete old release $old"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
done
|
||||
published=$(gh release view "$tag" -R "$CI_REPO" --json tagName,assets)
|
||||
jq -e --arg tag "$tag" '.tagName == $tag and (.assets | length) > 0' <<< "$published" >/dev/null
|
||||
url="$GITHUB_SERVER_URL/$CI_REPO/releases/tag/$tag"
|
||||
apk=$(cd signed && ls DroidDeck-*.apk | awk 'length(a) == 0 || length($0) < length(a) { a = $0 } END { print a }')
|
||||
echo "release=$url" >> "$GITHUB_OUTPUT"
|
||||
echo "apk=$GITHUB_SERVER_URL/$CI_REPO/releases/download/$tag/$apk" >> "$GITHUB_OUTPUT"
|
||||
echo "Published $url"
|
||||
@@ -0,0 +1,77 @@
|
||||
#!/usr/bin/env bash
|
||||
set -uo pipefail
|
||||
MARK="<!-- droiddeck-pr-build -->"
|
||||
{
|
||||
echo "$MARK"
|
||||
echo "## Build of this pull request"
|
||||
echo
|
||||
[ -f /tmp/pr-merge.md ] && cat /tmp/pr-merge.md
|
||||
echo
|
||||
case "$BUILD_OUTCOME:$UNIT_TEST_OUTCOME:$APK_OUTCOME" in
|
||||
success:success:success)
|
||||
echo "### Build passed"
|
||||
echo
|
||||
echo "The \`droiddeck-apk\` artifact is [on this run]($RUN_URL), signed with the public test key."
|
||||
echo
|
||||
if [ "$SAME_REPO" = true ]; then
|
||||
echo "After the parallel regression tests pass, a release-signed tester build that installs over Stable or Preview will be published and will appear in DroidDeck's **Test builds** list. Label the PR \`no-test-build\` to skip that."
|
||||
else
|
||||
echo "**Maintainer:** add the \`publish-test\` label to publish a release-signed tester build that installs over Stable or Preview and appears in DroidDeck's **Test builds** list. The label is removed automatically after publishing."
|
||||
fi
|
||||
echo
|
||||
echo "Fallback: [open **PR Release Publish**]($GITHUB_SERVER_URL/$GITHUB_REPOSITORY/actions/workflows/pr-release-publish.yml) on \`main\` and enter PR \`$PR\`."
|
||||
;;
|
||||
success:success:*)
|
||||
echo "### APK publication incomplete"
|
||||
echo
|
||||
echo "Compilation and unit tests passed, but APK publication did not complete. See [the run]($RUN_URL)."
|
||||
;;
|
||||
success:failure:*)
|
||||
echo "### ERROR: Unit tests failed"
|
||||
echo
|
||||
echo "The APK compiled, but unit tests failed. No installable artifact was published."
|
||||
echo
|
||||
if [ -n "$TEST_DIAGNOSTICS_URL" ]; then
|
||||
echo "The [unit-test-results]($TEST_DIAGNOSTICS_URL) artifact contains the test log and any generated reports."
|
||||
else
|
||||
echo "The test diagnostics upload did not complete. See [the test log]($RUN_URL)."
|
||||
fi
|
||||
;;
|
||||
success:*)
|
||||
echo "### Build incomplete"
|
||||
echo
|
||||
echo "The APK compiled, but unit tests did not complete successfully. See [the run]($RUN_URL)."
|
||||
;;
|
||||
failure:*)
|
||||
echo "### ERROR: Build failed"
|
||||
echo
|
||||
echo "The compiler's errors ([full log]($RUN_URL)):"
|
||||
echo
|
||||
echo '```'
|
||||
{ grep -E '^e: |^w: .*error|error:|CMake Error|fatal error|ninja: error|FAILED|What went wrong|Execution failed for task|Unresolved reference|Type mismatch|Unresolved' /tmp/build.log 2>/dev/null \
|
||||
| sed -e 's#file:///home/runner/work/[^/]*/[^/]*/##' -e 's#/home/runner/work/[^/]*/[^/]*/##' \
|
||||
| grep -v '^w: ' | awk '!seen[$0]++' | head -80; } || true
|
||||
echo '```'
|
||||
echo
|
||||
echo "<details><summary>What went wrong (Gradle)</summary>"
|
||||
echo
|
||||
echo '```'
|
||||
awk '/^\* What went wrong/{p=1} /^\* Try:/{p=0} p{print}' /tmp/build.log 2>/dev/null | head -60
|
||||
echo '```'
|
||||
echo "</details>"
|
||||
;;
|
||||
skipped:*|cancelled:*)
|
||||
echo "### Not built"
|
||||
echo
|
||||
echo "The build did not run (see above, or [the run]($RUN_URL))."
|
||||
;;
|
||||
esac
|
||||
echo
|
||||
} > /tmp/pr-report.md
|
||||
cat /tmp/pr-report.md >> "$GITHUB_STEP_SUMMARY"
|
||||
ID=$(gh api "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" --paginate --jq ".[] | select(.user.login == \"github-actions[bot]\" and (.body | startswith(\"$MARK\"))) | .id" | head -1 || true)
|
||||
if [ -n "$ID" ]; then
|
||||
gh api -X PATCH "repos/${GITHUB_REPOSITORY}/issues/comments/${ID}" -F body=@/tmp/pr-report.md >/dev/null
|
||||
else
|
||||
gh api -X POST "repos/${GITHUB_REPOSITORY}/issues/${PR}/comments" -F body=@/tmp/pr-report.md >/dev/null
|
||||
fi
|
||||
@@ -21,9 +21,9 @@ PACKED_FILES = {'lib/arm64-v8a/libproot.so': ('proot', 'libproot.so'),
|
||||
PACKED_LIBRARIES = ['lib/arm64-v8a/libopencv_java4.so', 'lib/arm64-v8a/libmediapipe_tasks_jni.so']
|
||||
PACK_NAMES = ['proot', 'directaudio', 'tracking', 'xbox', 'comet']
|
||||
SOURCE_PATHS = ['app/build.gradle', 'app/src/main/cpp/fakeinput_steam.cpp', 'app/src/main/assets/pulseaudio.tzst',
|
||||
'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio',
|
||||
'tools/linuxfs', 'tools/proot', 'tools/aaudio-sink', 'tools/directaudio', 'tools/packs',
|
||||
'tools/gamescope/release.env', 'tools/droiddeck-esync/release.env',
|
||||
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/build_local.sh',
|
||||
'tools/mangoapp', 'tools/msitools', 'tools/pipewire', 'tools/comet', 'tools/xbox', 'tools/components', 'tools/ci', 'tools/build_local.sh',
|
||||
'tools/release/runtime_inputs.py', 'app/src/main/assets/desktop-removal',
|
||||
'tools/quest', 'tools/vr/src', 'tools/vr/driver_droiddeck', 'tools/vr/layer', 'tools/vr/build.sh',
|
||||
'app/src/main/cpp/waylandcomp/src/headpose_shm.h',
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,95 @@
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shlex
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class CiChecksTest(unittest.TestCase):
|
||||
def test_pr_cache_writes_and_source_timestamp_policy(self):
|
||||
jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs']
|
||||
cache = next(step for step in jobs['build']['steps']
|
||||
if step.get('uses') == 'gradle/actions/setup-gradle@v4')['with']
|
||||
self.assertEqual(cache['cache-read-only'],
|
||||
"${{ github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name != github.repository }}")
|
||||
gradle = (ROOT / 'app/build.gradle').read_text()
|
||||
self.assertIn("gitValue(['show', '-s', '--format=%ct', '--end-of-options', sourceCommit])", gradle)
|
||||
|
||||
def test_report_comment_lookup_ignores_human_marker(self):
|
||||
if not shutil.which('jq'):
|
||||
self.skipTest('jq required to execute comment selection')
|
||||
script = (ROOT / 'tools/release/report-build.sh').read_text()
|
||||
line = next(line for line in script.splitlines() if line.startswith('ID='))
|
||||
arguments = shlex.split(line[len('ID=$('):].split(' | head', 1)[0])
|
||||
query = arguments[arguments.index('--jq') + 1].replace('$MARK', '<!-- build -->')
|
||||
comments = [dict(id=1, user=dict(login='someone'), body='<!-- build --> forged'),
|
||||
dict(id=2, user=dict(login='github-actions[bot]'), body='<!-- build --> result')]
|
||||
result = subprocess.check_output(['jq', '-r', query], input=json.dumps(comments), text=True)
|
||||
self.assertEqual(result.strip(), '2')
|
||||
|
||||
def test_build_and_tests_use_identical_generated_metadata(self):
|
||||
jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs']
|
||||
steps = {step.get('id'): step for step in jobs['build']['steps']}
|
||||
self.assertEqual(steps['build']['env'], steps['unit-tests']['env'])
|
||||
self.assertIn('DROIDDECK_BUILD_LABEL', steps['unit-tests']['env'])
|
||||
self.assertIn('SGDB_API_KEY', steps['unit-tests']['env'])
|
||||
gradle = (ROOT / 'app/build.gradle').read_text()
|
||||
self.assertIn("outputs.doNotCacheIf('CI executes the test suite on every run') { true }", gradle)
|
||||
self.assertIn('outputs.upToDateWhen { false }', gradle)
|
||||
|
||||
def test_independent_jobs_wait_only_for_the_pinned_source(self):
|
||||
jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs']
|
||||
for name in ('xbox', 'components', 'python-tests'):
|
||||
self.assertEqual(jobs[name]['needs'], 'source')
|
||||
self.assertEqual(set(jobs['build']['needs']), {'source', 'components', 'xbox'})
|
||||
|
||||
def test_dependency_update_errors_block_installation(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
sudo = root / 'sudo'
|
||||
sudo.write_text('#!/bin/bash\nprintf "%s\\n" "$*" >> "$APT_LOG"\nexit "${APT_RESULT:-0}"\n')
|
||||
sudo.chmod(0o755)
|
||||
query = root / 'dpkg-query'
|
||||
query.write_text('#!/bin/sh\nexit 1\n')
|
||||
query.chmod(0o755)
|
||||
log = root / 'apt.log'
|
||||
env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'], APT_LOG=str(log))
|
||||
installer = ROOT / 'tools/ci/install-ubuntu-packages.sh'
|
||||
result = subprocess.run(['bash', str(installer), 'qemu-user'], env=dict(env, APT_RESULT='17'))
|
||||
self.assertEqual(result.returncode, 17)
|
||||
self.assertEqual(len(log.read_text().splitlines()), 2)
|
||||
log.unlink()
|
||||
subprocess.run(['bash', str(installer), 'qemu-user'], env=env, check=True)
|
||||
update, install = log.read_text().splitlines()
|
||||
for command in (update, install):
|
||||
self.assertIn('Dir::Etc::sourceparts=-', command)
|
||||
self.assertIn('Acquire::https::Timeout=15', command)
|
||||
self.assertIn('Acquire::Retries=1', command)
|
||||
self.assertIn('APT::Update::Error-Mode=any', update)
|
||||
self.assertIn('install -y -q --no-install-recommends qemu-user', install)
|
||||
|
||||
def test_required_status_rejects_failed_cancelled_or_skipped_test_jobs(self):
|
||||
jobs = yaml.safe_load((ROOT / '.github/workflows/build.yml').read_text())['jobs']
|
||||
gate = jobs['checks']
|
||||
self.assertEqual(gate['name'], 'Compile and test APK')
|
||||
self.assertEqual(set(gate['needs']), {'build', 'python-tests'})
|
||||
self.assertIn('always()', gate['if'])
|
||||
for build, python in itertools.product(('success', 'failure', 'cancelled', 'skipped'), repeat=2):
|
||||
with self.subTest(build=build, python=python):
|
||||
result = subprocess.run(
|
||||
['bash', '-c', gate['steps'][0]['run']],
|
||||
env=dict(os.environ, BUILD_RESULT=build, PYTHON_RESULT=python),
|
||||
capture_output=True)
|
||||
self.assertEqual(result.returncode == 0, build == python == 'success')
|
||||
for publisher in ('sign', 'packs'):
|
||||
self.assertIn('checks', jobs[publisher]['needs'])
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class CiNdkTest(unittest.TestCase):
|
||||
def test_installed_ndk_must_match_the_declared_version(self):
|
||||
version = (ROOT / 'tools/ci/toolchains.env').read_text().strip().split('=', 1)[1]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
ndk = root / 'ndk' / version
|
||||
ndk.mkdir(parents=True)
|
||||
properties = ndk / 'source.properties'
|
||||
properties.write_text('Pkg.Revision = ' + version + '\n')
|
||||
output = root / 'environment'
|
||||
env = dict(os.environ, ANDROID_HOME=str(root), GITHUB_ENV=str(output))
|
||||
script = ROOT / 'tools/ci/resolve-ndk.sh'
|
||||
subprocess.run(['bash', str(script)], env=env, check=True)
|
||||
self.assertIn('NDK_VERSION=' + version, output.read_text())
|
||||
self.assertIn('ANDROID_NDK_HOME=' + str(ndk), output.read_text())
|
||||
properties.write_text('Pkg.Revision = unexpected\n')
|
||||
self.assertNotEqual(subprocess.run(['bash', str(script)], env=env).returncode, 0)
|
||||
@@ -0,0 +1,106 @@
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
SPEC = importlib.util.spec_from_file_location('component_prepare', Path(__file__).resolve().parents[1] / 'components/prepare.py')
|
||||
components = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(components)
|
||||
|
||||
|
||||
class ComponentPrepareTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
self.root = Path(directory.name)
|
||||
self.fixture(self.root)
|
||||
|
||||
def fixture(self, root):
|
||||
for name in components.TREES:
|
||||
(root / name).mkdir(parents=True)
|
||||
(root / 'tools/components/recipes').mkdir(parents=True)
|
||||
(root / 'input.h').write_text('#define VALUE 1\n')
|
||||
(root / 'tools/components/recipes/fake.sh').write_text('printf binary > app/src/main/assets/linuxfs/demo.so\n')
|
||||
spec = dict(script='tools/components/recipes/fake.sh', inputs=['input.h', 'tools/components/recipes/fake.sh'],
|
||||
outputs=['app/src/main/assets/linuxfs/demo.so'])
|
||||
(root / components.REGISTRY).write_text(json.dumps(dict(fake=spec)))
|
||||
for name in components.LIBRARIES:
|
||||
(root / name).parent.mkdir(parents=True, exist_ok=True)
|
||||
(root / name).write_bytes(b'library')
|
||||
subprocess.run(['git', 'init', '-q', str(root)], check=True)
|
||||
subprocess.run(['git', '-C', str(root), 'config', 'core.autocrlf', 'false'], check=True)
|
||||
subprocess.run(['git', '-C', str(root), 'add', '.'], check=True)
|
||||
subprocess.run(['git', '-C', str(root), '-c', 'user.name=Test Developer', '-c', 'user.email=test@example.test',
|
||||
'commit', '-qm', 'baseline'], check=True)
|
||||
|
||||
def test_recipe_failure_or_missing_output_does_not_succeed(self):
|
||||
script = self.root / 'tools/components/recipes/fake.sh'
|
||||
script.write_text('exit 7\n')
|
||||
with self.assertRaises(subprocess.CalledProcessError):
|
||||
components.prepare('fake', self.root)
|
||||
script.write_text('exit 0\n')
|
||||
with self.assertRaisesRegex(ValueError, 'required outputs'):
|
||||
components.prepare('fake', self.root)
|
||||
|
||||
def test_identity_covers_source_and_recipe_changes(self):
|
||||
original = components.identity('fake', self.root)
|
||||
(self.root / 'input.h').write_text('#define VALUE 2\n')
|
||||
changed = components.identity('fake', self.root)
|
||||
self.assertNotEqual(original, changed)
|
||||
script = self.root / 'tools/components/recipes/fake.sh'
|
||||
script.write_text(script.read_text() + '\nprintf changed\n')
|
||||
self.assertNotEqual(changed, components.identity('fake', self.root))
|
||||
|
||||
def test_tool_requirements_are_installed_in_one_union(self):
|
||||
definitions = dict(one=dict(packages=['gcc', 'cmake']), two=dict(packages=['gcc', 'qemu-user']))
|
||||
with patch.object(components, 'registry', return_value=definitions), patch.object(components.subprocess, 'run') as run:
|
||||
components.prepare_tools(['one', 'two'], self.root)
|
||||
run.assert_called_once_with(['bash', 'tools/ci/install-ubuntu-packages.sh', 'cmake', 'gcc', 'qemu-user'],
|
||||
cwd=self.root, check=True)
|
||||
|
||||
def test_prepared_handoff_verifies_every_file_and_source_tree(self):
|
||||
components.prepare('fake', self.root)
|
||||
archive = self.root / 'prepared.tar.gz'
|
||||
components.pack(archive, self.root)
|
||||
tree = subprocess.check_output(['git', 'rev-parse', 'HEAD^{tree}'], cwd=self.root, text=True).strip()
|
||||
target = self.root / 'target'
|
||||
self.fixture(target)
|
||||
components.unpack(archive, tree, target)
|
||||
self.assertEqual((target / 'app/src/main/assets/linuxfs/demo.so').read_bytes(), b'binary')
|
||||
with self.assertRaisesRegex(ValueError, 'pinned source'):
|
||||
components.unpack(archive, 'wrong-tree', target)
|
||||
|
||||
def test_tampered_component_bytes_fail_handoff_verification(self):
|
||||
components.prepare('fake', self.root)
|
||||
archive = self.root / 'prepared.tar.gz'
|
||||
components.pack(archive, self.root)
|
||||
corrupt = self.root / 'corrupt.tar.gz'
|
||||
with tarfile.open(archive) as original, tarfile.open(corrupt, 'w:gz') as output:
|
||||
for entry in original:
|
||||
content = original.extractfile(entry).read()
|
||||
if entry.name.endswith('demo.so'):
|
||||
content = b'tampered'
|
||||
entry.size = len(content)
|
||||
output.addfile(entry, io.BytesIO(content))
|
||||
target = self.root / 'target'
|
||||
self.fixture(target)
|
||||
tree = subprocess.check_output(['git', 'rev-parse', 'HEAD^{tree}'], cwd=self.root, text=True).strip()
|
||||
with self.assertRaisesRegex(ValueError, 'file hashes'):
|
||||
components.unpack(corrupt, tree, target)
|
||||
|
||||
def test_archive_cannot_overwrite_source_through_traversal(self):
|
||||
archive = self.root / 'bad.tar.gz'
|
||||
with tarfile.open(archive, mode='w:gz') as tar:
|
||||
name = 'app/src/main/assets/linuxfs/../../../../../input.h'
|
||||
entry = tarfile.TarInfo(name)
|
||||
entry.size = 3
|
||||
tar.addfile(entry, io.BytesIO(b'bad'))
|
||||
with self.assertRaisesRegex(ValueError, 'Unsafe'):
|
||||
components.unpack(archive, 'tree', self.root)
|
||||
self.assertEqual((self.root / 'input.h').read_text(), '#define VALUE 1\n')
|
||||
@@ -456,6 +456,15 @@ class ProtonRunTest(Temp):
|
||||
("0", "0", str(appid << 32 | 0x02000000), "1"))
|
||||
self.assertEqual(env["STEAM_COMPAT_DATA_PATH"], str(self.root / ("steamapps/compatdata/%d" % appid)))
|
||||
|
||||
def test_a_window_draws_with_the_desktops_software_gl(self):
|
||||
target = RUN["Target"]("2596113170", "/c", "/i", str(self.root), "fixed")
|
||||
session = {"MESA_LOADER_DRIVER_OVERRIDE": "zink", "GALLIUM_DRIVER": "zink", "LIBGL_KOPPER_DRI2": "true"}
|
||||
env = RUN["environment"](session, target, "/tool", str(self.root), window=True)
|
||||
self.assertEqual((env["LIBGL_ALWAYS_SOFTWARE"], env["GALLIUM_DRIVER"]), ("1", "llvmpipe"))
|
||||
self.assertNotIn("MESA_LOADER_DRIVER_OVERRIDE", env)
|
||||
self.assertNotIn("LIBGL_KOPPER_DRI2", env)
|
||||
self.assertEqual(RUN["environment"](session, target, "/tool", str(self.root))["GALLIUM_DRIVER"], "zink")
|
||||
|
||||
def test_a_steam_game_keeps_its_own_id(self):
|
||||
target = RUN["Target"]("413150", "/c", "/i", str(self.root), "steam")
|
||||
env = RUN["environment"]({"PROTON_USE_WINED3D": "0"}, target, "/tool", str(self.root), window=True)
|
||||
@@ -465,6 +474,13 @@ class ProtonRunTest(Temp):
|
||||
self.assertEqual(RUN["arguments"]("/root/x/setup.msi", ["/qn"]), ["msiexec", "/i", "Z:\\root\\x\\setup.msi", "/qn"])
|
||||
self.assertEqual(RUN["arguments"]("/root/x/a.exe", ["-w"]), ["/root/x/a.exe", "-w"])
|
||||
|
||||
def test_a_virtual_desktop_runs_the_program_by_its_windows_path(self):
|
||||
pfx = "/root/Steam/steamapps/compatdata/2596113170"
|
||||
self.assertEqual(RUN["arguments"](pfx + "/pfx/drive_c/Program Files (x86)/Battle.net/Battle.net Launcher.exe", [], "1280x720", pfx),
|
||||
["explorer.exe", "/desktop=droiddeck,1280x720", "C:\\Program Files (x86)\\Battle.net\\Battle.net Launcher.exe"])
|
||||
self.assertEqual(RUN["arguments"]("/root/.cache/setup.exe", ["--lang=enUS"], "1920x1080", pfx),
|
||||
["explorer.exe", "/desktop=droiddeck,1920x1080", "Z:\\root\\.cache\\setup.exe", "--lang=enUS"])
|
||||
|
||||
def test_a_games_own_program_is_left_to_steam(self):
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: STARDEW}))
|
||||
self.assertEqual(RUN["compat"]()["launch_programs"](STARDEW["config"]),
|
||||
@@ -554,6 +570,50 @@ class ProtonRunTest(Temp):
|
||||
self.game("70", "Linux Game", "run.sh")
|
||||
self.assertEqual(self.run_main(["--app", "70"])[0], 2)
|
||||
|
||||
def test_without_steam_a_shortcut_reuses_a_signed_prefix_folder(self):
|
||||
bat = self.write("Games/Epic/Game/.droiddeck-launch.bat", b"@echo off")
|
||||
start = self.tmp / "Games/Epic/Game/Binaries"
|
||||
start.mkdir()
|
||||
signed = self.root / "steamapps/compatdata/-1561598272"
|
||||
signed.mkdir(parents=True)
|
||||
code, calls, dirs = self.run_main(["--app", "2733369024", "--dir", str(start), "--", str(bat)])
|
||||
self.assertIsNone(code)
|
||||
env = calls[0][2]
|
||||
self.assertEqual(env["STEAM_COMPAT_DATA_PATH"], str(signed))
|
||||
self.assertFalse((self.root / "steamapps/compatdata/2733369024").exists())
|
||||
|
||||
def test_prefix_folder_prefers_initialized_unsigned_over_empty_signed(self):
|
||||
signed = self.root / "steamapps/compatdata/-1561598272"
|
||||
signed.mkdir(parents=True)
|
||||
initialized = self.root / "steamapps/compatdata/2733369024/pfx"
|
||||
initialized.mkdir(parents=True)
|
||||
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024), str(initialized.parent))
|
||||
|
||||
def test_prefix_folder_prefers_initialized_signed_over_empty_unsigned(self):
|
||||
unsigned = self.root / "steamapps/compatdata/2733369024"
|
||||
unsigned.mkdir(parents=True)
|
||||
initialized = self.root / "steamapps/compatdata/-1561598272/pfx"
|
||||
initialized.mkdir(parents=True)
|
||||
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024), str(initialized.parent))
|
||||
|
||||
def test_prefix_folder_prefers_unsigned_when_initialization_ties(self):
|
||||
unsigned = self.root / "steamapps/compatdata/2733369024/pfx"
|
||||
unsigned.mkdir(parents=True)
|
||||
signed = self.root / "steamapps/compatdata/-1561598272/pfx"
|
||||
signed.mkdir(parents=True)
|
||||
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024), str(unsigned.parent))
|
||||
|
||||
def test_prefix_folder_skips_numeric_names_too_long_to_convert(self):
|
||||
from unittest.mock import patch
|
||||
folder = self.root / "steamapps/compatdata"
|
||||
folder.mkdir(parents=True)
|
||||
with patch.object(RUN["os"], "listdir", return_value=["9" * 5000]):
|
||||
self.assertEqual(RUN["prefix_folder"](str(self.root), 2733369024),
|
||||
str(folder / "2733369024"))
|
||||
|
||||
def test_without_steam_a_shortcut_keeps_its_prefix_folder_and_launch_options(self):
|
||||
bat = self.write("Games/Epic/Game/.droiddeck-launch.bat", b"@echo off")
|
||||
start = self.tmp / "Games/Epic/Game/Binaries"
|
||||
@@ -568,6 +628,43 @@ class ProtonRunTest(Temp):
|
||||
self.assertTrue((self.root / "steamapps/compatdata/2733369024").is_dir())
|
||||
self.assertEqual(dirs, [str(start)])
|
||||
|
||||
def write_account(self):
|
||||
self.write("Steam/config/loginusers.vdf",
|
||||
'"users"\n{\n\t"76561198352563669"\n\t{\n\t\t"MostRecent"\t\t"1"\n\t}\n}\n')
|
||||
return "Steam/userdata/392297941/config/"
|
||||
|
||||
def test_without_steam_and_options_a_game_takes_its_steam_launch_options(self):
|
||||
config = self.write_account()
|
||||
self.write(config + "localconfig.vdf", '"UserLocalConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n'
|
||||
'\t\t\t"Steam"\n\t\t\t{\n\t\t\t\t"apps"\n\t\t\t\t{\n\t\t\t\t\t"413150"\n\t\t\t\t\t{\n'
|
||||
'\t\t\t\t\t\t"cloud"\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t"LaunchOptions"\t\t"-wrong"\n\t\t\t\t\t\t}\n'
|
||||
'\t\t\t\t\t\t"LaunchOptions"\t\t"DXVK_HUD=1 %command% -d3d9 \\"-name=Two Words\\""\n'
|
||||
'\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n')
|
||||
shortcuts = runpy.run_path(str(BIN / "droiddeck-steam-shortcuts"))
|
||||
self.write(config + "shortcuts.vdf", shortcuts["write"]({"shortcuts": {
|
||||
"0": {"appid": -1561598272, "AppName": "Batman", "LaunchOptions": "-d3d9"},
|
||||
"1": {"appid": -1, "AppName": "Other", "LaunchOptions": "-x"},
|
||||
}}))
|
||||
root = str(self.root)
|
||||
self.assertEqual(RUN["steam_options"]("413150", root), 'DXVK_HUD=1 %command% -d3d9 "-name=Two Words"')
|
||||
self.assertEqual(RUN["steam_options"]("2733369024", root), "-d3d9")
|
||||
self.assertEqual(RUN["steam_options"]("70", root), "")
|
||||
self.assertEqual(RUN["steam_options"]("2733369025", root), "")
|
||||
info = {"common": {"type": "Game"}, "config": {"launch": {
|
||||
"0": {"executable": "Game.exe", "type": "default", "config": {"oslist": "windows"}}}}}
|
||||
self.write("Steam/appcache/appinfo.vdf", appinfo({413150: info}))
|
||||
program = self.game("413150", "Some Game", "Game.exe")
|
||||
code, calls, _ = self.run_main(["--app", "413150"])
|
||||
self.assertIsNone(code)
|
||||
_, argv, env = calls[0]
|
||||
self.assertEqual(argv[1:], ["waitforexitandrun", str(program), "-d3d9", "-name=Two Words"])
|
||||
self.assertEqual(env["DXVK_HUD"], "1")
|
||||
bat = self.write("Games/GOG/Batman/Batman.exe", b"MZ")
|
||||
code, calls, _ = self.run_main(["--app", "2733369024", "--", str(bat)])
|
||||
self.assertEqual(calls[0][1][1:], ["waitforexitandrun", str(bat), "-d3d9"])
|
||||
code, calls, _ = self.run_main(["--app", "2733369024", "--options", "", "--", str(bat)])
|
||||
self.assertEqual(calls[0][1][1:], ["waitforexitandrun", str(bat)])
|
||||
|
||||
def test_launch_options_split_like_steam_does(self):
|
||||
split = RUN["split_options"]
|
||||
self.assertEqual(split(""), ({}, []))
|
||||
|
||||
@@ -196,6 +196,63 @@ class AgentTest(unittest.TestCase):
|
||||
answer = self.ask({"kind": "vr", "action": "status"})
|
||||
self.assertEqual("UNAVAILABLE", answer["error"]["code"])
|
||||
|
||||
def fake_proc(self, pid, parent, comm, env):
|
||||
root = self.dir / "proc" / str(pid)
|
||||
root.mkdir(parents=True)
|
||||
(root / "comm").write_text(comm + "\n")
|
||||
(root / "stat").write_text("%d (%s) S %d 0 0" % (pid, comm, parent))
|
||||
(root / "environ").write_bytes(b"\0".join(b"%s=%s" % (k.encode(), v.encode()) for k, v in env.items()) + b"\0")
|
||||
|
||||
def tag(self, wins, arch="arm64"):
|
||||
snap = {"displays": {":0": [], ":1": wins}}
|
||||
with patch.dict(os.environ, {"DISPLAY": ":0", "BL_STEAM_CLIENT_ARCH": arch}), \
|
||||
patch.object(agent.subprocess, "run") as run, patch.object(agent, "log"):
|
||||
run.return_value.returncode = 0
|
||||
tagged = agent.tag_game_windows(snap, proc=self.dir / "proc")
|
||||
return tagged, [call.args[0][-1] for call in run.call_args_list]
|
||||
|
||||
def test_a_sandboxed_flatpak_window_is_tagged_with_its_shortcut(self):
|
||||
self.fake_proc(40, 1, "gjs", {"FLATPAK_ID": "com.github.tchx84.Flatseal", "SteamAppId": "2166984148"})
|
||||
win = {"window": 7, "map": "viewable", "class": "com.github.tchx84.Flatseal", "pid": None}
|
||||
self.assertEqual(self.tag([win]), (True, ["2166984148"]))
|
||||
|
||||
def test_a_flatpak_window_named_after_the_app_is_matched(self):
|
||||
self.fake_proc(40, 1, "vacuumtube", {"FLATPAK_ID": "rocks.shy.VacuumTube", "SteamAppId": "3000000001"})
|
||||
win = {"window": 7, "map": "viewable", "class": "VacuumTube", "pid": None}
|
||||
self.assertEqual(self.tag([win]), (True, ["3000000001"]))
|
||||
|
||||
def test_a_window_whose_process_has_no_app_id_falls_back_to_its_flatpak(self):
|
||||
self.fake_proc(40, 1, "bwrap", {"FLATPAK_ID": "com.github.tchx84.Flatseal", "SteamAppId": "2166984148"})
|
||||
self.fake_proc(41, 1, "gjs", {})
|
||||
win = {"window": 7, "map": "viewable", "class": "com.github.tchx84.Flatseal", "pid": 41}
|
||||
self.assertEqual(self.tag([win]), (True, ["2166984148"]))
|
||||
|
||||
def test_a_flatpak_shared_by_two_shortcuts_is_not_guessed(self):
|
||||
self.fake_proc(40, 1, "gjs", {"FLATPAK_ID": "com.github.tchx84.Flatseal", "SteamAppId": "2166984148"})
|
||||
self.fake_proc(42, 1, "gjs", {"FLATPAK_ID": "com.github.tchx84.Flatseal", "SteamAppId": "3000000003"})
|
||||
win = {"window": 7, "map": "viewable", "class": "com.github.tchx84.Flatseal", "pid": None}
|
||||
self.assertEqual(self.tag([win]), (False, []))
|
||||
|
||||
def test_a_window_outside_the_reaper_takes_its_process_app_id(self):
|
||||
self.fake_proc(30, 1, "proot", {})
|
||||
self.fake_proc(31, 30, "electron", {"SteamAppId": "3000000002"})
|
||||
win = {"window": 8, "map": "viewable", "class": "electron", "pid": 31}
|
||||
self.assertEqual(self.tag([win]), (True, ["3000000002"]))
|
||||
|
||||
def test_windows_gamescope_already_resolves_are_left_alone(self):
|
||||
self.fake_proc(20, 1, "reaper", {})
|
||||
self.fake_proc(21, 20, "game", {"SteamAppId": "413150"})
|
||||
wins = [{"window": 9, "map": "viewable", "class": "game", "pid": 21},
|
||||
{"window": 10, "map": "viewable", "class": "tagged", "pid": None, "appId": 5},
|
||||
{"window": 11, "map": "viewable", "class": "other", "pid": None},
|
||||
{"window": 12, "map": "unmapped", "class": "game", "pid": 21},
|
||||
{"window": 13, "map": "viewable", "class": "steam_app_550", "pid": None}]
|
||||
self.assertEqual(self.tag(wins), (False, []))
|
||||
|
||||
def test_the_x86_client_still_tags_its_game_classes(self):
|
||||
win = {"window": 13, "map": "viewable", "class": "steam_app_550", "pid": None}
|
||||
self.assertEqual(self.tag([win], arch="x86_64"), (True, ["550"]))
|
||||
|
||||
def test_exec_output_and_status(self):
|
||||
answer = self.ask({"kind": "exec", "argv": ["sh", "-c", "echo out; echo err >&2; exit 3"], "env": {"X": "1"}})
|
||||
self.assertTrue(answer["ok"])
|
||||
|
||||
@@ -549,11 +549,12 @@ class LaunchTest(FexTestCase):
|
||||
def test_the_guest_environment(self):
|
||||
arm = self.write(self.tmp / "arm.so", elf(183))
|
||||
x86 = self.write(self.tmp / "x86.so", elf(62))
|
||||
env = {"LD_PRELOAD": "%s:%s %s" % (arm, x86, self.tmp / "gone.so"),
|
||||
env = {"LD_PRELOAD": "%s:%s %s libMelonLoader.Bootstrap.so" % (arm, x86, self.tmp / "gone.so"),
|
||||
"LD_LIBRARY_PATH": "/steam/steamrtarm64:/usr/lib/aarch64-linux-gnu:/game/lib:/steam/linuxarm64",
|
||||
"FEX_ROOTFS": "/usr/share/guestos/fex-mesa", "FEX_TSOENABLED": "1"}
|
||||
guest = FEX["guest_environment"]({"portable": True}, env)
|
||||
self.assertEqual((guest["LD_PRELOAD"], guest["LD_LIBRARY_PATH"], guest["FEX_PORTABLE"]), (str(x86), "/game/lib", "1"))
|
||||
self.assertEqual((guest["LD_PRELOAD"], guest["LD_LIBRARY_PATH"], guest["FEX_PORTABLE"]),
|
||||
("%s:libMelonLoader.Bootstrap.so" % x86, "/game/lib", "1"))
|
||||
self.assertNotIn("FEX_ROOTFS", guest)
|
||||
self.assertEqual(guest["FEX_TSOENABLED"], "1")
|
||||
self.assertTrue(guest["FEX_APP_CONFIG_LOCATION"].endswith("/config/"))
|
||||
@@ -690,6 +691,32 @@ class LaunchTest(FexTestCase):
|
||||
command, env, mode = G["launch"].call_args[0]
|
||||
self.assertEqual((command, mode), (["/game/run.sh", "-a"], "auto"))
|
||||
|
||||
def test_steam_games_get_their_settings_and_linux_unity_keeps_tso(self):
|
||||
config = self.home / ".config/droiddeck/game-environment.json"
|
||||
unity = self.write(self.tmp / "Megabonk/Megabonk.x86_64", elf(62), 0o755)
|
||||
self.write(self.tmp / "Megabonk/UnityPlayer.so", elf(62))
|
||||
self.write(self.tmp / "Megabonk/GameAssembly.so", elf(62))
|
||||
other = self.write(self.tmp / "Other/game.x86_64", elf(62), 0o755)
|
||||
self.write(config, json.dumps({"version": 1, "shared": {"FEX_TSOENABLED": "0", "FEX_MULTIBLOCK": "1"},
|
||||
"games": {"20": {"FEX_TSOENABLED": "0"}}}))
|
||||
|
||||
def started(program, app):
|
||||
with mock.patch.dict(G, {"launch": mock.Mock(return_value=0), "GAME_ENVIRONMENT": str(config)}), \
|
||||
mock.patch.dict(os.environ, {"SteamAppId": app}, clear=True):
|
||||
_, said = self.quiet(FEX["main"], ["steam", "waitforexitandrun", str(program), "-arg"])
|
||||
command, env, _ = G["launch"].call_args[0]
|
||||
self.assertEqual(command, [str(program), "-arg"])
|
||||
return env.get("FEX_TSOENABLED"), env.get("FEX_MULTIBLOCK"), said
|
||||
|
||||
tso, multiblock, said = started(unity, "10")
|
||||
self.assertEqual((tso, multiblock), ("1", "1"))
|
||||
self.assertIn("Unity: FEX with TSO", said)
|
||||
self.assertEqual(started(other, "10")[:2], ("0", "1"))
|
||||
self.assertEqual(started(unity, "20")[:2], ("0", "1"))
|
||||
config.unlink()
|
||||
self.assertEqual(started(unity, "10")[:2], ("1", None))
|
||||
self.assertEqual(started(other, "10")[:2], (None, None))
|
||||
|
||||
|
||||
class AppInfoTest(unittest.TestCase):
|
||||
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
import json
|
||||
import runpy
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
COMPAT = runpy.run_path(str(BIN / "steam-compatibility"))
|
||||
TOOL = COMPAT["TOOL"]
|
||||
OLD = {"name": "DroidDeck-Proton-11-11.2", "display": "DroidDeck-Proton 11-11.2", "dir": "DroidDeck-Proton 11-11.2", "valve": False}
|
||||
NEW = {"name": "DroidDeck-Proton-11-11.4", "display": "DroidDeck-Proton 11-11.4", "dir": "DroidDeck-Proton 11-11.4", "valve": False}
|
||||
VALVE = {"name": TOOL, "display": "Proton Experimental ARM64", "dir": "Proton - Experimental (ARM64)", "valve": True}
|
||||
GE = {"name": "GE-Proton11-7", "display": "GE-Proton11-7", "dir": "GE-Proton11-7", "valve": False}
|
||||
|
||||
|
||||
def config_text(entries):
|
||||
mapping = "".join('"%s" { "name" "%s" "config" "" "priority" "%s" }' % (app, name, "75" if app == "0" else "250") for app, name in entries)
|
||||
return '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }' % mapping
|
||||
|
||||
|
||||
class DroidDeckProtonDefaultTest(unittest.TestCase):
|
||||
def run_default(self, state, mapping, catalog, apps=(), request=None, settle=True):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
directory = Path(tmp)
|
||||
(directory / "state.json").write_text(json.dumps(state))
|
||||
if request is not None:
|
||||
(directory / "request.json").write_text(json.dumps(request))
|
||||
config = directory / "config.vdf"
|
||||
config.write_text(config_text(mapping))
|
||||
default = COMPAT["register_default"](str(config), list(apps), catalog=catalog, directory=str(directory), settle=settle)
|
||||
return default, COMPAT["read_config_mapping"](str(config)), json.loads((directory / "state.json").read_text())
|
||||
|
||||
def test_a_replacement_seen_while_steam_runs_still_moves_the_default_later(self):
|
||||
_, mapping, state = self.run_default(
|
||||
{"default": OLD["name"], "own_proton": True, "tools": [VALVE, OLD]}, [("0", OLD["name"])], [VALVE, NEW], settle=False)
|
||||
self.assertEqual(state["tools"], [VALVE, NEW])
|
||||
self.assertIn(OLD["name"], state["own_builds"])
|
||||
default, mapping, state = self.run_default(state, [("0", OLD["name"])], [VALVE, NEW])
|
||||
self.assertEqual(default, NEW["name"])
|
||||
self.assertEqual(mapping, {"0": NEW["name"]})
|
||||
|
||||
def test_a_valve_default_picked_in_steam_after_a_replacement_is_kept(self):
|
||||
default, mapping, _ = self.run_default(
|
||||
{"default": OLD["name"], "own_proton": True, "tools": [VALVE, OLD]}, [("0", TOOL)], [VALVE, NEW])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
|
||||
def test_the_first_start_with_droiddeck_proton_makes_it_the_default_for_following_titles(self):
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": TOOL, "auto": {"42": TOOL}}, [("0", TOOL), ("42", TOOL), ("43", TOOL)], [VALVE, NEW], ["42", "43"])
|
||||
self.assertEqual(default, NEW["name"])
|
||||
self.assertEqual(mapping, {"0": NEW["name"], "42": NEW["name"], "43": TOOL})
|
||||
self.assertEqual(state["default"], NEW["name"])
|
||||
self.assertTrue(state["own_proton"])
|
||||
|
||||
def test_a_default_picked_after_the_switch_is_kept(self):
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": NEW["name"], "own_proton": True, "applied": 1, "tools": [VALVE, NEW]},
|
||||
[("0", NEW["name"])], [VALVE, NEW], request={"seq": 2, "valve": True, "dir": VALVE["dir"]})
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": TOOL, "own_proton": True, "tools": [VALVE, NEW]}, [("0", TOOL)], [VALVE, NEW])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
|
||||
def test_a_replaced_build_moves_its_default_and_titles_to_the_newest(self):
|
||||
default, mapping, state = self.run_default(
|
||||
{"default": OLD["name"], "own_proton": True, "auto": {"42": OLD["name"]}, "tools": [VALVE, OLD, GE]},
|
||||
[("0", OLD["name"]), ("42", OLD["name"]), ("43", OLD["name"]), ("44", GE["name"]), ("45", TOOL)],
|
||||
[VALVE, NEW, GE], ["42", "43", "44", "45"])
|
||||
self.assertEqual(default, NEW["name"])
|
||||
self.assertEqual(mapping, {"0": NEW["name"], "42": NEW["name"], "43": NEW["name"], "44": GE["name"], "45": TOOL})
|
||||
self.assertEqual(state["auto"], {"42": NEW["name"]})
|
||||
|
||||
def test_a_replaced_build_does_not_override_a_valve_default(self):
|
||||
default, mapping, _ = self.run_default(
|
||||
{"default": TOOL, "own_proton": True, "tools": [VALVE, OLD]}, [("0", TOOL), ("43", OLD["name"])], [VALVE, NEW], ["43"])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL, "43": NEW["name"]})
|
||||
|
||||
def test_nothing_changes_without_droiddeck_proton(self):
|
||||
default, mapping, state = self.run_default({"default": TOOL}, [("0", TOOL)], [VALVE, GE])
|
||||
self.assertEqual(default, TOOL)
|
||||
self.assertEqual(mapping, {"0": TOOL})
|
||||
self.assertNotIn("own_proton", state)
|
||||
|
||||
def test_the_newest_build_is_found_by_version(self):
|
||||
newest, gone = COMPAT["own_proton_moves"]({"tools": [OLD]}, [dict(NEW, name="a", dir="DroidDeck-Proton 11-9.10"), dict(NEW, name="b", dir="DroidDeck-Proton 11-11.1")])
|
||||
self.assertEqual(newest, "b")
|
||||
self.assertEqual(gone, {OLD["name"]})
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -413,6 +413,21 @@ class DroiddeckctlTest(FakeAdbTest):
|
||||
self.assertEqual("Awake", out["wakefulness"])
|
||||
self.assertIn(["shell", "input", "keyevent", "KEYCODE_WAKEUP"], [c["args"] for c in self.calls()])
|
||||
|
||||
def test_proot_profile_queues_only_the_next_session(self):
|
||||
self.configure({"env": {"ok": True}})
|
||||
code, out = self.run_ctl("proot-profile", "enable", "--slow-us", "250")
|
||||
self.assertEqual(0, code, out)
|
||||
self.assertEqual({"op": "set", "lines": ["PROOT_PROFILE=1", "PROOT_PROFILE_SLOW_US=250"], "persistent": False},
|
||||
self.calls("env")[0]["request"])
|
||||
|
||||
def test_proot_profile_report_needs_no_adb_or_device(self):
|
||||
path = self.dir / "session.log"
|
||||
path.write_text('ordinary log')
|
||||
with unittest.mock.patch.object(ctl, "adb_path", side_effect=AssertionError("must stay offline")):
|
||||
code, out = self.run_ctl("proot-profile", "report", str(path))
|
||||
self.assertEqual(0, code, out)
|
||||
self.assertFalse(out["hasCounters"])
|
||||
|
||||
def test_override_pushes_to_the_inbox_first(self):
|
||||
self.configure({
|
||||
"access": {"ok": True, "commands": True, "inbox": "/sdcard/Android/data/x/files/agent-inbox"},
|
||||
|
||||
@@ -1160,8 +1160,12 @@ class BundleTest(unittest.TestCase):
|
||||
except ImportError:
|
||||
self.skipTest("PyYAML is not installed")
|
||||
apk = yaml.safe_load((self.ROOT / ".github/workflows/build.yml").read_text())
|
||||
steps = {step.get("name"): step for step in apk["jobs"]["build"]["steps"]}
|
||||
bundle = steps["Bundle the droiddeck-esync packs"]
|
||||
steps = {step.get("name"): step for step in apk["jobs"]["components"]["steps"]}
|
||||
import json
|
||||
recipes = json.loads((self.ROOT / "tools/components/recipes.json").read_text())
|
||||
bundle = dict(steps["Bundle the droiddeck-esync packs"])
|
||||
self.assertIn("prepare.py esync", bundle["run"])
|
||||
bundle["run"] = (self.ROOT / recipes["esync"]["script"]).read_text()
|
||||
self.assertNotIn("if", bundle)
|
||||
self.assertIn("tools/droiddeck-esync/release.env", bundle["run"])
|
||||
self.assertIn('release_url="https://github.com/${SYNC_BUNDLE_REPO}/releases/download/${SYNC_BUNDLE_TAG}"', bundle["run"])
|
||||
@@ -1169,7 +1173,7 @@ class BundleTest(unittest.TestCase):
|
||||
self.assertIn('curl -fsSL --retry 3 -o sync-index.json "$release_url/index.json"', bundle["run"])
|
||||
self.assertIn("sha256sum -c -", bundle["run"])
|
||||
self.assertNotIn("revoked.txt", bundle["run"])
|
||||
stage = next(step for step in apk["jobs"]["build"]["steps"] if "overlay/usr/local/bin/droiddeck-*" in step.get("run", ""))
|
||||
stage = {"run": (self.ROOT / recipes["runtime"]["script"]).read_text()}
|
||||
self.assertIn("tools/linuxfs/overlay/usr/local/bin/droiddeck-* ", stage["run"])
|
||||
local = (self.ROOT / "tools/build_local.sh").read_text()
|
||||
self.assertIn("tools/linuxfs/overlay/usr/local/bin/droiddeck-* ", local)
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin/droiddeck-flatpak-setup"
|
||||
|
||||
|
||||
class FlatpakSetupTest(unittest.TestCase):
|
||||
def run_setup(self, uid, pacman):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
bin_dir = root / "bin"
|
||||
bin_dir.mkdir()
|
||||
stubs = {"id": "echo %d" % uid, "curl": "exit 7", "pacman": pacman, "pacman-key": "exit 0"}
|
||||
for name, body in stubs.items():
|
||||
(bin_dir / name).write_text("#!/bin/sh\n%s\n" % body)
|
||||
(bin_dir / name).chmod(0o755)
|
||||
script = root / "setup"
|
||||
script.write_text(SCRIPT.read_text().replace("WORK=/var/cache/droiddeck-flatpak", "WORK=%s/work" % root)
|
||||
.replace("/etc/pacman.d/gnupg/pubring.gpg", str(root / "pubring.gpg"))
|
||||
.replace(" /etc/pacman.conf >", " %s >" % (root / "pacman.conf")))
|
||||
(root / "pacman.conf").write_text("[options]\n[core]\nInclude = /etc/pacman.d/mirrorlist\n")
|
||||
(root / "pubring.gpg").write_text("")
|
||||
env = dict(os.environ, PATH="%s:%s" % (bin_dir, os.environ["PATH"]))
|
||||
result = subprocess.run(["bash", str(script)], env=env, capture_output=True, text=True, timeout=30)
|
||||
return result.returncode, result.stdout
|
||||
|
||||
def test_a_manual_run_without_root_says_so(self):
|
||||
code, out = self.run_setup(1000, "exit 0")
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("== FAIL needs root", out)
|
||||
self.assertNotIn("Reading the package lists", out)
|
||||
|
||||
def test_an_unreachable_mirror_reports_pacmans_error(self):
|
||||
code, out = self.run_setup(0, "echo \"error: failed retrieving file 'core.db' : Could not resolve host\" >&2; exit 1")
|
||||
self.assertEqual(code, 1)
|
||||
self.assertIn("== FAIL could not reach the Arch Linux ARM mirrors (error: failed retrieving file 'core.db' : "
|
||||
"Could not resolve host)", out)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -8,6 +8,7 @@ import shlex
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
from unittest import mock
|
||||
import unittest
|
||||
|
||||
BIN = Path(__file__).resolve().parents[1] / "linuxfs/overlay/usr/local/bin"
|
||||
@@ -295,6 +296,14 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
self.assertEqual(MODULE["apply_config"](env, config, "42")["TU_DEBUG"], "sysmem")
|
||||
self.assertNotIn("TU_DEBUG", MODULE["apply_config"](env, config, "43"))
|
||||
|
||||
def test_the_vram_cap_comes_before_the_games_own_dxvk_settings(self):
|
||||
cap = MODULE["vram_cap"]
|
||||
self.assertEqual(cap({"BL_VRAM_MB": "4096"})["DXVK_CONFIG"], "dxgi.maxDeviceMemory = 4096")
|
||||
self.assertEqual(cap({"BL_VRAM_MB": "2048", "DXVK_CONFIG": "dxvk.maxFrameRate = 60;"})["DXVK_CONFIG"],
|
||||
"dxgi.maxDeviceMemory = 2048; dxvk.maxFrameRate = 60")
|
||||
for off in ({}, {"BL_VRAM_MB": "0"}, {"BL_VRAM_MB": "lots"}, {"BL_VRAM_MB": "²"}, {"BL_VRAM_MB": "-1"}):
|
||||
self.assertNotIn("DXVK_CONFIG", cap(off))
|
||||
|
||||
def test_a_games_wine_sync_choice_also_reaches_its_setup_runs(self):
|
||||
env = {"BL_SYNC": "1", "BL_SYNC_FALLBACK": "1", "BL_FSYNC_FIRST": "0", "OTHER": "kept"}
|
||||
config = {"version": 1, "games": {"42": {"BL_SYNC": "0", "BL_FSYNC_FIRST": "1", "PROTON_NO_ESYNC": "1", "FEX_TSOENABLED": "1"}}}
|
||||
@@ -472,6 +481,90 @@ class GameEnvironmentTest(unittest.TestCase):
|
||||
(asylum / name).touch()
|
||||
self.assertEqual(MODULE["engine_fixes"](str(asylum / "BmLauncher.exe"), []), ({}, [], []))
|
||||
|
||||
def test_black_ops_iii_and_dark_souls_remastered_skip_protonfixes(self):
|
||||
for exe in ("/game/Call of Duty Black Ops III/BlackOps3.exe", "/game/DARK SOULS REMASTERED/DarkSoulsRemastered.exe"):
|
||||
env, extra, notes = MODULE["engine_fixes"](exe, [])
|
||||
self.assertEqual((env, extra), ({"PROTONFIXES_DISABLE": "1"}, []))
|
||||
self.assertTrue(notes)
|
||||
self.assertEqual(MODULE["engine_fixes"]("/game/Game/DarkSoulsII.exe", []), ({}, [], []))
|
||||
|
||||
def test_game_cores_are_parsed_from_lists_and_ranges(self):
|
||||
parse = MODULE["parse_cores"]
|
||||
self.assertEqual(parse("0-3,6"), {0, 1, 2, 3, 6})
|
||||
self.assertEqual(parse(" 4, 5 "), {4, 5})
|
||||
for bad in ("", "a", "3-1", "1,,2", "-1", "1-"):
|
||||
self.assertIsNone(parse(bad), bad)
|
||||
|
||||
def test_a_profiles_game_cores_pin_the_game_within_the_online_cores(self):
|
||||
calls = []
|
||||
os_mod = MODULE["os"]
|
||||
with mock.patch.dict(MODULE["game_cores"].__globals__, {"online_cores": lambda: {0, 1, 2, 3, 4, 5, 6, 7}}), \
|
||||
mock.patch.object(os_mod, "sched_setaffinity", side_effect=lambda pid, cores: calls.append(set(cores)), create=True):
|
||||
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "0-2,9"})
|
||||
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "junk"})
|
||||
MODULE["game_cores"]({"DROIDDECK_GAME_CORES": "12-13"})
|
||||
MODULE["game_cores"]({})
|
||||
self.assertEqual(calls, [{0, 1, 2}])
|
||||
self.assertEqual(MODULE["parse_cores"]("0,2-7"), {0, 2, 3, 4, 5, 6, 7})
|
||||
|
||||
def test_caravan_sandwitch_robocop_and_cyberpunk_run_at_feature_level_12_1(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
caravan = Path(tmp) / "Caravan SandWitch"
|
||||
shipping = caravan / "CaravanSandWitch/Binaries/Win64"
|
||||
shipping.mkdir(parents=True)
|
||||
for name in ("CaravanSandWitch.exe", ".droiddeck-launch.bat"):
|
||||
(caravan / name).touch()
|
||||
(shipping / "CaravanSandWitch-Win64-Shipping.exe").touch()
|
||||
cyberpunk = Path(tmp) / "Cyberpunk 2077"
|
||||
(cyberpunk / "bin/x64").mkdir(parents=True)
|
||||
for name in ("REDprelauncher.exe", "bin/x64/Cyberpunk2077.exe"):
|
||||
(cyberpunk / name).touch()
|
||||
robocop = Path(tmp) / "RoboCop Rogue City"
|
||||
(robocop / "RoboCop/Binaries/Win64").mkdir(parents=True)
|
||||
for name in ("RoboCop.exe", "RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe"):
|
||||
(robocop / name).touch()
|
||||
games = [caravan / "CaravanSandWitch.exe", caravan / ".droiddeck-launch.bat",
|
||||
shipping / "CaravanSandWitch-Win64-Shipping.exe",
|
||||
robocop / "RoboCop.exe", robocop / "RoboCop/Binaries/Win64/RoboCop-Win64-Shipping.exe",
|
||||
cyberpunk / "REDprelauncher.exe", cyberpunk / "bin/x64/Cyberpunk2077.exe"]
|
||||
for exe in games:
|
||||
env, extra, notes = MODULE["engine_fixes"](str(exe), [])
|
||||
self.assertEqual((env, extra), ({"VKD3D_FEATURE_LEVEL": "12_1"}, []), exe)
|
||||
self.assertTrue(notes)
|
||||
config = {"version": 1, "shared": {"VKD3D_FEATURE_LEVEL": "12_2"}}
|
||||
self.assertEqual(MODULE["apply_config"]({}, config, "1582650", env)["VKD3D_FEATURE_LEVEL"], "12_1")
|
||||
config["games"] = {"1582650": {"VKD3D_FEATURE_LEVEL": "12_2"}}
|
||||
self.assertEqual(MODULE["apply_config"]({}, config, "1582650", env)["VKD3D_FEATURE_LEVEL"], "12_2")
|
||||
other = Path(tmp) / "Other/Binaries/Win64"
|
||||
other.mkdir(parents=True)
|
||||
(other / "Other-Win64-Shipping.exe").touch()
|
||||
self.assertEqual(MODULE["engine_fixes"](str(other / "Other-Win64-Shipping.exe"), []), ({}, [], []))
|
||||
witcher = Path(tmp) / "The Witcher 3"
|
||||
witcher.mkdir()
|
||||
(witcher / "REDprelauncher.exe").touch()
|
||||
self.assertNotIn("VKD3D_FEATURE_LEVEL", MODULE["engine_fixes"](str(witcher / "REDprelauncher.exe"), [])[0])
|
||||
|
||||
def test_unity_players_keep_tso_over_the_preset(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
def game(*names):
|
||||
for name in names:
|
||||
(Path(tmp) / name).parent.mkdir(parents=True, exist_ok=True)
|
||||
(Path(tmp) / name).touch()
|
||||
return str(Path(tmp) / names[0])
|
||||
|
||||
il2cpp = game("Megabonk/Megabonk.x86_64", "Megabonk/UnityPlayer.so", "Megabonk/GameAssembly.so")
|
||||
mono = game("Mono/Game.x86_64", "Mono/UnityPlayer.so")
|
||||
windows = game("Crab Game/Crab Game.exe", "Crab Game/UnityPlayer.dll", "Crab Game/GameAssembly.dll")
|
||||
windows_mono = game("RoR2/Risk of Rain 2.exe", "RoR2/UnityPlayer.dll", "RoR2/MonoBleedingEdge/mono-2.0-bdwgc.dll")
|
||||
for exe in (il2cpp, mono, windows, windows_mono):
|
||||
env, extra, notes = MODULE["engine_fixes"](exe, [])
|
||||
self.assertEqual((env, extra, notes), ({"FEX_TSOENABLED": "1"}, [], ["Unity: FEX with TSO"]))
|
||||
performance = {"version": 1, "shared": {"FEX_TSOENABLED": "0", "FEX_VECTORTSOENABLED": "0"}}
|
||||
result = MODULE["apply_config"]({}, performance, "3405340", env)
|
||||
self.assertEqual((result["FEX_TSOENABLED"], result["FEX_VECTORTSOENABLED"]), ("1", "0"))
|
||||
performance["games"] = {"3405340": {"FEX_TSOENABLED": "0"}}
|
||||
self.assertEqual(MODULE["apply_config"]({}, performance, "3405340", env)["FEX_TSOENABLED"], "0")
|
||||
|
||||
def test_a_new_fix_only_needs_registering(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
(Path(tmp) / "Game.exe").touch()
|
||||
@@ -1278,6 +1371,52 @@ class DirectAudioPrefixTest(unittest.TestCase):
|
||||
self.assertIsNone(self.link("system32"))
|
||||
|
||||
|
||||
class UbisoftOverlayTest(unittest.TestCase):
|
||||
SETTINGS = (
|
||||
"language:\n code: en-US\n"
|
||||
"overlay:\n enabled: true\n forceunhookgame: false\n fps_enabled: false\n warning_enabled: true\n"
|
||||
"patchTrigger:\n source: USER_RESTART\n"
|
||||
)
|
||||
|
||||
def test_the_overlay_and_its_prompt_are_turned_off_and_the_rest_is_kept(self):
|
||||
got = MODULE["overlay_off"](self.SETTINGS)
|
||||
self.assertEqual(got, self.SETTINGS.replace("enabled: true", "enabled: false"))
|
||||
self.assertEqual(MODULE["overlay_off"](got), got)
|
||||
|
||||
def test_missing_keys_or_section_are_added(self):
|
||||
self.assertEqual(MODULE["overlay_off"]("overlay:\n fps_enabled: true\nmisc:\n a: 1\n"),
|
||||
"overlay:\n fps_enabled: true\n enabled: false\n warning_enabled: false\nmisc:\n a: 1\n")
|
||||
self.assertEqual(MODULE["overlay_off"](""), "overlay:\n enabled: false\n warning_enabled: false\n")
|
||||
|
||||
def test_blank_lines_inside_the_overlay_section_do_not_end_it(self):
|
||||
text = "overlay:\n enabled: true\n\n warning_enabled: true\n\nmisc:\n a: 1\n"
|
||||
self.assertEqual(MODULE["overlay_off"](text), text.replace("true", "false"))
|
||||
self.assertEqual(MODULE["overlay_off"]("overlay:\n fps_enabled: true\n\nmisc:\n a: 1\n"),
|
||||
"overlay:\n fps_enabled: true\n enabled: false\n warning_enabled: false\n\nmisc:\n a: 1\n")
|
||||
|
||||
def test_an_annotated_overlay_header_is_the_same_section(self):
|
||||
self.assertEqual(MODULE["overlay_off"]("overlay: # in-game\n enabled: true\n"),
|
||||
"overlay: # in-game\n enabled: false\n warning_enabled: false\n")
|
||||
|
||||
def test_only_prefixes_with_ubisoft_connect_are_touched(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
prefix = Path(tmp) / "447040/pfx"
|
||||
env = {"STEAM_COMPAT_DATA_PATH": str(prefix.parent)}
|
||||
settings = prefix / MODULE["UBISOFT_SETTINGS"]
|
||||
prefix.mkdir(parents=True)
|
||||
MODULE["ubisoft_overlay_off"](env)
|
||||
self.assertFalse(settings.exists())
|
||||
(prefix / MODULE["UBISOFT_LAUNCHER"]).mkdir(parents=True)
|
||||
MODULE["ubisoft_overlay_off"](env)
|
||||
self.assertEqual(settings.read_text(), "overlay:\n enabled: false\n warning_enabled: false\n")
|
||||
settings.write_text(self.SETTINGS)
|
||||
settings.chmod(0o644)
|
||||
MODULE["ubisoft_overlay_off"](env)
|
||||
self.assertEqual(settings.read_text(), self.SETTINGS.replace("enabled: true", "enabled: false"))
|
||||
self.assertEqual(settings.stat().st_mode & 0o777, 0o644)
|
||||
self.assertEqual(sorted(p.name for p in settings.parent.iterdir()), ["settings.yaml"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
@@ -0,0 +1,188 @@
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdatomic.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "../../app/src/main/cpp/adrenotools/src/hook/kgsl.h"
|
||||
#include "../../app/src/main/cpp/waylandcomp/src/gpu_clock_pin.h"
|
||||
|
||||
enum { NONE, OPEN, DEVICE, CONTEXT, CONSTRAINT, MEMORY, MAP, SYNC, SUBMIT, THREAD, WAIT };
|
||||
static atomic_int failure, descriptors, contexts, memories, mappings, submissions, waits;
|
||||
static atomic_bool timeout_wait;
|
||||
static bool legacy_core;
|
||||
static uint32_t commands[1024];
|
||||
|
||||
int __android_log_print(int priority, const char *tag, const char *format, ...) {
|
||||
(void)priority; (void)tag; (void)format;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __wrap_open(const char *path, int flags, ...) {
|
||||
(void)flags;
|
||||
assert(!strcmp(path, "/dev/kgsl-3d0"));
|
||||
if (atomic_load(&failure) == OPEN) { errno = EACCES; return -1; }
|
||||
assert(atomic_fetch_add(&descriptors, 1) == 0);
|
||||
return 91;
|
||||
}
|
||||
|
||||
int __wrap_close(int fd) {
|
||||
assert(fd == 91);
|
||||
assert(atomic_fetch_sub(&descriptors, 1) == 1);
|
||||
errno = EBADF;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void *__wrap_mmap(void *address, size_t size, int protection, int flags, int fd, off_t offset) {
|
||||
(void)address; (void)protection; (void)flags;
|
||||
assert(fd == 91 && size == sizeof(commands) && offset == (23 << 12));
|
||||
if (atomic_load(&failure) == MAP) { errno = EACCES; return MAP_FAILED; }
|
||||
assert(atomic_fetch_add(&mappings, 1) == 0);
|
||||
return commands;
|
||||
}
|
||||
|
||||
int __wrap_munmap(void *address, size_t size) {
|
||||
assert(address == commands && size == sizeof(commands));
|
||||
assert(atomic_fetch_sub(&mappings, 1) == 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef __ANDROID__
|
||||
int __wrap_ioctl(int fd, int request, ...) {
|
||||
#else
|
||||
int __wrap_ioctl(int fd, unsigned long request, ...) {
|
||||
#endif
|
||||
assert(fd == 91);
|
||||
va_list args;
|
||||
va_start(args, request);
|
||||
void *arg = va_arg(args, void *);
|
||||
va_end(args);
|
||||
int step = NONE;
|
||||
switch ((unsigned int)request) {
|
||||
case IOCTL_KGSL_DEVICE_GETPROPERTY: step = DEVICE; break;
|
||||
case IOCTL_KGSL_DRAWCTXT_CREATE: step = CONTEXT; break;
|
||||
case IOCTL_KGSL_SETPROPERTY: step = CONSTRAINT; break;
|
||||
case IOCTL_KGSL_GPUMEM_ALLOC_ID: step = MEMORY; break;
|
||||
case IOCTL_KGSL_GPUMEM_SYNC_CACHE: step = SYNC; break;
|
||||
case IOCTL_KGSL_GPU_COMMAND: step = SUBMIT; break;
|
||||
case IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID: step = WAIT; break;
|
||||
}
|
||||
if (step && atomic_load(&failure) == step) { errno = EACCES; return -1; }
|
||||
switch ((unsigned int)request) {
|
||||
case IOCTL_KGSL_DEVICE_GETPROPERTY: {
|
||||
struct kgsl_device_getproperty *property = arg;
|
||||
assert(property->type == KGSL_PROP_DEVICE_INFO);
|
||||
((struct kgsl_devinfo *)property->value)->chip_id = legacy_core ? 0x04030000 : 0x07030000;
|
||||
break;
|
||||
}
|
||||
case IOCTL_KGSL_DRAWCTXT_CREATE: {
|
||||
struct kgsl_drawctxt_create *context = arg;
|
||||
assert(context->flags & KGSL_CONTEXT_PWR_CONSTRAINT);
|
||||
context->drawctxt_id = 17;
|
||||
atomic_fetch_add(&contexts, 1);
|
||||
break;
|
||||
}
|
||||
case IOCTL_KGSL_SETPROPERTY: {
|
||||
struct kgsl_device_getproperty *property = arg;
|
||||
assert(property->type == KGSL_PROP_PWR_CONSTRAINT);
|
||||
struct kgsl_device_constraint *constraint = property->value;
|
||||
assert(constraint->context_id == 17 && constraint->type == KGSL_CONSTRAINT_PWRLEVEL);
|
||||
assert(((struct kgsl_device_constraint_pwrlevel *)constraint->data)->level == KGSL_CONSTRAINT_PWR_MAX);
|
||||
break;
|
||||
}
|
||||
case IOCTL_KGSL_GPUMEM_ALLOC_ID: {
|
||||
struct kgsl_gpumem_alloc_id *memory = arg;
|
||||
memory->id = 23; memory->gpuaddr = 0x100000; memory->mmapsize = sizeof(commands);
|
||||
atomic_fetch_add(&memories, 1);
|
||||
break;
|
||||
}
|
||||
case IOCTL_KGSL_GPUMEM_SYNC_CACHE:
|
||||
assert(((struct kgsl_gpumem_sync_cache *)arg)->op == KGSL_GPUMEM_CACHE_CLEAN);
|
||||
break;
|
||||
case IOCTL_KGSL_GPU_COMMAND: {
|
||||
struct kgsl_gpu_command *command = arg;
|
||||
struct kgsl_command_object *object = (void *)(uintptr_t)command->cmdlist;
|
||||
assert(command->context_id == 17 && command->numcmds == 1);
|
||||
assert(command->flags & KGSL_CMDBATCH_PWR_CONSTRAINT);
|
||||
assert(object->id == 23 && object->gpuaddr == 0x100000 && object->size == 8);
|
||||
assert(commands[0] == (legacy_core ? 0xc0001000 : 0x70100001) && commands[1] == 0);
|
||||
command->timestamp = atomic_fetch_add(&submissions, 1) + 1;
|
||||
break;
|
||||
}
|
||||
case IOCTL_KGSL_DEVICE_WAITTIMESTAMP_CTXTID:
|
||||
atomic_fetch_add(&waits, 1);
|
||||
if (atomic_load(&timeout_wait)) { errno = ETIMEDOUT; return -1; }
|
||||
break;
|
||||
case IOCTL_KGSL_DRAWCTXT_DESTROY:
|
||||
assert(atomic_fetch_sub(&contexts, 1) == 1);
|
||||
break;
|
||||
case IOCTL_KGSL_GPUMEM_FREE_ID:
|
||||
assert(atomic_fetch_sub(&memories, 1) == 1);
|
||||
break;
|
||||
default: assert(!"unexpected ioctl");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int __real_pthread_create(pthread_t *, const pthread_attr_t *, void *(*)(void *), void *);
|
||||
int __wrap_pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start)(void *), void *arg) {
|
||||
if (atomic_load(&failure) == THREAD) return EAGAIN;
|
||||
return __real_pthread_create(thread, attr, start, arg);
|
||||
}
|
||||
|
||||
static void assert_released(void) {
|
||||
assert(!atomic_load(&descriptors) && !atomic_load(&contexts));
|
||||
assert(!atomic_load(&memories) && !atomic_load(&mappings));
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
assert(gpu_clock_pin_set(false));
|
||||
assert_released();
|
||||
legacy_core = true;
|
||||
assert(gpu_clock_pin_set(true));
|
||||
assert(gpu_clock_pin_set(false));
|
||||
assert_released();
|
||||
legacy_core = false;
|
||||
for (int step = OPEN; step <= THREAD; ++step) {
|
||||
atomic_store(&failure, step);
|
||||
assert(!gpu_clock_pin_set(true));
|
||||
assert(errno == (step == THREAD ? EAGAIN : EACCES));
|
||||
assert_released();
|
||||
}
|
||||
atomic_store(&failure, NONE);
|
||||
atomic_store(&submissions, 0);
|
||||
assert(gpu_clock_pin_set(true));
|
||||
assert(gpu_clock_pin_set(true));
|
||||
for (int i = 0; i < 100 && atomic_load(&submissions) < 2; ++i) usleep(10000);
|
||||
assert(atomic_load(&submissions) > 1);
|
||||
assert(gpu_clock_pin_set(false));
|
||||
assert(gpu_clock_pin_set(false));
|
||||
assert_released();
|
||||
|
||||
atomic_store(&timeout_wait, true);
|
||||
atomic_store(&submissions, 0);
|
||||
atomic_store(&waits, 0);
|
||||
assert(gpu_clock_pin_set(true));
|
||||
for (int i = 0; i < 100 && atomic_load(&waits) < 2; ++i) usleep(10000);
|
||||
assert(atomic_load(&waits) >= 2);
|
||||
assert(atomic_load(&submissions) == 1);
|
||||
assert(gpu_clock_pin_set(false));
|
||||
assert_released();
|
||||
atomic_store(&timeout_wait, false);
|
||||
|
||||
atomic_store(&failure, WAIT);
|
||||
assert(gpu_clock_pin_set(true));
|
||||
for (int i = 0; i < 100 && atomic_load(&descriptors); ++i) usleep(10000);
|
||||
assert_released();
|
||||
atomic_store(&failure, NONE);
|
||||
assert(gpu_clock_pin_set(true));
|
||||
assert(gpu_clock_pin_set(false));
|
||||
assert_released();
|
||||
puts("gpu clock pin: failure cleanup, renewal, bounded queue and restart passed");
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import pathlib
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = pathlib.Path(__file__).resolve().parents[2]
|
||||
|
||||
|
||||
class GpuClockPinTest(unittest.TestCase):
|
||||
@unittest.skipUnless(sys.platform.startswith('linux') and shutil.which('cc'), 'requires a Linux C compiler')
|
||||
def test_constraint_lifecycle(self):
|
||||
with tempfile.TemporaryDirectory() as tmp:
|
||||
directory = pathlib.Path(tmp)
|
||||
(directory / 'android').mkdir()
|
||||
(directory / 'android/log.h').write_text(
|
||||
'#define ANDROID_LOG_WARN 5\n'
|
||||
'int __android_log_print(int, const char *, const char *, ...);\n')
|
||||
binary = directory / 'gpu-clock-pin-test'
|
||||
subprocess.run([
|
||||
'cc', '-std=c11', '-D_DEFAULT_SOURCE', '-D__user=', '-Wall', '-Wextra', '-Werror',
|
||||
'-I', str(directory), '-pthread',
|
||||
str(ROOT / 'tools/tests/test_gpu_clock_pin.c'),
|
||||
str(ROOT / 'app/src/main/cpp/waylandcomp/src/gpu_clock_pin.c'),
|
||||
'-Wl,--wrap=open,--wrap=close,--wrap=mmap,--wrap=munmap,--wrap=ioctl,--wrap=pthread_create',
|
||||
'-o', str(binary),
|
||||
], check=True)
|
||||
subprocess.run([str(binary)], check=True, timeout=10)
|
||||
@@ -0,0 +1,580 @@
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload"
|
||||
|
||||
NTDLL = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <signal.h>
|
||||
#include <string.h>
|
||||
|
||||
int install_handler(int sig, void (*fn)(int, siginfo_t *, void *), void **seen) {
|
||||
struct sigaction sa, old;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_sigaction = fn;
|
||||
sa.sa_flags = SA_SIGINFO | SA_RESTART;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
if (sigaction(sig, &sa, NULL) != 0) return -1;
|
||||
if (sigaction(sig, NULL, &old) != 0) return -1;
|
||||
*seen = (void *)old.sa_sigaction;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int install_oneshot(int sig, void (*fn)(int, siginfo_t *, void *)) {
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
sa.sa_sigaction = fn;
|
||||
sa.sa_flags = SA_SIGINFO | SA_RESTART | SA_RESETHAND;
|
||||
sigemptyset(&sa.sa_mask);
|
||||
return sigaction(sig, &sa, NULL);
|
||||
}
|
||||
"""
|
||||
|
||||
PROGRAM = r"""
|
||||
#define _GNU_SOURCE
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <linux/ioctl.h>
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <signal.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/wait.h>
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
struct sem_args { uint32_t count, max; };
|
||||
struct mutex_args { uint32_t owner, count; };
|
||||
struct event_args { uint32_t manual, signaled; };
|
||||
struct wait_args { uint64_t timeout, objs; uint32_t count, index, flags, owner, alert, pad; };
|
||||
#define NT_CREATE_SEM _IOW('N', 0x80, struct sem_args)
|
||||
#define NT_SEM_RELEASE _IOWR('N', 0x81, uint32_t)
|
||||
#define NT_WAIT_ANY _IOWR('N', 0x82, struct wait_args)
|
||||
#define NT_WAIT_ALL _IOWR('N', 0x83, struct wait_args)
|
||||
#define NT_CREATE_MUTEX _IOW('N', 0x84, struct mutex_args)
|
||||
#define NT_MUTEX_UNLOCK _IOWR('N', 0x85, struct mutex_args)
|
||||
#define NT_MUTEX_KILL _IOW('N', 0x86, uint32_t)
|
||||
#define NT_CREATE_EVENT _IOW('N', 0x87, struct event_args)
|
||||
#define NT_EVENT_SET _IOR('N', 0x88, uint32_t)
|
||||
#define NT_EVENT_RESET _IOR('N', 0x89, uint32_t)
|
||||
#define NT_EVENT_PULSE _IOR('N', 0x8a, uint32_t)
|
||||
#define NT_SEM_READ _IOR('N', 0x8b, struct sem_args)
|
||||
#define NT_MUTEX_READ _IOR('N', 0x8c, struct mutex_args)
|
||||
#define NT_EVENT_READ _IOR('N', 0x8d, struct event_args)
|
||||
|
||||
int install_handler(int sig, void (*fn)(int, siginfo_t *, void *), void **seen);
|
||||
int install_oneshot(int sig, void (*fn)(int, siginfo_t *, void *));
|
||||
|
||||
static int dev, fails;
|
||||
#define CHECK(name, cond) do { if (!(cond)) { printf("FAIL %s line %d errno %d\n", name, __LINE__, errno); fails++; } } while (0)
|
||||
|
||||
static uint64_t mono_ns(int64_t delta_ms) {
|
||||
struct timespec t;
|
||||
clock_gettime(CLOCK_MONOTONIC, &t);
|
||||
return (uint64_t)t.tv_sec * 1000000000ull + (uint64_t)t.tv_nsec + (uint64_t)(delta_ms * 1000000);
|
||||
}
|
||||
|
||||
static int wait_on(unsigned long req, const int *objs, uint32_t count, uint32_t owner, int alert, uint64_t timeout, uint32_t *index) {
|
||||
struct wait_args w = {timeout, (uintptr_t)objs, count, 0xdead, 0, owner, (uint32_t)alert, 0};
|
||||
int r = ioctl(dev, req, &w);
|
||||
if (index) *index = w.index;
|
||||
return r < 0 ? errno : 0;
|
||||
}
|
||||
|
||||
static int event(int manual, int signaled) {
|
||||
struct event_args a = {(uint32_t)manual, (uint32_t)signaled};
|
||||
return ioctl(dev, NT_CREATE_EVENT, &a);
|
||||
}
|
||||
|
||||
static int sem(uint32_t count, uint32_t max) {
|
||||
struct sem_args a = {count, max};
|
||||
return ioctl(dev, NT_CREATE_SEM, &a);
|
||||
}
|
||||
|
||||
static int mutex(uint32_t owner, uint32_t count) {
|
||||
struct mutex_args a = {owner, count};
|
||||
return ioctl(dev, NT_CREATE_MUTEX, &a);
|
||||
}
|
||||
|
||||
static uint32_t prev_of(int fd, unsigned long req, uint32_t in) {
|
||||
uint32_t v = in;
|
||||
if (ioctl(fd, req, &v) < 0) return 0xffffffff;
|
||||
return v;
|
||||
}
|
||||
|
||||
static void semaphores(void) {
|
||||
struct sem_args bad = {3, 2}, r;
|
||||
CHECK("sem_create_invalid", ioctl(dev, NT_CREATE_SEM, &bad) < 0 && errno == EINVAL);
|
||||
int s = sem(2, 2);
|
||||
CHECK("sem_create", s >= 0);
|
||||
uint32_t idx;
|
||||
CHECK("sem_wait1", wait_on(NT_WAIT_ANY, &s, 1, 1, 0, 0, &idx) == 0 && idx == 0);
|
||||
CHECK("sem_wait2", wait_on(NT_WAIT_ANY, &s, 1, 1, 0, 0, &idx) == 0);
|
||||
CHECK("sem_empty", wait_on(NT_WAIT_ANY, &s, 1, 1, 0, 0, NULL) == ETIMEDOUT);
|
||||
CHECK("sem_release_prev", prev_of(s, NT_SEM_RELEASE, 1) == 0);
|
||||
CHECK("sem_overflow", prev_of(s, NT_SEM_RELEASE, 2) == 0xffffffff && errno == EOVERFLOW);
|
||||
CHECK("sem_read", ioctl(s, NT_SEM_READ, &r) == 0 && r.count == 1 && r.max == 2);
|
||||
close(s);
|
||||
}
|
||||
|
||||
static void mutexes(void) {
|
||||
struct mutex_args bad = {0, 1}, r, u;
|
||||
CHECK("mutex_create_invalid", ioctl(dev, NT_CREATE_MUTEX, &bad) < 0 && errno == EINVAL);
|
||||
int m = mutex(0, 0);
|
||||
uint32_t idx;
|
||||
CHECK("mutex_owner_zero", wait_on(NT_WAIT_ANY, &m, 1, 0, 0, 0, NULL) == EINVAL);
|
||||
CHECK("mutex_take", wait_on(NT_WAIT_ANY, &m, 1, 7, 0, 0, &idx) == 0 && idx == 0);
|
||||
CHECK("mutex_recurse", wait_on(NT_WAIT_ANY, &m, 1, 7, 0, 0, NULL) == 0);
|
||||
CHECK("mutex_other", wait_on(NT_WAIT_ANY, &m, 1, 8, 0, 0, NULL) == ETIMEDOUT);
|
||||
CHECK("mutex_read", ioctl(m, NT_MUTEX_READ, &r) == 0 && r.owner == 7 && r.count == 2);
|
||||
u = (struct mutex_args){8, 0};
|
||||
CHECK("mutex_unlock_eperm", ioctl(m, NT_MUTEX_UNLOCK, &u) < 0 && errno == EPERM);
|
||||
u = (struct mutex_args){0, 0};
|
||||
CHECK("mutex_unlock_einval", ioctl(m, NT_MUTEX_UNLOCK, &u) < 0 && errno == EINVAL);
|
||||
u = (struct mutex_args){7, 0};
|
||||
CHECK("mutex_unlock_prev", ioctl(m, NT_MUTEX_UNLOCK, &u) == 0 && u.count == 2);
|
||||
uint32_t who = 8;
|
||||
CHECK("mutex_kill_eperm", ioctl(m, NT_MUTEX_KILL, &who) < 0 && errno == EPERM);
|
||||
who = 7;
|
||||
CHECK("mutex_kill", ioctl(m, NT_MUTEX_KILL, &who) == 0);
|
||||
CHECK("mutex_read_dead", ioctl(m, NT_MUTEX_READ, &r) < 0 && errno == EOWNERDEAD && r.owner == 0 && r.count == 0);
|
||||
CHECK("mutex_abandoned", wait_on(NT_WAIT_ANY, &m, 1, 9, 0, 0, &idx) == EOWNERDEAD && idx == 0);
|
||||
CHECK("mutex_after_abandon", ioctl(m, NT_MUTEX_READ, &r) == 0 && r.owner == 9 && r.count == 1);
|
||||
close(m);
|
||||
}
|
||||
|
||||
static void events(void) {
|
||||
int a = event(0, 1), m = event(1, 0);
|
||||
struct event_args r;
|
||||
CHECK("auto_take", wait_on(NT_WAIT_ANY, &a, 1, 1, 0, 0, NULL) == 0);
|
||||
CHECK("auto_consumed", wait_on(NT_WAIT_ANY, &a, 1, 1, 0, 0, NULL) == ETIMEDOUT);
|
||||
CHECK("set_prev0", prev_of(m, NT_EVENT_SET, 0) == 0);
|
||||
CHECK("set_prev1", prev_of(m, NT_EVENT_SET, 0) == 1);
|
||||
CHECK("manual_kept", wait_on(NT_WAIT_ANY, &m, 1, 1, 0, 0, NULL) == 0 && wait_on(NT_WAIT_ANY, &m, 1, 1, 0, 0, NULL) == 0);
|
||||
CHECK("reset_prev", prev_of(m, NT_EVENT_RESET, 0) == 1);
|
||||
CHECK("pulse_prev", prev_of(m, NT_EVENT_PULSE, 0) == 0);
|
||||
CHECK("pulse_leaves_unsignaled", ioctl(m, NT_EVENT_READ, &r) == 0 && r.manual == 1 && r.signaled == 0);
|
||||
close(a);
|
||||
close(m);
|
||||
}
|
||||
|
||||
static void any_order(void) {
|
||||
int o[4] = {event(1, 0), sem(1, 5), event(1, 1), sem(0, 5)};
|
||||
int alert = event(0, 1);
|
||||
uint32_t idx;
|
||||
CHECK("any_lowest", wait_on(NT_WAIT_ANY, o, 4, 1, alert, 0, &idx) == 0 && idx == 1);
|
||||
CHECK("any_next", wait_on(NT_WAIT_ANY, o, 4, 1, alert, 0, &idx) == 0 && idx == 2);
|
||||
prev_of(o[2], NT_EVENT_RESET, 0);
|
||||
CHECK("any_alert", wait_on(NT_WAIT_ANY, o, 4, 1, alert, 0, &idx) == 0 && idx == 4);
|
||||
CHECK("any_alert_consumed", wait_on(NT_WAIT_ANY, o, 4, 1, alert, 0, NULL) == ETIMEDOUT);
|
||||
int dup[3] = {o[3], o[0], o[3]};
|
||||
prev_of(o[3], NT_SEM_RELEASE, 1);
|
||||
CHECK("any_duplicate_lowest", wait_on(NT_WAIT_ANY, dup, 3, 1, 0, 0, &idx) == 0 && idx == 0);
|
||||
int many[65];
|
||||
for (int i = 0; i < 65; i++) many[i] = o[0];
|
||||
CHECK("any_too_many", wait_on(NT_WAIT_ANY, many, 65, 1, 0, 0, NULL) == EINVAL);
|
||||
int badfd = 0;
|
||||
CHECK("any_invalid_fd", wait_on(NT_WAIT_ANY, &badfd, 1, 1, 0, 0, NULL) == EINVAL);
|
||||
CHECK("any_timeout", wait_on(NT_WAIT_ANY, o, 1, 1, 0, mono_ns(30), NULL) == ETIMEDOUT);
|
||||
for (int i = 0; i < 4; i++) close(o[i]);
|
||||
close(alert);
|
||||
}
|
||||
|
||||
static void all_semantics(void) {
|
||||
int s = sem(1, 5), e = event(0, 0), m = mutex(0, 0);
|
||||
int o[3] = {s, e, m};
|
||||
struct sem_args sr;
|
||||
uint32_t idx;
|
||||
CHECK("all_not_ready", wait_on(NT_WAIT_ALL, o, 3, 4, 0, 0, NULL) == ETIMEDOUT);
|
||||
CHECK("all_untouched", ioctl(s, NT_SEM_READ, &sr) == 0 && sr.count == 1);
|
||||
prev_of(e, NT_EVENT_SET, 0);
|
||||
CHECK("all_ready", wait_on(NT_WAIT_ALL, o, 3, 4, 0, 0, &idx) == 0 && idx == 0);
|
||||
CHECK("all_took_sem", ioctl(s, NT_SEM_READ, &sr) == 0 && sr.count == 0);
|
||||
int dup[2] = {s, s};
|
||||
CHECK("all_duplicate", wait_on(NT_WAIT_ALL, dup, 2, 4, 0, 0, NULL) == EINVAL);
|
||||
int alert = event(1, 1);
|
||||
CHECK("all_alert", wait_on(NT_WAIT_ALL, o, 3, 4, alert, 0, &idx) == 0 && idx == 3);
|
||||
close(s);
|
||||
close(e);
|
||||
close(m);
|
||||
close(alert);
|
||||
}
|
||||
|
||||
static int wake_obj;
|
||||
static uint32_t wake_index;
|
||||
static int wake_ret;
|
||||
static void *waiter(void *p) {
|
||||
int all = (int)(intptr_t)p;
|
||||
int objs[2] = {wake_obj, wake_obj + 0};
|
||||
wake_ret = wait_on(all ? NT_WAIT_ALL : NT_WAIT_ANY, objs, 1, 3, 0, UINT64_MAX, &wake_index);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void cross_thread(void) {
|
||||
wake_obj = event(0, 0);
|
||||
pthread_t t;
|
||||
pthread_create(&t, NULL, waiter, NULL);
|
||||
usleep(30000);
|
||||
prev_of(wake_obj, NT_EVENT_SET, 0);
|
||||
pthread_join(t, NULL);
|
||||
CHECK("thread_wake", wake_ret == 0 && wake_index == 0);
|
||||
struct event_args r;
|
||||
CHECK("thread_auto_reset", ioctl(wake_obj, NT_EVENT_READ, &r) == 0 && r.signaled == 0);
|
||||
close(wake_obj);
|
||||
int s = sem(0, 10);
|
||||
wake_obj = s;
|
||||
pthread_t ts[3];
|
||||
for (int i = 0; i < 3; i++) pthread_create(&ts[i], NULL, waiter, NULL);
|
||||
usleep(30000);
|
||||
CHECK("sem_release_three", prev_of(s, NT_SEM_RELEASE, 3) == 0);
|
||||
for (int i = 0; i < 3; i++) pthread_join(ts[i], NULL);
|
||||
struct sem_args sr;
|
||||
CHECK("sem_all_taken", ioctl(s, NT_SEM_READ, &sr) == 0 && sr.count == 0);
|
||||
close(s);
|
||||
}
|
||||
|
||||
static void cross_process(void) {
|
||||
int sv[2];
|
||||
CHECK("socketpair", socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == 0);
|
||||
int inherited = event(0, 0);
|
||||
pid_t pid = fork();
|
||||
if (pid == 0) {
|
||||
uint32_t idx;
|
||||
int r1 = wait_on(NT_WAIT_ANY, &inherited, 1, 5, 0, mono_ns(5000), &idx);
|
||||
char c;
|
||||
struct iovec io = {&c, 1};
|
||||
char cbuf[CMSG_SPACE(sizeof(int))];
|
||||
struct msghdr msg = {0};
|
||||
msg.msg_iov = &io;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = cbuf;
|
||||
msg.msg_controllen = sizeof(cbuf);
|
||||
int got = -1;
|
||||
if (recvmsg(sv[1], &msg, 0) == 1) memcpy(&got, CMSG_DATA(CMSG_FIRSTHDR(&msg)), sizeof(int));
|
||||
int r2 = wait_on(NT_WAIT_ANY, &got, 1, 5, 0, mono_ns(5000), NULL);
|
||||
_exit(r1 == 0 && r2 == 0 ? 0 : 1);
|
||||
}
|
||||
usleep(30000);
|
||||
prev_of(inherited, NT_EVENT_SET, 0);
|
||||
int sent = sem(0, 1);
|
||||
char c = 'x';
|
||||
struct iovec io = {&c, 1};
|
||||
char cbuf[CMSG_SPACE(sizeof(int))];
|
||||
struct msghdr msg = {0};
|
||||
msg.msg_iov = &io;
|
||||
msg.msg_iovlen = 1;
|
||||
msg.msg_control = cbuf;
|
||||
msg.msg_controllen = sizeof(cbuf);
|
||||
struct cmsghdr *cm = CMSG_FIRSTHDR(&msg);
|
||||
cm->cmsg_level = SOL_SOCKET;
|
||||
cm->cmsg_type = SCM_RIGHTS;
|
||||
cm->cmsg_len = CMSG_LEN(sizeof(int));
|
||||
memcpy(CMSG_DATA(cm), &sent, sizeof(int));
|
||||
sendmsg(sv[0], &msg, 0);
|
||||
usleep(30000);
|
||||
prev_of(sent, NT_SEM_RELEASE, 1);
|
||||
int status = 0;
|
||||
waitpid(pid, &status, 0);
|
||||
CHECK("process_wake", WIFEXITED(status) && WEXITSTATUS(status) == 0);
|
||||
close(inherited);
|
||||
close(sent);
|
||||
close(sv[0]);
|
||||
close(sv[1]);
|
||||
}
|
||||
|
||||
static int ping_obj, pong_obj, stress_sem;
|
||||
static void *stress_ponger(void *p) {
|
||||
long n = (long)p;
|
||||
uint32_t v;
|
||||
for (long i = 0; i < n; i++) {
|
||||
if (wait_on(NT_WAIT_ANY, &ping_obj, 1, 21, 0, UINT64_MAX, NULL) != 0) return (void *)1;
|
||||
ioctl(pong_obj, NT_EVENT_SET, &v);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
static void *stress_hammer(void *p) {
|
||||
long n = (long)p;
|
||||
for (long i = 0; i < n; i++) {
|
||||
if (wait_on(NT_WAIT_ANY, &stress_sem, 1, 22, 0, UINT64_MAX, NULL) != 0) return (void *)1;
|
||||
uint32_t c = 1;
|
||||
ioctl(stress_sem, NT_SEM_RELEASE, &c);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void stress(void) {
|
||||
long rounds = 20000;
|
||||
ping_obj = event(0, 0);
|
||||
pong_obj = event(0, 0);
|
||||
pthread_t t;
|
||||
void *bad = NULL;
|
||||
pthread_create(&t, NULL, stress_ponger, (void *)rounds);
|
||||
uint32_t v;
|
||||
int ok = 1;
|
||||
for (long i = 0; i < rounds && ok; i++) {
|
||||
ioctl(ping_obj, NT_EVENT_SET, &v);
|
||||
ok = wait_on(NT_WAIT_ANY, &pong_obj, 1, 20, 0, UINT64_MAX, NULL) == 0;
|
||||
}
|
||||
pthread_join(t, &bad);
|
||||
CHECK("stress_pingpong", ok && bad == NULL);
|
||||
stress_sem = sem(1, 1);
|
||||
pthread_t th[4];
|
||||
for (int i = 0; i < 4; i++) pthread_create(&th[i], NULL, stress_hammer, (void *)5000L);
|
||||
int hammer_ok = 1;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
pthread_join(th[i], &bad);
|
||||
hammer_ok &= bad == NULL;
|
||||
}
|
||||
struct sem_args sr;
|
||||
CHECK("stress_contended", hammer_ok && ioctl(stress_sem, NT_SEM_READ, &sr) == 0 && sr.count == 1);
|
||||
close(ping_obj);
|
||||
close(pong_obj);
|
||||
close(stress_sem);
|
||||
}
|
||||
|
||||
static int busy_obj;
|
||||
static volatile int handled, stop_worker;
|
||||
static sem_t parked, unpark;
|
||||
static void reentrant(int sig, siginfo_t *si, void *uc) {
|
||||
(void)sig; (void)si; (void)uc;
|
||||
uint32_t v = 0;
|
||||
ioctl(busy_obj, NT_EVENT_SET, &v);
|
||||
handled++;
|
||||
}
|
||||
static void suspending(int sig, siginfo_t *si, void *uc) {
|
||||
(void)sig; (void)si; (void)uc;
|
||||
sem_post(&parked);
|
||||
while (sem_wait(&unpark) != 0) {}
|
||||
handled++;
|
||||
}
|
||||
static void *worker(void *p) {
|
||||
(void)p;
|
||||
uint32_t v;
|
||||
while (!stop_worker) {
|
||||
ioctl(busy_obj, NT_EVENT_SET, &v);
|
||||
wait_on(NT_WAIT_ANY, &busy_obj, 1, 11, 0, 0, NULL);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void signals(void) {
|
||||
void *seen = NULL;
|
||||
busy_obj = event(0, 0);
|
||||
CHECK("install_reentrant", install_handler(SIGUSR1, reentrant, &seen) == 0);
|
||||
CHECK("query_original", seen == (void *)reentrant);
|
||||
pthread_t w;
|
||||
stop_worker = 0;
|
||||
handled = 0;
|
||||
pthread_create(&w, NULL, worker, NULL);
|
||||
for (int i = 0; i < 2000; i++) {
|
||||
pthread_kill(w, SIGUSR1);
|
||||
if (i % 64 == 0) usleep(100);
|
||||
}
|
||||
usleep(20000);
|
||||
stop_worker = 1;
|
||||
pthread_join(w, NULL);
|
||||
CHECK("reentrant_ran", handled > 0);
|
||||
sem_init(&parked, 0, 0);
|
||||
sem_init(&unpark, 0, 0);
|
||||
CHECK("install_suspending", install_handler(SIGUSR1, suspending, &seen) == 0);
|
||||
stop_worker = 0;
|
||||
handled = 0;
|
||||
pthread_create(&w, NULL, worker, NULL);
|
||||
uint32_t v;
|
||||
for (int i = 0; i < 300; i++) {
|
||||
pthread_kill(w, SIGUSR1);
|
||||
while (sem_wait(&parked) != 0) {}
|
||||
ioctl(busy_obj, NT_EVENT_SET, &v);
|
||||
wait_on(NT_WAIT_ANY, &busy_obj, 1, 12, 0, 0, NULL);
|
||||
sem_post(&unpark);
|
||||
}
|
||||
stop_worker = 1;
|
||||
pthread_join(w, NULL);
|
||||
CHECK("suspend_ran", handled == 300);
|
||||
close(busy_obj);
|
||||
}
|
||||
|
||||
static volatile int burst_count;
|
||||
static void bursting(int sig, siginfo_t *si, void *uc) {
|
||||
(void)sig; (void)si; (void)uc;
|
||||
uint32_t v = 0;
|
||||
ioctl(busy_obj, NT_EVENT_SET, &v);
|
||||
__atomic_add_fetch(&burst_count, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static void bursts(void) {
|
||||
void *seen = NULL;
|
||||
busy_obj = event(0, 0);
|
||||
for (int s = 0; s < 8; s++) CHECK("install_burst", install_handler(SIGRTMIN + s, bursting, &seen) == 0);
|
||||
pthread_t w;
|
||||
stop_worker = 0;
|
||||
burst_count = 0;
|
||||
pthread_create(&w, NULL, worker, NULL);
|
||||
union sigval val = {0};
|
||||
int sent = 0;
|
||||
for (int i = 0; i < 400; i++) {
|
||||
for (int s = 0; s < 8; s++)
|
||||
if (pthread_sigqueue(w, SIGRTMIN + s, val) == 0) sent++;
|
||||
usleep(200);
|
||||
}
|
||||
for (int i = 0; i < 2000 && __atomic_load_n(&burst_count, __ATOMIC_RELAXED) < sent; i++) usleep(1000);
|
||||
stop_worker = 1;
|
||||
pthread_join(w, NULL);
|
||||
CHECK("burst_all_handled", burst_count == sent && sent > 0);
|
||||
close(busy_obj);
|
||||
}
|
||||
|
||||
static volatile int oneshot_count;
|
||||
static void oneshot(int sig, siginfo_t *si, void *uc) {
|
||||
(void)sig; (void)si; (void)uc;
|
||||
__atomic_add_fetch(&oneshot_count, 1, __ATOMIC_RELAXED);
|
||||
}
|
||||
|
||||
static void oneshots(void) {
|
||||
busy_obj = event(0, 0);
|
||||
pthread_t w;
|
||||
stop_worker = 0;
|
||||
oneshot_count = 0;
|
||||
pthread_create(&w, NULL, worker, NULL);
|
||||
int fired = 0;
|
||||
for (int i = 0; i < 300; i++) {
|
||||
if (install_oneshot(SIGWINCH, oneshot) != 0) break;
|
||||
int before = __atomic_load_n(&oneshot_count, __ATOMIC_RELAXED);
|
||||
pthread_kill(w, SIGWINCH);
|
||||
fired++;
|
||||
for (int j = 0; j < 2000 && __atomic_load_n(&oneshot_count, __ATOMIC_RELAXED) == before; j++) usleep(50);
|
||||
}
|
||||
stop_worker = 1;
|
||||
pthread_join(w, NULL);
|
||||
CHECK("oneshot_handlers_run", oneshot_count == fired && fired == 300);
|
||||
close(busy_obj);
|
||||
}
|
||||
|
||||
static int outer_obj, inner_obj, other_dev, other_obj;
|
||||
static volatile int nested_ok, nested_done, outer_done;
|
||||
static void nesting(int sig, siginfo_t *si, void *uc) {
|
||||
(void)sig; (void)si; (void)uc;
|
||||
uint32_t idx = 99;
|
||||
int ok = wait_on(NT_WAIT_ANY, &inner_obj, 1, 21, 0, mono_ns(50), &idx) == 0 && idx == 0;
|
||||
struct wait_args w = {mono_ns(2), (uintptr_t)&other_obj, 1, 0xdead, 0, 22, 0, 0};
|
||||
ok = ok && ioctl(other_dev, NT_WAIT_ANY, &w) < 0 && errno == ETIMEDOUT;
|
||||
nested_ok += ok;
|
||||
__atomic_store_n(&nested_done, 1, __ATOMIC_RELEASE);
|
||||
}
|
||||
static void *outer_waiter(void *p) {
|
||||
struct wait_args w = {mono_ns(3000), (uintptr_t)&outer_obj, 1, 99, 0, 23, 0, 0};
|
||||
int r;
|
||||
do { r = ioctl(dev, NT_WAIT_ANY, &w); } while (r < 0 && errno == EINTR);
|
||||
*(int *)p = r == 0 && w.index == 0;
|
||||
__atomic_store_n(&outer_done, 1, __ATOMIC_RELEASE);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void nested_waits(void) {
|
||||
void *seen = NULL;
|
||||
other_dev = open("/dev/ntsync", O_RDWR | O_CLOEXEC);
|
||||
CHECK("second_device", other_dev >= 0);
|
||||
struct event_args ea = {0, 0};
|
||||
other_obj = ioctl(other_dev, NT_CREATE_EVENT, &ea);
|
||||
inner_obj = event(1, 1);
|
||||
CHECK("install_nesting", install_handler(SIGUSR2, nesting, &seen) == 0);
|
||||
int good = 0, early = 0;
|
||||
nested_ok = 0;
|
||||
for (int i = 0; i < 40; i++) {
|
||||
outer_obj = event(0, 0);
|
||||
int result = 0;
|
||||
pthread_t t;
|
||||
nested_done = outer_done = 0;
|
||||
pthread_create(&t, NULL, outer_waiter, &result);
|
||||
usleep(5000);
|
||||
pthread_kill(t, SIGUSR2);
|
||||
while (!__atomic_load_n(&nested_done, __ATOMIC_ACQUIRE)) usleep(200);
|
||||
usleep(5000);
|
||||
early += __atomic_load_n(&outer_done, __ATOMIC_ACQUIRE);
|
||||
uint32_t v = 0;
|
||||
ioctl(outer_obj, NT_EVENT_SET, &v);
|
||||
pthread_join(t, NULL);
|
||||
good += result;
|
||||
close(outer_obj);
|
||||
}
|
||||
CHECK("outer_wait_not_woken_by_nested_wait", early == 0);
|
||||
CHECK("outer_wait_survives_nested_waits", good == 40);
|
||||
CHECK("nested_waits_complete", nested_ok == 40);
|
||||
close(inner_obj);
|
||||
close(other_obj);
|
||||
close(other_dev);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
alarm(60);
|
||||
dev = open("/dev/ntsync", O_RDWR | O_CLOEXEC);
|
||||
if (dev < 0) {
|
||||
printf("no device %d\n", errno);
|
||||
return 1;
|
||||
}
|
||||
semaphores();
|
||||
mutexes();
|
||||
events();
|
||||
any_order();
|
||||
all_semantics();
|
||||
cross_thread();
|
||||
cross_process();
|
||||
stress();
|
||||
signals();
|
||||
bursts();
|
||||
oneshots();
|
||||
nested_waits();
|
||||
printf("done fails=%d\n", fails);
|
||||
return fails != 0;
|
||||
}
|
||||
"""
|
||||
|
||||
|
||||
class NtsyncPreloadTest(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
if not shutil.which("cc"):
|
||||
raise unittest.SkipTest("no compiler")
|
||||
cls.tmp = tempfile.TemporaryDirectory()
|
||||
tmp = Path(cls.tmp.name)
|
||||
(tmp / "ntdll.c").write_text(NTDLL)
|
||||
(tmp / "prog.c").write_text(PROGRAM)
|
||||
sources = sorted(str(p) for p in PRELOAD.glob("*.c"))
|
||||
subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-Wall", "-pthread", "-o", str(tmp / "libblsession.so"), *sources, "-ldl"],
|
||||
check=True)
|
||||
subprocess.run(["cc", "-shared", "-fPIC", "-O2", "-o", str(tmp / "ntdll.so"), str(tmp / "ntdll.c")], check=True)
|
||||
subprocess.run(["cc", "-O1", "-pthread", "-o", str(tmp / "prog"), str(tmp / "prog.c"), str(tmp / "ntdll.so"),
|
||||
"-Wl,-rpath," + str(tmp)], check=True)
|
||||
cls.program = tmp / "prog"
|
||||
cls.preload = tmp / "libblsession.so"
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
cls.tmp.cleanup()
|
||||
|
||||
def run_program(self):
|
||||
env = dict(os.environ, LD_PRELOAD=str(self.preload), BL_SYNC="1")
|
||||
return subprocess.run([str(self.program)], env=env, capture_output=True, text=True, timeout=90)
|
||||
|
||||
def test_emulation_matches_the_ntsync_driver(self):
|
||||
out = self.run_program()
|
||||
self.assertEqual(out.returncode, 0, out.stdout + out.stderr)
|
||||
self.assertIn("done fails=0", out.stdout)
|
||||
|
||||
def test_repeated_runs_stay_consistent(self):
|
||||
for _ in range(3):
|
||||
out = self.run_program()
|
||||
self.assertEqual(out.returncode, 0, out.stdout + out.stderr)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -66,6 +66,8 @@ static void send_toplevel_configure(struct surface *s) { (void)s; resizes++; }
|
||||
#define pointer_button(...) ((void)0)
|
||||
#define scroll_event(...) ((void)0)
|
||||
#define axis_event(...) ((void)0)
|
||||
#define stream_take(...) ((void)0)
|
||||
#define stream_forget_all(...) ((void)0)
|
||||
#define pointer_delta(...) ((void)0)
|
||||
#define deliver_touch(m) ((void)0)
|
||||
#define deliver_pointer(m) (pointers++)
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import hashlib
|
||||
import http.server
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import socket
|
||||
import subprocess
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
FETCH = ROOT / 'tools/packs/fetch-verified.sh'
|
||||
|
||||
|
||||
class PackDownloadsTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
self.root = Path(directory.name)
|
||||
self.cache = self.root / 'cache'
|
||||
self.cache.mkdir()
|
||||
self.destination = self.root / 'download'
|
||||
self.remote = self.root / 'remote'
|
||||
self.remote.write_bytes(b'verified input')
|
||||
self.checksum = hashlib.sha256(self.remote.read_bytes()).hexdigest()
|
||||
self.log = self.root / 'curl.log'
|
||||
tool = self.root / 'bin/curl'
|
||||
tool.parent.mkdir()
|
||||
tool.write_text('#!/usr/bin/env python3\nimport json,os,shutil,sys\n'
|
||||
'args=sys.argv[1:]\n'
|
||||
'with open(os.environ["CURL_LOG"],"a") as f: f.write(json.dumps(args)+"\\n")\n'
|
||||
'shutil.copyfile(os.environ["REMOTE"],args[args.index("-o")+1])\n')
|
||||
tool.chmod(0o755)
|
||||
self.env = dict(os.environ, DROIDDECK_PACK_CACHE=str(self.cache), CURL_LOG=str(self.log),
|
||||
REMOTE=str(self.remote), PATH=str(tool.parent) + os.pathsep + os.environ['PATH'])
|
||||
|
||||
def fetch(self, checksum=None, url='https://example.test/pinned', env=None):
|
||||
return subprocess.run(['bash', str(FETCH), url, checksum or self.checksum, str(self.destination)],
|
||||
env=env or self.env, capture_output=True, text=True)
|
||||
|
||||
def test_cold_download_then_warm_reuse_and_corruption_repair(self):
|
||||
self.assertEqual(self.fetch().returncode, 0)
|
||||
self.assertEqual(self.fetch().returncode, 0)
|
||||
self.assertEqual(len(self.log.read_text().splitlines()), 1)
|
||||
self.assertEqual(self.destination.read_bytes(), b'verified input')
|
||||
(self.cache / self.checksum).write_bytes(b'corrupt')
|
||||
self.assertEqual(self.fetch().returncode, 0)
|
||||
self.assertEqual(len(self.log.read_text().splitlines()), 2)
|
||||
self.assertEqual((self.cache / self.checksum).read_bytes(), b'verified input')
|
||||
|
||||
def test_directory_cache_entry_is_replaced_only_after_verification(self):
|
||||
entry = self.cache / self.checksum
|
||||
entry.mkdir()
|
||||
sentinel = entry / 'old-entry'
|
||||
sentinel.write_bytes(b'preserve until verified')
|
||||
self.remote.write_bytes(b'tampered download')
|
||||
self.assertNotEqual(self.fetch().returncode, 0)
|
||||
self.assertEqual(sentinel.read_bytes(), b'preserve until verified')
|
||||
self.assertFalse(self.destination.exists())
|
||||
self.remote.write_bytes(b'verified input')
|
||||
result = self.fetch()
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertTrue(entry.is_file())
|
||||
self.assertEqual(entry.read_bytes(), b'verified input')
|
||||
self.assertEqual(self.destination.read_bytes(), b'verified input')
|
||||
self.assertEqual(list(self.cache.iterdir()), [entry])
|
||||
self.assertEqual(self.fetch().returncode, 0)
|
||||
self.assertEqual(len(self.log.read_text().splitlines()), 2)
|
||||
|
||||
def test_changed_pin_cannot_reuse_old_bytes(self):
|
||||
self.assertEqual(self.fetch().returncode, 0)
|
||||
self.remote.write_bytes(b'new approved input')
|
||||
updated = hashlib.sha256(self.remote.read_bytes()).hexdigest()
|
||||
self.assertEqual(self.fetch(updated).returncode, 0)
|
||||
self.assertEqual(len(self.log.read_text().splitlines()), 2)
|
||||
self.assertEqual(self.destination.read_bytes(), b'new approved input')
|
||||
|
||||
def test_bad_download_is_not_cached_or_written(self):
|
||||
self.remote.write_bytes(b'tampered download')
|
||||
self.assertNotEqual(self.fetch().returncode, 0)
|
||||
self.assertFalse((self.cache / self.checksum).exists())
|
||||
self.assertFalse(self.destination.exists())
|
||||
self.assertEqual(list(self.cache.iterdir()), [])
|
||||
arguments = json.loads(self.log.read_text())
|
||||
self.assertIn('--retry-all-errors', arguments)
|
||||
self.assertIn('--max-time', arguments)
|
||||
self.assertIn('--retry-max-time', arguments)
|
||||
|
||||
def test_connection_reset_retries_then_verifies_real_download(self):
|
||||
if not shutil.which('curl'):
|
||||
self.skipTest('curl required for transport test')
|
||||
content = self.remote.read_bytes()
|
||||
attempts = []
|
||||
|
||||
class Handler(http.server.BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
attempts.append(True)
|
||||
if len(attempts) == 1:
|
||||
self.connection.shutdown(socket.SHUT_RDWR)
|
||||
self.connection.close()
|
||||
return
|
||||
self.send_response(200)
|
||||
self.send_header('Content-Length', str(len(content)))
|
||||
self.end_headers()
|
||||
self.wfile.write(content)
|
||||
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
server = http.server.ThreadingHTTPServer(('127.0.0.1', 0), Handler)
|
||||
thread = threading.Thread(target=server.serve_forever, daemon=True)
|
||||
thread.start()
|
||||
try:
|
||||
env = dict(self.env, PATH=os.environ['PATH'])
|
||||
result = self.fetch(url=f'http://127.0.0.1:{server.server_port}/input', env=env)
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
self.assertGreaterEqual(len(attempts), 2)
|
||||
self.assertEqual(self.destination.read_bytes(), content)
|
||||
finally:
|
||||
server.shutdown()
|
||||
server.server_close()
|
||||
thread.join()
|
||||
@@ -0,0 +1,187 @@
|
||||
import copy
|
||||
import importlib.util
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tarfile
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
SPEC = importlib.util.spec_from_file_location('preload_snapshots', Path(__file__).resolve().parents[1] / 'components/preloads.py')
|
||||
snapshots = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(snapshots)
|
||||
|
||||
|
||||
def archive(files):
|
||||
stream = io.BytesIO()
|
||||
with tarfile.open(fileobj=stream, mode='w:gz') as tar:
|
||||
for name, content in files.items():
|
||||
entry = tarfile.TarInfo(name)
|
||||
entry.size = len(content)
|
||||
tar.addfile(entry, io.BytesIO(content))
|
||||
return stream.getvalue()
|
||||
|
||||
|
||||
class PreloadSnapshotTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(directory.cleanup)
|
||||
self.root = Path(directory.name)
|
||||
# Real repository inputs exercise the transitive include walker and build recipe.
|
||||
for group in snapshots.INPUTS:
|
||||
for name in snapshots.source_files(group):
|
||||
if name.startswith('@'):
|
||||
continue
|
||||
target = self.root / name
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes((snapshots.ROOT / name).read_bytes())
|
||||
recipe = 'tools/components/build-arm64-preloads.sh'
|
||||
(self.root / recipe).parent.mkdir(parents=True, exist_ok=True)
|
||||
(self.root / recipe).write_text((snapshots.ROOT / recipe).read_text())
|
||||
x86 = 'tools/components/recipes/x86-preloads.sh'
|
||||
(self.root / x86).parent.mkdir(parents=True, exist_ok=True)
|
||||
(self.root / x86).write_text((snapshots.ROOT / x86).read_text())
|
||||
(self.root / '.github/workflows').mkdir(parents=True)
|
||||
(self.root / '.github/workflows/build.yml').write_text((snapshots.ROOT / '.github/workflows/build.yml').read_text())
|
||||
self.git('init', '-q')
|
||||
self.git('config', 'core.autocrlf', 'false')
|
||||
self.git('config', 'user.name', 'Test Developer')
|
||||
self.git('config', 'user.email', 'test@example.test')
|
||||
self.git('add', '.')
|
||||
self.binaries = {name: ('verified-' + name).encode() for name in snapshots.FILES}
|
||||
self.content = archive(self.binaries)
|
||||
self.data = dict(version=1, origin=dict(run=123, commit='abc', artifact=456, artifact_sha256='0' * 64),
|
||||
groups={g: snapshots.source_files(g, self.root) for g in snapshots.INPUTS},
|
||||
arm64_recipe=snapshots.recipe(self.root), x86_recipe=snapshots.x86_recipe(self.root),
|
||||
archive_sha256=snapshots.sha(self.content),
|
||||
outputs={name: snapshots.sha(value) for name, value in self.binaries.items()})
|
||||
(self.root / snapshots.LOCK).write_text(json.dumps(self.data))
|
||||
self.git('add', '.')
|
||||
self.git('commit', '-qm', 'Approved baseline')
|
||||
self.base = self.git('rev-parse', 'HEAD').strip()
|
||||
|
||||
def git(self, *args):
|
||||
return subprocess.check_output(['git', *args], cwd=self.root, text=True)
|
||||
|
||||
def restore(self, base=None):
|
||||
with patch.dict(os.environ, COMPONENT_TRUSTED_BASE=base or self.base, FORCE_PRELOAD_REBUILD='false'), \
|
||||
patch.object(snapshots.urllib.request, 'urlopen', return_value=io.BytesIO(self.content)) as fetch, \
|
||||
patch.object(snapshots, 'prove_origin') as prove:
|
||||
result = snapshots.restore(self.root)
|
||||
return result, fetch, prove
|
||||
|
||||
def test_reviewed_unchanged_binaries_reused_and_written(self):
|
||||
result, fetch, prove = self.restore()
|
||||
self.assertEqual(result, dict(arm64=True, x86=True))
|
||||
prove.assert_not_called()
|
||||
fetch.assert_called_once()
|
||||
for name, value in self.binaries.items():
|
||||
self.assertEqual((self.root / 'app/src/main/assets/linuxfs' / name).read_bytes(), value)
|
||||
|
||||
def test_changed_common_source_requires_both_rebuilds(self):
|
||||
path = self.root / snapshots.COMMON[0]
|
||||
path.write_text(path.read_text() + '\n// Changed source\n')
|
||||
result, fetch, prove = self.restore()
|
||||
self.assertEqual(result, dict(arm64=False, x86=False))
|
||||
fetch.assert_not_called()
|
||||
prove.assert_not_called()
|
||||
|
||||
def test_new_transitive_header_is_an_input(self):
|
||||
source = self.root / snapshots.COMMON[0]
|
||||
source.write_text(source.read_text() + '\n#include "new-header.h"\n')
|
||||
header = source.with_name('new-header.h')
|
||||
header.write_text('#define VALUE 1\n')
|
||||
before = snapshots.source_files('arm64', self.root)
|
||||
header.write_text('#define VALUE 2\n')
|
||||
self.assertNotEqual(before, snapshots.source_files('arm64', self.root))
|
||||
|
||||
def test_changed_recipe_rebuilds_arm64_only(self):
|
||||
script = self.root / 'tools/components/build-arm64-preloads.sh'
|
||||
script.write_text(script.read_text().replace('-O2', '-O3'))
|
||||
result, _, _ = self.restore()
|
||||
self.assertEqual(result, dict(arm64=False, x86=True))
|
||||
|
||||
def test_shell_newline_changes_invalidate_the_recipe(self):
|
||||
script = self.root / 'tools/components/build-arm64-preloads.sh'
|
||||
original = snapshots.recipe(self.root)
|
||||
text = script.read_text()
|
||||
script.write_text(text.replace('-ldl\n', '-ldl ', 1))
|
||||
self.assertNotEqual(original, snapshots.recipe(self.root))
|
||||
|
||||
def test_x86_container_recipe_changes_rebuild_x86_only(self):
|
||||
script = self.root / 'tools/components/recipes/x86-preloads.sh'
|
||||
script.write_text(script.read_text().replace('debian:bullseye', 'debian:bookworm'))
|
||||
result, _, _ = self.restore()
|
||||
self.assertEqual(result, dict(arm64=True, x86=False))
|
||||
|
||||
def test_new_manifest_requires_main_build_proof(self):
|
||||
result, _, prove = self.restore('HEAD~1')
|
||||
self.assertTrue(all(result.values()))
|
||||
prove.assert_called_once()
|
||||
|
||||
def test_forged_binary_hash_cannot_prove_main_origin(self):
|
||||
data = copy.deepcopy(self.data)
|
||||
data['outputs']['libblsession.so'] = 'f' * 64
|
||||
with patch.object(snapshots, 'artifact_bytes', return_value=self.binaries):
|
||||
with self.assertRaisesRegex(ValueError, 'original main APK'):
|
||||
snapshots.prove_origin(data, self.root / 'cache', self.root)
|
||||
|
||||
def test_modified_input_policy_cannot_omit_producer_dependencies(self):
|
||||
data = copy.deepcopy(self.data)
|
||||
data['origin']['commit'] = self.base
|
||||
omitted = snapshots.COMMON[0]
|
||||
del data['groups']['arm64'][omitted]
|
||||
with patch.object(snapshots, 'artifact_bytes', return_value=self.binaries), \
|
||||
patch.object(snapshots, 'run', return_value=b''), \
|
||||
patch.object(snapshots, 'source_files', side_effect=lambda group, *args: data['groups'][group]), \
|
||||
patch.object(snapshots, 'producer_sources', return_value={omitted: self.data['groups']['arm64'][omitted]}):
|
||||
with self.assertRaisesRegex(ValueError, 'producing build dependency'):
|
||||
snapshots.prove_origin(data, self.root / 'cache', self.root)
|
||||
|
||||
def test_non_main_or_unsuccessful_run_cannot_prove_origin(self):
|
||||
build = dict(event='pull_request', head_branch='main', conclusion='success', head_sha='abc',
|
||||
path='.github/workflows/build.yml', repository=dict(full_name=snapshots.REPO))
|
||||
for field, value in [('event', 'pull_request'), ('head_branch', 'feature'), ('conclusion', 'failure')]:
|
||||
candidate = dict(build, event='push')
|
||||
candidate[field] = value
|
||||
with self.subTest(field=field), patch.object(snapshots, 'api', return_value=candidate):
|
||||
with self.assertRaisesRegex(ValueError, 'successful main'):
|
||||
snapshots.artifact_bytes(self.data['origin'], self.root / 'cache')
|
||||
|
||||
def test_corrupt_archive_is_rejected(self):
|
||||
with self.assertRaisesRegex(ValueError, 'checksum'):
|
||||
snapshots.unpack(self.content + b'tampered', self.data)
|
||||
|
||||
def test_missing_duplicate_or_traversal_entries_are_rejected(self):
|
||||
for files in ({}, {'../escaped': b'bad'}, {'libblsession.so': b'wrong'}):
|
||||
content = archive(files)
|
||||
data = dict(self.data, archive_sha256=snapshots.sha(content))
|
||||
with self.subTest(names=list(files)), self.assertRaises(ValueError):
|
||||
snapshots.unpack(content, data)
|
||||
|
||||
def test_missing_release_rebuilds_without_accepting_unverified_bytes(self):
|
||||
error = snapshots.urllib.error.HTTPError('https://example.test', 404, 'missing', {}, None)
|
||||
with patch.dict(os.environ, COMPONENT_TRUSTED_BASE=self.base), \
|
||||
patch.object(snapshots.urllib.request, 'urlopen', side_effect=error):
|
||||
self.assertEqual(snapshots.restore(self.root), dict(arm64=False, x86=False))
|
||||
|
||||
def test_transient_download_failure_rebuilds_but_integrity_errors_fail(self):
|
||||
errors = [TimeoutError('network'), snapshots.http.client.IncompleteRead(b'partial'),
|
||||
snapshots.urllib.error.HTTPError('https://example.test', 503, 'unavailable', {}, None)]
|
||||
for error in errors:
|
||||
with self.subTest(error=type(error).__name__), patch.dict(os.environ, COMPONENT_TRUSTED_BASE=self.base), \
|
||||
patch.object(snapshots.urllib.request, 'urlopen', side_effect=error):
|
||||
self.assertEqual(snapshots.restore(self.root), dict(arm64=False, x86=False))
|
||||
with patch.dict(os.environ, COMPONENT_TRUSTED_BASE=self.base), \
|
||||
patch.object(snapshots.urllib.request, 'urlopen', return_value=io.BytesIO(b'corrupt')):
|
||||
with self.assertRaisesRegex(ValueError, 'checksum'):
|
||||
snapshots.restore(self.root)
|
||||
|
||||
def test_manual_rebuild_does_not_download_snapshot(self):
|
||||
with patch.dict(os.environ, FORCE_PRELOAD_REBUILD='true'), \
|
||||
patch.object(snapshots.urllib.request, 'urlopen') as fetch:
|
||||
self.assertEqual(snapshots.restore(self.root), dict(arm64=False, x86=False))
|
||||
fetch.assert_not_called()
|
||||
@@ -0,0 +1,91 @@
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
TOOLS = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(TOOLS))
|
||||
from proot_profile import report
|
||||
|
||||
PROGRAM = r'''
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#define PR_NB_SYSNUM 2
|
||||
#define PR_void 0
|
||||
static const char *stringify_sysnum(unsigned nr) { return nr ? "openat" : "void"; }
|
||||
#include "profile.h"
|
||||
int main(void) {
|
||||
errno = EBUSY;
|
||||
if (!dd_profile_enabled()) return errno != EBUSY;
|
||||
if (errno != EBUSY) return 1;
|
||||
for (int i = 0; i < 40; i++) {
|
||||
uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
struct timespec wait = {0, 2000000};
|
||||
nanosleep(&wait, 0);
|
||||
errno = ENOENT;
|
||||
dd_profile_record(1, 1, 123, wall, cpu);
|
||||
if (errno != ENOENT) return 2;
|
||||
if (i == 9) dd_profile_flush();
|
||||
}
|
||||
dd_profile_next = 0;
|
||||
uint64_t wall = dd_profile_clock(CLOCK_MONOTONIC);
|
||||
uint64_t cpu = dd_profile_clock(CLOCK_THREAD_CPUTIME_ID);
|
||||
struct timespec wait = {0, 2000000};
|
||||
nanosleep(&wait, 0);
|
||||
dd_profile_record(1, 0, 123, wall, cpu);
|
||||
return 0;
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class ProotProfileTest(unittest.TestCase):
|
||||
def test_snapshots_replace_instead_of_adding_and_tracers_remain_separate(self):
|
||||
with tempfile.TemporaryDirectory() as work:
|
||||
path = Path(work) / 'session.log'
|
||||
records = [dict(type='total', tracer=1, id=2, syscall='statx', stage='enter',
|
||||
calls=n, wall_ns=n * 100, cpu_ns=n * 10, max_ns=100) for n in (3, 8)]
|
||||
records.append(dict(records[-1], tracer=2, calls=2))
|
||||
records += [dict(type='total', tracer=1, id=3, syscall='openat', stage='enter',
|
||||
calls=1, wall_ns=1000, cpu_ns=1000, max_ns=1000)]
|
||||
path.write_text('unrelated log\n' + ''.join('prefix proot-profile ' + json.dumps(r) + '\n' for r in records)
|
||||
+ 'proot-profile {truncated\n' + 'proot-profile []\n')
|
||||
result = report(path)
|
||||
self.assertEqual(11, result['handlerCalls'])
|
||||
self.assertEqual(3, result['tracers'])
|
||||
self.assertEqual(2, result['malformedRecords'])
|
||||
self.assertEqual('statx', result['totals'][0]['syscall'])
|
||||
self.assertEqual('openat', report(path, 'cpu')['totals'][0]['syscall'])
|
||||
|
||||
def test_empty_logs_do_not_claim_profiling_ran(self):
|
||||
with tempfile.TemporaryDirectory() as work:
|
||||
path = Path(work) / 'session.log'
|
||||
path.write_text('ordinary log\n')
|
||||
self.assertFalse(report(path)['hasCounters'])
|
||||
|
||||
@unittest.skipUnless(shutil.which('cc'), 'C compiler required')
|
||||
def test_real_clocks_bounded_samples_errno_and_periodic_counters(self):
|
||||
with tempfile.TemporaryDirectory() as work:
|
||||
source = Path(work) / 'profile.c'
|
||||
binary = Path(work) / 'profile'
|
||||
source.write_text(PROGRAM)
|
||||
subprocess.run(['cc', '-Wall', '-Wextra', '-Werror', '-std=c99', '-I', str(TOOLS / 'proot'),
|
||||
str(source), '-o', str(binary)], check=True)
|
||||
for setting in ('0', ''):
|
||||
result = subprocess.run([binary], env=dict(os.environ, PROOT_PROFILE=setting), capture_output=True, check=True)
|
||||
self.assertEqual(b'', result.stderr)
|
||||
result = subprocess.run([binary], env=dict(os.environ, PROOT_PROFILE='1', PROOT_PROFILE_SLOW_US='1'),
|
||||
capture_output=True, check=True)
|
||||
rows = [json.loads(line.split(b'proot-profile ', 1)[1]) for line in result.stderr.splitlines()]
|
||||
self.assertEqual(33, sum(row['type'] == 'slow' for row in rows))
|
||||
self.assertEqual(32, sum(row['type'] == 'slow' and row['stage'] == 'enter' for row in rows))
|
||||
self.assertGreater(sum(row['type'] == 'total' for row in rows), 2)
|
||||
log = Path(work) / 'session.log'
|
||||
log.write_bytes(result.stderr)
|
||||
counters = report(log)
|
||||
self.assertEqual(41, counters['handlerCalls'])
|
||||
self.assertGreater(counters['handlerWallNs'], counters['handlerCpuNs'])
|
||||
self.assertEqual(40, counters['totals'][0]['calls'])
|
||||
@@ -45,6 +45,26 @@ VULKAN_SCRIPT = r'''"InstallScript"
|
||||
'''
|
||||
|
||||
|
||||
UBISOFT_SCRIPT = r'''"installscript"
|
||||
{
|
||||
"Run Process"
|
||||
{
|
||||
"Ubisoft Connect PC Client"
|
||||
{
|
||||
"process 1" "%INSTALLDIR%\\UbisoftConnectInstaller.exe"
|
||||
"command 1" "/S"
|
||||
}
|
||||
"easyanticheat"
|
||||
{
|
||||
"HasRunKey" "HKEY_CURRENT_USER\\SOFTWARE\\Ubisoft\\WatchDogs2EAC"
|
||||
"process 1" "%INSTALLDIR%\\EasyAntiCheat\\InstallWD2EAC.cmd"
|
||||
"command 1" ""
|
||||
}
|
||||
}
|
||||
}
|
||||
'''
|
||||
|
||||
|
||||
class SeedRedistsTest(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.tmp = Path(tempfile.mkdtemp())
|
||||
@@ -353,5 +373,33 @@ class SeedRedistsTest(unittest.TestCase):
|
||||
self.assertEqual(self.reg.read_text().count('"Vulkan111080"'), 2)
|
||||
|
||||
|
||||
def ubisoft(self):
|
||||
script = self.tmp / "legacycompat/evaluatorscript_447040.vdf"
|
||||
script.parent.mkdir(parents=True)
|
||||
script.write_text('"evaluatorscript"\n{\n\t"appid"\t\t"447040"\n\t"1"\n'
|
||||
+ "\n".join("\t" + line for line in UBISOFT_SCRIPT.splitlines()) + "\n}\n")
|
||||
env = dict(os.environ, DROIDDECK_LIBRARIES="", DROIDDECK_SEED_SCRIPTS=str(script))
|
||||
return subprocess.run(["bash", str(SCRIPT), str(self.steam)], env=env, capture_output=True, text=True, check=True)
|
||||
|
||||
def test_the_ubisoft_connect_installer_is_left_to_run(self):
|
||||
self.ubisoft()
|
||||
self.assertIn('"easyanticheat"=dword:00000001', self.user.read_text())
|
||||
self.assertNotIn("Ubisoft Connect PC Client", self.reg.read_text())
|
||||
self.assertNotIn("Ubisoft Connect PC Client", (self.reg.parent / ".droiddeck-redists").read_text())
|
||||
|
||||
def test_a_ubisoft_connect_marker_an_earlier_seeding_wrote_comes_out(self):
|
||||
marker = "HKEY_LOCAL_MACHINE\\\\Software\\\\Valve\\\\Steam\\\\Apps\\\\447040\tUbisoft Connect PC Client"
|
||||
self.reg.write_text(
|
||||
"WINE REGISTRY Version 2\n"
|
||||
"\n[Software\\\\Valve\\\\Steam\\\\Apps\\\\447040] 1791729070\n"
|
||||
'"Ubisoft Connect PC Client"=dword:00000001\n'
|
||||
"\n[Software\\\\Wow6432Node\\\\Valve\\\\Steam\\\\Apps\\\\447040] 1791729070\n"
|
||||
'"Ubisoft Connect PC Client"=dword:00000001\n')
|
||||
(self.reg.parent / ".droiddeck-redists").write_text(marker + "\n")
|
||||
result = self.ubisoft()
|
||||
self.assertNotIn("Ubisoft Connect PC Client", self.reg.read_text())
|
||||
self.assertNotIn("Ubisoft Connect PC Client", (self.reg.parent / ".droiddeck-redists").read_text())
|
||||
self.assertIn("Ubisoft Connect markers out", result.stdout)
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,4 +1,4 @@
|
||||
"""The XTest cursor path is enabled only for Steam sessions."""
|
||||
"""Gamescope composites the cursor only when a Steam session asks for it."""
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
@@ -8,29 +8,37 @@ import unittest
|
||||
SESSION = Path(__file__).resolve().parents[1] / 'linuxfs/overlay/usr/local/bin/droiddeck-session'
|
||||
SOURCE = SESSION.read_text()
|
||||
MATCH = re.search(
|
||||
r'^ if \[ "\$mode" = steam \]; then\n.*?^ fi\n', SOURCE, re.M | re.S)
|
||||
r'^ if \[ "\$mode" = steam \] && \[ "\$\{BL_CURSOR_COMPOSITE:-0\}" = 1 \]; then\n.*?^ fi\n',
|
||||
SOURCE, re.M | re.S)
|
||||
assert MATCH is not None
|
||||
CURSOR_SETUP = MATCH.group(0)
|
||||
|
||||
|
||||
class SessionCursorRoutingTest(unittest.TestCase):
|
||||
def run_setup(self, mode, initial=None):
|
||||
def run_setup(self, mode, initial=None, composite=None):
|
||||
env = dict(os.environ, mode=mode)
|
||||
if initial is not None:
|
||||
env['gamescope_cursor_composite'] = initial
|
||||
else:
|
||||
env.pop('gamescope_cursor_composite', None)
|
||||
if composite is not None:
|
||||
env['BL_CURSOR_COMPOSITE'] = composite
|
||||
else:
|
||||
env.pop('BL_CURSOR_COMPOSITE', None)
|
||||
result = subprocess.run(
|
||||
['bash', '-c', CURSOR_SETUP + 'printf "%s\n" "${gamescope_cursor_composite-}"'],
|
||||
env=env, text=True, capture_output=True, check=True)
|
||||
return result.stdout.strip()
|
||||
|
||||
def test_steam_enables_manual_composition_for_the_nested_cursor(self):
|
||||
self.assertEqual('2', self.run_setup('steam'))
|
||||
def test_steam_leaves_the_cursor_with_the_host_unless_asked(self):
|
||||
self.assertEqual('', self.run_setup('steam'))
|
||||
|
||||
def test_steam_composites_the_cursor_when_the_setting_is_on(self):
|
||||
self.assertEqual('2', self.run_setup('steam', composite='1'))
|
||||
|
||||
def test_other_sessions_keep_their_existing_cursor_composition(self):
|
||||
self.assertEqual('', self.run_setup('desktop'))
|
||||
self.assertEqual('1', self.run_setup('run', '1'))
|
||||
self.assertEqual('', self.run_setup('desktop', composite='1'))
|
||||
self.assertEqual('1', self.run_setup('run', '1', composite='1'))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -22,7 +22,7 @@ PACKAGES = [line.split()[1] for line in VARIANTS.read_text().splitlines()
|
||||
def guest_prefix(package):
|
||||
source = SERVICE.read_text()
|
||||
before_environment = source.split("val guest = ArrayList<String>()", 1)[1].split(
|
||||
"addClientEnvironment(guest, steamHere)", 1)[0]
|
||||
"addClientEnvironment(guest,", 1)[0]
|
||||
environment = source.split("private fun addClientEnvironment(", 1)[1].split(
|
||||
'guest.add("HOME=/root")', 1)[0]
|
||||
prefix = []
|
||||
|
||||
@@ -45,6 +45,68 @@ class SteamCompatEnvironmentTest(unittest.TestCase):
|
||||
client_path += ':' + inherited['LD_LIBRARY_PATH']
|
||||
self.assertEqual(result.stdout.splitlines(), ['1', client_path])
|
||||
|
||||
def test_session_exit_stops_the_library_helper(self):
|
||||
source = (BIN / 'droiddeck-session').read_text()
|
||||
launch = next(line for line in source.splitlines()
|
||||
if 'droiddeck-steam-compat "$steam_root"' in line)
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
pid = root / 'pid'
|
||||
helper = root / 'droiddeck-steam-compat'
|
||||
helper.write_text('#!/bin/sh\necho $$ > "$PID_FILE"\nexec sleep 30\n')
|
||||
helper.chmod(0o755)
|
||||
env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'],
|
||||
PID_FILE=str(pid), steam_root='/steam', steam_x64='0')
|
||||
subprocess.run(['bash', '-c', '_bl_compat_env=(env)\n' + launch + '\n'
|
||||
'until [ -s "$PID_FILE" ]; do sleep 0.05; done\n'
|
||||
'kill $(jobs -p)\nwait'],
|
||||
env=env, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=10)
|
||||
helper_pid = int(pid.read_text())
|
||||
try:
|
||||
os.kill(helper_pid, 0)
|
||||
except ProcessLookupError:
|
||||
return
|
||||
os.kill(helper_pid, 9)
|
||||
self.fail('droiddeck-steam-compat outlived the session')
|
||||
|
||||
def test_the_x86_64_client_gets_only_the_file_dialog_bridge(self):
|
||||
source = (BIN / 'droiddeck-session').read_text()
|
||||
start = source.index(' if [ "$steam_x64" = 1 ]; then\n { droiddeck-steam-compat --files-only')
|
||||
block = source[start:source.index(' fi\n', start) + len(' fi\n')]
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
helper = root / 'droiddeck-steam-compat'
|
||||
helper.write_text('#!/bin/sh\necho "$@" >> "$ARGS_FILE"\n')
|
||||
helper.chmod(0o755)
|
||||
for x64, expected in (('1', '--files-only /steam'), ('0', '/steam')):
|
||||
with self.subTest(x64=x64):
|
||||
args = root / ('args-' + x64)
|
||||
env = dict(os.environ, PATH=str(root) + os.pathsep + os.environ['PATH'],
|
||||
ARGS_FILE=str(args), steam_root='/steam', steam_x64=x64)
|
||||
subprocess.run(['bash', '-c', '_bl_compat_env=(env)\n' + block + 'wait\n'], env=env, timeout=10, check=True)
|
||||
self.assertEqual(args.read_text().split('\n')[0], expected)
|
||||
|
||||
def test_files_only_mode_installs_only_the_file_dialog_hook(self):
|
||||
import runpy
|
||||
compat = runpy.run_path(str(BIN / 'droiddeck-steam-compat'))
|
||||
calls = []
|
||||
|
||||
class Page:
|
||||
def __init__(self, port, path):
|
||||
self.ws = None
|
||||
def evaluate(self, expression):
|
||||
calls.append(('evaluate', expression[:40]))
|
||||
return True
|
||||
def call(self, method, params):
|
||||
calls.append((method, params['name']))
|
||||
|
||||
helper = compat['Helper']('/steam', 1234, files_only=True)
|
||||
helper.attach.__globals__.update(shared_context=lambda port: '/devtools/page/1', Page=Page)
|
||||
self.assertTrue(helper.attach())
|
||||
bindings = [name for method, name in calls if method == 'Runtime.addBinding']
|
||||
self.assertEqual(bindings, [compat['FILE_BINDING']])
|
||||
self.assertIn(('evaluate', compat['FILE_JS'][:40]), calls)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -641,6 +641,114 @@ class ReconcileTest(unittest.TestCase):
|
||||
self.assertEqual(page.mapping["10"], "GE-Proton9-1")
|
||||
self.assertEqual(state["auto"], {"11": TOOL})
|
||||
|
||||
def games(self):
|
||||
return json.loads((self.state / "games.json").read_text())["games"]
|
||||
|
||||
def write_games(self, games):
|
||||
(self.state / "games.json").write_text(json.dumps({"version": 1, "games": games}))
|
||||
|
||||
def test_a_steam_pick_after_the_app_choice_is_kept_live(self):
|
||||
page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [("10", TOOL_11)])
|
||||
self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
|
||||
page.sets.clear()
|
||||
page.mapping["10"] = COMPAT["FEX_TOOL"]
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(page.mapping["10"], COMPAT["FEX_TOOL"])
|
||||
self.assertEqual(self.games(), {})
|
||||
self.assertEqual(state["games_applied"], {})
|
||||
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [("10", TOOL_11)])
|
||||
|
||||
def test_a_steam_pick_of_our_proton_becomes_the_app_choice_live(self):
|
||||
page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11])
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
self.reconcile(page)
|
||||
page.sets.clear()
|
||||
page.mapping["10"] = TOOL
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(self.games(), {"10": {"valve": True, "dir": "Proton Experimental (ARM64)"}})
|
||||
self.assertEqual(state["games_applied"], self.games())
|
||||
|
||||
def test_use_the_default_applies_once_then_steam_picks_stand_live(self):
|
||||
page = FakePage({"0": TOOL, "10": TOOL_11, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
|
||||
self.write_games({"10": None})
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [("10", TOOL)])
|
||||
|
||||
page.sets.clear()
|
||||
self.reconcile(page)
|
||||
self.assertEqual(self.games(), {})
|
||||
page.mapping["10"] = COMPAT["FEX_TOOL"]
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(page.mapping["10"], COMPAT["FEX_TOOL"])
|
||||
|
||||
def test_choices_an_earlier_build_applied_give_way_to_steam_picks_live(self):
|
||||
(self.state / "state.json").write_text(json.dumps({"default": TOOL, "auto": {"11": TOOL}, "tools": []}))
|
||||
self.write_games({"10": None, "11": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
page = FakePage({"0": TOOL, "10": COMPAT["FEX_TOOL"], "11": "steamlinuxruntime_sniper"},
|
||||
[TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(self.games(), {})
|
||||
|
||||
def test_an_app_choice_written_during_a_sync_is_not_overwritten(self):
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
requests, text = COMPAT["read_game_requests"]()
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton Experimental (ARM64)"}})
|
||||
self.assertFalse(COMPAT["write_game_requests"]({}, text))
|
||||
self.assertEqual(self.games(), {"10": {"valve": True, "dir": "Proton Experimental (ARM64)"}})
|
||||
|
||||
def test_an_app_the_client_briefly_refuses_keeps_its_applied_choice_live(self):
|
||||
page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
self.reconcile(page)
|
||||
page.refused = {"10"}
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
page.refused = set()
|
||||
page.sets.clear()
|
||||
page.mapping["10"] = COMPAT["FEX_TOOL"]
|
||||
self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(page.mapping["10"], COMPAT["FEX_TOOL"])
|
||||
|
||||
def test_an_app_rewriting_its_choices_during_both_tries_applies_none_of_them_live(self):
|
||||
page = FakePage({"0": TOOL, "10": TOOL, "11": TOOL}, [TOOL, TOOL_11, COMPAT["FEX_TOOL"]])
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
self.reconcile(page)
|
||||
page.sets.clear()
|
||||
page.mapping["10"] = COMPAT["FEX_TOOL"]
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}, "11": None})
|
||||
with mock.patch.dict(COMPAT["settled_game_requests"].__globals__, write_game_requests=lambda *_: False):
|
||||
state = self.reconcile(page)
|
||||
self.assertEqual(page.sets, [])
|
||||
self.assertEqual(state["games_applied"], {"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
|
||||
def test_a_steam_pick_is_kept_at_the_next_start(self):
|
||||
config = self.steam / "config/config.vdf"
|
||||
config.parent.mkdir(parents=True)
|
||||
vdf = '"InstallConfigStore" { "Software" { "Valve" { "Steam" { "CompatToolMapping" { %s } } } } }'
|
||||
entry = '"%s" { "name" "%s" "config" "" "priority" "250" }'
|
||||
catalog = COMPAT["tool_catalog"](str(self.steam))
|
||||
self.write_games({"10": {"valve": True, "dir": "Proton 11.0 (ARM64)"}})
|
||||
config.write_text(vdf % (entry % ("0", TOOL) + entry % ("10", TOOL)))
|
||||
with mock.patch.dict(COMPAT["register_default"].__globals__, steam_running=lambda: False):
|
||||
COMPAT["register_default"](str(config), ["10"], catalog=catalog, directory=str(self.state), settle=True)
|
||||
self.assertIn(entry % ("10", TOOL_11), " ".join(config.read_text().split()))
|
||||
config.write_text(vdf % (entry % ("0", TOOL) + entry % ("10", COMPAT["FEX_TOOL"])))
|
||||
COMPAT["register_default"](str(config), ["10"], catalog=catalog, directory=str(self.state), settle=True)
|
||||
self.assertIn(entry % ("10", COMPAT["FEX_TOOL"]), " ".join(config.read_text().split()))
|
||||
self.assertEqual(self.games(), {})
|
||||
|
||||
def test_file_mode_defers_to_the_live_helper(self):
|
||||
(self.state / "live.pid").write_text("%d\n" % os.getpid())
|
||||
self.assertTrue(COMPAT["live_helper_running"]())
|
||||
|
||||
@@ -42,6 +42,15 @@ class DesktopSteamLaunchTest(unittest.TestCase):
|
||||
self.assertEqual(result.stdout.splitlines(), ['1', 'desktop', ':7', 'steam', 'steam://open/library'])
|
||||
self.assertFalse((self.session / 'steam-launch').exists())
|
||||
|
||||
def test_desktop_games_present_without_dri3(self):
|
||||
(self.root / 'supervisor').write_text('#!/bin/bash\nprintf "%s\\n" "$MESA_VK_WSI_DEBUG"\n')
|
||||
self.env.pop('MESA_VK_WSI_DEBUG', None)
|
||||
self.assertEqual(self.launch('desktop', '945360').stdout.splitlines(), ['sw'])
|
||||
self.env['MESA_VK_WSI_DEBUG'] = 'noshm'
|
||||
self.assertEqual(self.launch('desktop', '945360').stdout.splitlines(), ['noshm,sw'])
|
||||
self.env['MESA_VK_WSI_DEBUG'] = 'sw,noshm'
|
||||
self.assertEqual(self.launch('desktop', '945360').stdout.splitlines(), ['sw,noshm'])
|
||||
|
||||
def test_desktop_game_url_goes_to_client(self):
|
||||
result = self.launch('desktop', '501590')
|
||||
self.assertEqual(result.returncode, 0, result.stderr)
|
||||
|
||||
Loaded 100 of 473 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user