Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209#!/bin/bash# shellcheck disable=SC2016 # Mock scripts expand their own environment at execution.set -euo pipefailcd "$(dirname "$0")/../.."work=$(mktemp -d "${TMPDIR:-/tmp}/parcel-reality-runner.XXXXXX")trap 'rm -rf "$work"' EXITmkdir -p "$work/Scripts" "$work/bin" "$work/build" "$work/.build/debug" \ "$work/Tests/Reality" "$work/Tests/RealityDriver" "$work/Sources/FixtureApp" \ "$work/Sources/ParcelApp" "$work/Resources"cp Scripts/test-reality.sh "$work/Scripts/"printf '#!/bin/sh\nset -eu\nexec swift build "$@"\n' > "$work/Scripts/swift-build.sh"cat > "$work/Scripts/bundle.sh" <<'MOCK'#!/bin/bashset -euo pipefailprintf 'bundle %s\n' "$*" >> "$EVENTS"if [[ ${BUNDLE_STATUS:-0} != 0 ]]; then exit "$BUNDLE_STATUS"; fiif [[ ${MUTATE_PACKAGE:-0} == 1 ]]; then printf 'concurrent package edit\n' > Package.swift; firm -rf build/Parcel.appmkdir -p build/Parcel.app/Contents/{MacOS,Helpers,Resources/bin}printf '#!/bin/sh\n# reality debug %s\n' "$(<Sources/ParcelApp/Main.swift)" > build/Parcel.app/Contents/MacOS/Parcelcp build/reality-helper/ParcelRealityDriver build/Parcel.app/Contents/Helpers/printf '#!/bin/sh\n' > build/Parcel.app/Contents/Resources/bin/prclchmod +x build/Parcel.app/Contents/MacOS/Parcel build/Parcel.app/Contents/Resources/bin/prclMOCKcat > "$work/Scripts/build-reality-driver.sh" <<'MOCK'#!/bin/bashset -euo pipefailprintf 'driver\n' >> "$EVENTS"mkdir -p build/reality-helperprintf '#!/bin/sh\n# %s\n' "$(<Tests/RealityDriver/Main.swift)" > build/reality-helper/ParcelRealityDriverchmod +x build/reality-helper/ParcelRealityDriverMOCKprintf '#!/bin/bash\nprintf "lock %%s\\n" "$*" >> "$EVENTS"\nexec "$@"\n' > "$work/Scripts/screen-lock.sh"cat > "$work/bin/swift" <<'MOCK'#!/bin/bashset -euo pipefailif [[ $1 == --version ]]; then printf 'fixture Swift %s\n' "${SWIFT_VERSION:-1}"; exit 0; fiif [[ $* == *--show-bin-path* ]]; then printf '%s\n' "$EXECUTABLE_DIR"; exit 0; fiprintf 'swift %s\n' "$*" >> "$EVENTS"[[ $PARCEL_BUNDLE_BUILD == 0 ]]mkdir -p "$EXECUTABLE_DIR"case "$*" in 'build --product ParcelRealityTests') printf '#!/bin/bash\nprintf "runner %%s\\n" "$*" >> "$EVENTS"\nprintf "%%s\\n" "$PARCEL_FIXTURE_PATH" > "$EVENTS.fixture"\nexit "${REALITY_STATUS:-0}"\n' > "$EXECUTABLE_DIR/ParcelRealityTests" chmod +x "$EXECUTABLE_DIR/ParcelRealityTests" mkdir -p "$EXECUTABLE_DIR/ParcelUI.bundle" printf 'compiled resources\n' > "$EXECUTABLE_DIR/ParcelUI.bundle/strings" ;; 'build --product FixtureApp') printf '#!/bin/sh\n' > "$EXECUTABLE_DIR/FixtureApp" chmod +x "$EXECUTABLE_DIR/FixtureApp" ;; *) exit 2 ;;esacMOCKprintf '#!/bin/bash\nprintf "caffeinate %%s\\n" "$1" >> "$EVENTS"\nshift\nexec "$@"\n' > "$work/bin/caffeinate"printf '#!/bin/sh\nprintf "fixture %%s\\n" "$*"\n' > "$work/bin/xcrun"printf '#!/bin/sh\nprintf "fixture Xcode\\n"\n' > "$work/bin/xcodebuild"printf '#!/bin/sh\nprintf '\'' 1) %%s "Parcel Development"\\n'\'' "${SIGN_FINGERPRINT:-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA}"\n' > "$work/bin/security"chmod +x "$work/Scripts/"*.sh "$work/bin/"*printf 'fixture package\n' > "$work/Package.swift"printf 'fixture driver\n' > "$work/Tests/RealityDriver/Main.swift"printf 'fixture harness\n' > "$work/Tests/Reality/Main.swift"printf 'fixture app\n' > "$work/Sources/ParcelApp/Main.swift"printf 'fixture window\n' > "$work/Sources/FixtureApp/Main.swift"export PATH="$work/bin:$PATH" EVENTS="$work/events" EXECUTABLE_DIR="$work/.build/debug"unset PARCEL_VERSION PARCEL_BUILD_NUMBER PARCEL_BUNDLE_ID PARCEL_SIGN_IDENTITY PARCEL_DEV_BINARY PARCEL_SPARKLE_FRAMEWORKrun() { PARCEL_REALITY=1 bash "$work/Scripts/test-reality.sh" "$@" > "$work/run.log" 2>&1; }build_count() { grep -c -E '^(driver|bundle|swift)($| )' "$EVENTS" || true; }refuse() { local expected=$1 status=0 shift : > "$EVENTS" run "$@" || status=$? [[ $status == 1 ]] grep -q "$expected" "$work/run.log" grep -q 'No apps launched' "$work/run.log" [[ ! -s $EVENTS ]]}env -u PARCEL_REALITY bash "$work/Scripts/test-reality.sh" --no-build > "$work/skip.log"grep -q 'No apps launched' "$work/skip.log"test ! -e "$EVENTS"refuse 'build/Parcel.app is missing' --no-build --scenario launchrun --scenario launchprintf 'driver\nbundle debug --reality\nswift build --product ParcelRealityTests\nswift build --product FixtureApp\ncaffeinate -dimsu\nlock %s/ParcelRealityTests --scenario launch\nrunner --scenario launch\n' "$EXECUTABLE_DIR" > "$work/expected"cmp "$work/expected" "$EVENTS"test "$(<"$EVENTS.fixture")" = "$EXECUTABLE_DIR/FixtureApp"
# Mtime alone never invalidates sources or signed outputs.touch -t 203001010000 "$work/Package.swift" "$work/Tests/Reality/Main.swift" \ "$work/Sources/ParcelApp/Main.swift" "$work/build/Parcel.app/Contents/MacOS/Parcel": > "$EVENTS"run --no-build --scenario launch[[ $(build_count) == 0 ]][[ $(grep -c 'reusing .*content stamp unchanged' "$work/run.log") == 4 ]]grep -q '^runner --scenario launch$' "$EVENTS"if grep -q -- '--no-build' "$EVENTS"; then exit 1; fi
# Byte changes with preserved mtimes invalidate only affected stages.cp -p "$work/Tests/Reality/Main.swift" "$work/original"printf 'changed harness\n' > "$work/Tests/Reality/Main.swift"touch -r "$work/original" "$work/Tests/Reality/Main.swift"refuse 'cannot reuse harness: stale inputs' --no-buildrun[[ $(build_count) == 1 ]]grep -q '^swift build --product ParcelRealityTests$' "$EVENTS"printf 'changed fixture\n' > "$work/Sources/FixtureApp/Main.swift"refuse 'cannot reuse fixture: stale inputs' --no-buildrun[[ $(build_count) == 1 ]]grep -q '^swift build --product FixtureApp$' "$EVENTS"printf 'changed app\n' > "$work/Sources/ParcelApp/Main.swift"refuse 'cannot reuse bundle: stale inputs' --no-buildrun[[ $(build_count) == 1 ]]grep -q '^bundle debug --reality$' "$EVENTS"printf 'changed driver\n' > "$work/Tests/RealityDriver/Main.swift"refuse 'cannot reuse driver: stale inputs' --no-buildrun[[ $(build_count) == 2 ]]grep -q '^driver$' "$EVENTS"grep -q '^bundle debug --reality$' "$EVENTS"
# Excluded docs do not force native compilation; added/deleted inputs do.printf 'fixture documentation\n' > "$work/Tests/Reality/README.md": > "$EVENTS"run --no-build[[ $(build_count) == 0 ]]printf 'resource\n' > "$work/Resources/new resource.txt"refuse 'cannot reuse bundle: stale inputs' --no-buildrun[[ $(build_count) == 1 ]]rm "$work/Resources/new resource.txt"refuse 'cannot reuse bundle: stale inputs' --no-buildrun[[ $(build_count) == 1 ]]
# An ordinary build replaces the bundle, not the external reality stamp.rm -rf "$work/build/Parcel.app/Contents/Helpers"printf '#!/bin/sh\n# ordinary debug\n' > "$work/build/Parcel.app/Contents/MacOS/Parcel"refuse 'bundle is not reality-enabled debug' --no-buildrun[[ $(build_count) == 1 ]]grep -q '^bundle debug --reality$' "$EVENTS"# Even retaining the helper cannot hide a changed host or resource payload.printf '# ordinary overwrite\n' >> "$work/build/Parcel.app/Contents/MacOS/Parcel"refuse 'cannot reuse bundle: stale inputs or changed output' --no-buildrun[[ $(build_count) == 1 ]]printf 'modified resource\n' > "$EXECUTABLE_DIR/ParcelUI.bundle/strings"refuse 'cannot reuse harness: stale inputs or changed output' --no-buildrun[[ $(build_count) == 1 ]]rm "$EXECUTABLE_DIR/FixtureApp"refuse 'missing or inappropriate .*FixtureApp' --no-buildrun[[ $(build_count) == 1 ]]rm "$work/build/reality-build-stamps/bundle"refuse 'cannot reuse bundle: no trusted content stamp' --no-buildrun[[ $(build_count) == 1 ]]
# Failed builds never stamp or launch, and the next invocation retries.printf 'another app change\n' > "$work/Sources/ParcelApp/Main.swift": > "$EVENTS"status=0BUNDLE_STATUS=17 run || status=$?[[ $status == 17 ]][[ ! -f $work/build/reality-build-stamps/bundle ]]if grep -q -E '^(caffeinate|lock|runner) ' "$EVENTS"; then exit 1; fi: > "$EVENTS"run[[ $(build_count) == 1 ]]
# A changing build input must not be stamped against an older output.rm "$work/build/reality-build-stamps/bundle": > "$EVENTS"status=0MUTATE_PACKAGE=1 run || status=$?[[ $status == 1 ]]grep -q 'inputs changed during the build' "$work/run.log"[[ ! -f $work/build/reality-build-stamps/bundle ]]if grep -q -E '^(caffeinate|lock|runner) ' "$EVENTS"; then exit 1; fi: > "$EVENTS"run[[ $(build_count) == 4 ]]
# A replacement certificate with the same name invalidates both signed stages.SIGN_FINGERPRINT=BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB refuse 'cannot reuse driver: stale inputs' --no-buildSIGN_FINGERPRINT=BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB run[[ $(build_count) == 2 ]]: > "$EVENTS"run[[ $(build_count) == 2 ]]
# Toolchain and packaging settings are inputs, but no-build never compiles/signs.SWIFT_VERSION=2 refuse 'cannot reuse driver: stale inputs' --no-buildSWIFT_VERSION=2 run[[ $(build_count) == 4 ]]SWIFT_VERSION=2 PARCEL_VERSION=0.2.0 refuse 'cannot reuse bundle: stale inputs' --no-buildSWIFT_VERSION=2 PARCEL_VERSION=0.2.0 run[[ $(build_count) == 1 ]]status=0SWIFT_VERSION=2 PARCEL_VERSION=0.2.0 REALITY_STATUS=19 run --no-build || status=$?[[ $status == 19 ]][[ $(build_count) == 1 ]][[ -z $(find "$work/build" -maxdepth 1 -name '.reality-stamps.*' -print) ]]printf 'Reality runner checks passed: opt-in, content reuse, mtime independence, stale/missing/ordinary bundles, selective rebuilds, resources, failed builds, arguments, lock, and red exit.\n'