Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121#!/bin/bash# shellcheck disable=SC2016 # Mock tools expand their own environment at execution.set -euo pipefailcd "$(dirname "$0")/../.."work=$(mktemp -d "${TMPDIR:-/tmp}/parcel reality isolation.XXXXXX")trap 'rm -rf "$work"' EXITchecker="$PWD/Scripts/check-reality-isolation.sh"app="$work/Ordinary Parcel.app"binary="$app/Contents/MacOS/Parcel"mkdir -p "$app/Contents/MacOS" "$work/bin"count=0check() { if ! "$@"; then printf 'Reality isolation test failed: %s\n' "$*" >&2 if [[ -f $work/failure.log ]]; then while IFS= read -r line; do printf '%s\n' "$line" >&2; done < "$work/failure.log" fi exit 1 fi count=$((count + 1))}reject() { local expected=$1 status=0 shift "$@" > "$work/failure.log" 2>&1 || status=$? if [[ $status != "$expected" ]]; then printf 'Expected status %s, got %s: %s\n' "$expected" "$status" "$*" >&2 while IFS= read -r line; do printf '%s\n' "$line" >&2; done < "$work/failure.log" return 1 fi}
printf '%s\n' 'print("ordinary")' > "$work/clean.swift"printf '%s\n' 'print("PARCEL_REALITY_DRIVER_SOCKET")' > "$work/socket.swift"printf '%s\n' 'print("AppRealityDriverHost")' > "$work/host.swift"printf '%s\n' '@_cdecl("AppRealityDriverHost") public func ordinaryEntry() -> Int32 { 0 }' \ '_ = ordinaryEntry()' > "$work/symbol.swift"for fixture in clean socket host symbol; do check swiftc "$work/$fixture.swift" -o "$work/$fixture"donecp "$work/clean" "$binary"check "$checker" "$app"check reject 2 "$checker"check grep -Fq 'Usage:' "$work/failure.log"check reject 2 "$checker" "$app" extracheck reject 1 "$checker" "$work/Missing.app"check grep -Fq 'Missing or invalid Parcel bundle binary:' "$work/failure.log"
for fixture in socket host; do cp "$work/$fixture" "$binary" check reject 1 "$checker" "$app" check grep -Fq 'Reality spawn strings found' "$work/failure.log"donecp "$work/symbol" "$binary"check reject 1 "$checker" "$app"check grep -Fq 'Reality spawn symbol found' "$work/failure.log"cp "$work/clean" "$binary"check /usr/bin/strip -S -x "$binary"check "$checker" "$app"mkdir -p "$app/Contents/Resources/nested" "$app/Contents/Helpers"for helper in Contents/Helpers/ParcelRealityDriver Contents/Resources/nested/ParcelRealityDriver; do cp "$work/clean" "$app/$helper" check reject 1 "$checker" "$app" check grep -Fq "$helper" "$work/failure.log" rm "$app/$helper"donemkdir "$app/Contents/Resources/nested/ParcelRealityDriver.app"check reject 1 "$checker" "$app"check grep -Fq 'ParcelRealityDriver.app' "$work/failure.log"rmdir "$app/Contents/Resources/nested/ParcelRealityDriver.app"ln -s missing "$app/Contents/Helpers/ParcelRealityDriver"check reject 1 "$checker" "$app"check grep -Fq 'Reality helper found' "$work/failure.log"rm "$app/Contents/Helpers/ParcelRealityDriver"check "$checker" "$app"
chmod -x "$binary"check reject 1 "$checker" "$app"rm "$binary"check reject 1 "$checker" "$app"mkdir "$binary"check reject 1 "$checker" "$app"rmdir "$binary"printf 'not a compiled binary\n' > "$binary"chmod +x "$binary"check reject 1 "$checker" "$app"check grep -Fq 'with nm (status 1)' "$work/failure.log"cp "$work/clean" "$binary"
printf '%s\n' '#!/bin/bash' 'set -euo pipefail' \ 'case ${TEST_STRINGS_MODE:-real} in' \ 'fail) printf "AppRealityDriverHost\n"; printf "strings inspection failed\n" >&2; exit 23 ;;' \ 'large) printf "AppRealityDriverHost\n"; for ((i=0; i<30000; i++)); do printf "ordinary binary text\n"; done ;;' \ 'real) exec /usr/bin/strings "$@" ;;' \ '*) exit 2 ;;' 'esac' > "$work/bin/strings"printf '%s\n' '#!/bin/bash' 'set -euo pipefail' \ 'case ${TEST_NM_MODE:-real} in' \ 'fail) printf "00000000 T _AppRealityDriverHost\n"; printf "nm inspection failed\n" >&2; exit 24 ;;' \ 'large) printf "00000000 T _AppRealityDriverHost\n"; for ((i=0; i<30000; i++)); do printf "00000000 T _ordinary\n"; done ;;' \ 'real) exec /usr/bin/nm "$@" ;;' \ '*) exit 2 ;;' 'esac' > "$work/bin/nm"printf '%s\n' '#!/bin/bash' \ 'if [[ ${TEST_GREP_FAILURE:-0} == 1 ]]; then printf "marker matching failed\n" >&2; exit 25; fi' \ 'exec /usr/bin/grep "$@"' > "$work/bin/grep"chmod +x "$work/bin/"*export PATH="$work/bin:$PATH"check "$checker" "$app"check reject 23 env TEST_STRINGS_MODE=fail "$checker" "$app"check grep -Fq 'with strings (status 23)' "$work/failure.log"check grep -Fq 'strings inspection failed' "$work/failure.log"check reject 24 env TEST_NM_MODE=fail "$checker" "$app"check grep -Fq 'with nm (status 24)' "$work/failure.log"check grep -Fq 'nm inspection failed' "$work/failure.log"check reject 1 env TEST_STRINGS_MODE=large "$checker" "$app"check grep -Fq 'Reality spawn strings found' "$work/failure.log"check reject 1 env TEST_NM_MODE=large "$checker" "$app"check grep -Fq 'Reality spawn symbol found' "$work/failure.log"check reject 25 env TEST_GREP_FAILURE=1 "$checker" "$app"check grep -Fq 'marker matching failed' "$work/failure.log"printf 'Reality isolation checks passed: %s\n' "$count"