Something went wrong. Try again.
An auto tiler for macOS
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201#!/bin/bash# shellcheck disable=SC2016set -euo pipefailcd "$(dirname "$0")/../.."work=$(mktemp -d "${TMPDIR:-/tmp}/parcel-reality-driver.XXXXXX")work=$(CDPATH='' cd "$work" && pwd -P)trap 'rm -rf "$work"' EXITmkdir -p "$work/Scripts" "$work/bin" "$work/executable"cp Scripts/build-reality-driver.sh "$work/Scripts/"printf '#!/bin/sh\nset -eu\nexec swift build "$@"\n' > "$work/Scripts/swift-build.sh"printf 'binary\n' > "$work/executable/ParcelRealityDriver"printf '#!/bin/bash\nprintf "%%s\\n" "${IDENTITIES:-}"\n' > "$work/bin/security"cat > "$work/bin/swift" <<'MOCK'#!/bin/bashset -euo pipefailprintf 'build %s BUNDLE=%s\n' "$*" "${PARCEL_BUNDLE_BUILD:-}" >> "$EVENTS"[[ $1 == build ]]shiftscratch="$PWD/.build"system=nativeconfiguration=debugreality=0product=''show=0while (( $# )); do case $1 in --scratch-path) scratch=$2; shift 2 ;; --build-system) system=$2; shift 2 ;; -c) configuration=$2; shift 2 ;; --product) product=$2; shift 2 ;; --show-bin-path) show=1; shift ;; -DPARCEL_REALITY) reality=1; shift ;; *) shift ;; esacdonevariant="$system:${PARCEL_BUNDLE_BUILD:-0}:$reality"bin_dir="$scratch/mock-products/$configuration"mkdir -p "$bin_dir/Parcel_ParcelUI.bundle/en.lproj"if [[ -f $scratch/variant && $(< "$scratch/variant") != "$variant" ]]; then printf 'Mixed build variants in one resource-copy cache.\n' >&2 exit 31fiprintf '%s\n' "$variant" > "$scratch/variant"printf '%s\n' "$variant" > "$bin_dir/Parcel_ParcelUI.bundle/en.lproj/Localizable.strings"if (( show )); then printf '%s\n' "$bin_dir"elif [[ $product == ParcelRealityDriver ]]; then cp "$EXECUTABLE_DIR/ParcelRealityDriver" "$bin_dir/$product"else printf '%s:%s\n' "$variant" "$configuration" > "$bin_dir/$product"fiMOCKprintf '#!/bin/bash\nprintf "sign %%s\\n" "$*" >> "$EVENTS"\nif [[ $1 == --verify ]]; then exit "${VERIFY_STATUS:-0}"; fi\nexit "${SIGN_STATUS:-0}"\n' > "$work/bin/codesign"printf '#!/bin/bash\nset -euo pipefail\n[[ $1 == build/reality-helper/ParcelRealityDriver && -f $1 && -f $2 ]]\nprintf "requirement\\n" >> "$EVENTS"\nexit "${REQUIREMENT_STATUS:-0}"\n' > "$work/Scripts/designated-requirement.sh"chmod +x "$work/Scripts/"*.sh "$work/bin/"* "$work/executable/ParcelRealityDriver"export PATH="$work/bin:$PATH" EVENTS="$work/events" EXECUTABLE_DIR="$work/executable"status=0bash "$work/Scripts/build-reality-driver.sh" > "$work/no-identity.log" 2>&1 || status=$?test "$status" = 1grep -q 'requires one Parcel Development identity' "$work/no-identity.log"test ! -e "$EVENTS"export IDENTITIES='1) 0123456789012345678901234567890123456789 "Parcel Development"'PARCEL_BUNDLE_BUILD=1 bash "$work/Scripts/build-reality-driver.sh" > "$work/build.log"grep -Fq "build build --scratch-path $work/.build/reality-driver --build-system native -c debug --product ParcelRealityDriver BUNDLE=0" "$EVENTS"grep -Fq "build build --scratch-path $work/.build/reality-driver --build-system native -c debug --show-bin-path BUNDLE=0" "$EVENTS"grep -q -- '--options runtime --timestamp=none' "$EVENTS"grep -q 'certificate leaf = H"0123456789012345678901234567890123456789"' "$EVENTS"grep -q -- '--identifier dev.vinnymac.parcel.reality-driver' "$EVENTS"grep -q -- '--verify --strict' "$EVENTS"helper="$work/build/reality-helper/ParcelRealityDriver"test -f "$helper"test -x "$helper"test ! -e "$work/build/ParcelRealityDriver.app"cmp "$work/executable/ParcelRealityDriver" "$helper"printf 'rebuilt binary\n' > "$work/executable/ParcelRealityDriver"bash "$work/Scripts/build-reality-driver.sh" > "$work/rebuild.log"grep -q 'requirement' "$EVENTS"cmp "$work/executable/ParcelRealityDriver" "$helper"cp "$helper" "$work/before-failure"printf 'unpublished binary\n' > "$work/executable/ParcelRealityDriver"for failure in REQUIREMENT_STATUS=17 SIGN_STATUS=18 VERIFY_STATUS=19; do status=0 env "$failure" bash "$work/Scripts/build-reality-driver.sh" > "$work/changed.log" 2>&1 || status=$? test "$status" = "${failure#*=}" cmp "$helper" "$work/before-failure"donecp "$EVENTS" "$work/before-unsafe-output"for path in build build/reality-helper build/reality-helper/ParcelRealityDriver .build .build/reality-driver; do mv "$work/$path" "$work/held-output" ln -s "$work/held-output" "$work/$path" status=0 bash "$work/Scripts/build-reality-driver.sh" > "$work/symlink.log" 2>&1 || status=$? test "$status" = 1 grep -q 'Refusing a symlinked reality output' "$work/symlink.log" cmp "$EVENTS" "$work/before-unsafe-output" rm "$work/$path" mv "$work/held-output" "$work/$path"donemv "$helper" "$work/held-output"mkdir "$helper"status=0bash "$work/Scripts/build-reality-driver.sh" > "$work/directory.log" 2>&1 || status=$?test "$status" = 1grep -q 'must be a regular executable' "$work/directory.log"rmdir "$helper"mv "$work/held-output" "$helper"export IDENTITIES="$IDENTITIES2) 1123456789012345678901234567890123456789 \"Parcel Development\""status=0bash "$work/Scripts/build-reality-driver.sh" > "$work/ambiguous.log" 2>&1 || status=$?test "$status" = 1# Exercise bundle build/path selection without compiling, signing, or launching an app.cp Scripts/bundle.sh Scripts/product.env Scripts/version.sh Scripts/packaging-paths.sh Scripts/check-app-icons.sh "$work/Scripts/"mkdir -p "$work/Packaging/AlternateIcons" "$work/Sources/ParcelUI/Resources"cp Packaging/AlternateIcons/IconTool.swift "$work/Packaging/AlternateIcons/"ditto Sources/ParcelUI/Resources/AppIcons "$work/Sources/ParcelUI/Resources/AppIcons"mkdir -p "$work/Resources" "$work/Packaging" "$work/.build/apple/Products/Debug/Parcel_ParcelUI.bundle/en.lproj"cp Resources/Info.plist "$work/Resources/"cp Packaging/Sparkle-LICENSE "$work/Packaging/"printf 'existing default-cache localization\n' > "$work/.build/apple/Products/Debug/Parcel_ParcelUI.bundle/en.lproj/marker"cp "$work/.build/apple/Products/Debug/Parcel_ParcelUI.bundle/en.lproj/marker" "$work/default-marker"cat > "$work/Scripts/parcel-dev.sh" <<'MOCK'#!/bin/bashset -euo pipefailcase $1 in --path) printf '%s\n' "$PWD/Scripts/parcel-dev.sh" ;; update-metadata) [[ $2 == configure && -f $3 && $4 == "${EXPECTED_VARIANT##*:}" ]] contents=${3%/Info.plist} [[ $(< "$contents/MacOS/Parcel") == "$EXPECTED_VARIANT" ]] [[ $(< "$contents/Resources/bin/prcl") == "$EXPECTED_VARIANT" ]] if [[ $EXPECTED_VARIANT == swiftbuild:1:1:* ]]; then cmp build/reality-helper/ParcelRealityDriver "$contents/Helpers/ParcelRealityDriver" else [[ ! -e $contents/Helpers ]] fi printf 'staged %s\n' "$EXPECTED_VARIANT" >> "$EVENTS" ;; *) exit 32 ;;esacMOCKprintf '#!/bin/bash\n[[ $# == 4 && $2 == -verify_arch && $3 == arm64 && $4 == x86_64 ]]\n' > "$work/bin/lipo"chmod +x "$work/Scripts/parcel-dev.sh" "$work/bin/lipo"unset PARCEL_DEV_BINARY PARCEL_BUNDLE_ID PARCEL_VERSION PARCEL_BUILD_NUMBER PARCEL_SPARKLE_FRAMEWORKfor mode in normal reality normal inspectable release; do configuration=debug lane=normal expected=swiftbuild:1:0:debug args=(debug) case $mode in reality) lane=reality; expected=swiftbuild:1:1:debug; args+=(--reality) ;; inspectable) args+=(--inspectable) ;; release) configuration=release; expected=swiftbuild:1:0:release; args=(release) ;; esac cache="$work/.build/bundle/$lane" : > "$EVENTS" status=0 EXPECTED_VARIANT="$expected" PARCEL_SIGN_IDENTITY=0123456789012345678901234567890123456789 \ bash "$work/Scripts/bundle.sh" "${args[@]}" > "$work/bundle.log" 2>&1 || status=$? test "$status" = 1 # Deliberately stop before framework assembly; all three Swift calls must agree. grep -Fxq "Sparkle framework not found: $cache/artifacts/sparkle/Sparkle/Sparkle.xcframework/macos-arm64_x86_64/Sparkle.framework" "$work/bundle.log" grep -F "build build --scratch-path $cache --build-system swiftbuild -c $configuration " "$EVENTS" > "$work/build-events" test "$(wc -l < "$work/build-events" | tr -d ' ')" = 3 for product in ParcelApp prcl; do grep -Fq -- "--product $product BUNDLE=1" "$work/build-events" done grep -Fq -- '--show-bin-path BUNDLE=1' "$work/build-events" if [[ $lane == reality ]]; then test "$(grep -c -- '-DPARCEL_REALITY' "$work/build-events")" = 3 else if grep -q -- '-DPARCEL_REALITY' "$work/build-events"; then exit 1; fi fi grep -Fxq "staged $expected" "$EVENTS" cmp "$work/.build/apple/Products/Debug/Parcel_ParcelUI.bundle/en.lproj/marker" "$work/default-marker" test -z "$(find "$work/build" -maxdepth 1 -name '.bundle.*' -print)"done: > "$EVENTS"status=0EXPECTED_VARIANT=swiftbuild:1:0:debug PARCEL_SPARKLE_FRAMEWORK="$work/override.framework" \ PARCEL_SIGN_IDENTITY=0123456789012345678901234567890123456789 \ bash "$work/Scripts/bundle.sh" > "$work/override.log" 2>&1 || status=$?test "$status" = 1grep -Fxq "Sparkle framework not found: $work/override.framework" "$work/override.log"for path in .build .build/bundle .build/bundle/normal .build/bundle/reality; do args=(debug) if [[ $path == .build/bundle/reality ]]; then args+=(--reality); fi mv "$work/$path" "$work/held-cache" ln -s "$work/held-cache" "$work/$path" : > "$EVENTS" status=0 PARCEL_SIGN_IDENTITY=0123456789012345678901234567890123456789 \ bash "$work/Scripts/bundle.sh" "${args[@]}" > "$work/cache-symlink.log" 2>&1 || status=$? test "$status" = 1 grep -q 'Refusing a symlinked bundle cache' "$work/cache-symlink.log" test ! -s "$EVENTS" rm "$work/$path" mv "$work/held-cache" "$work/$path"doneprintf 'Reality build checks passed: signed helper, protected rebuild, isolated native/normal/reality caches, variant return, matching build/path calls.\n'