#!/bin/bash set -euo pipefail cd "$(dirname "$0")/.." bin=${1:?Pass the built test directory.} shift helper="$(dirname "$(xcrun --find swift)")/../libexec/swift/pm/swiftpm-testing-helper" test_bundle="$bin/ParcelPackageTests.xctest/Contents/MacOS/ParcelPackageTests" [[ -x $helper && -f $test_bundle ]] || { printf 'Native test host requires the selected toolchain helper and built test bundle.\n' >&2; exit 2; } mkdir -p .build work=$(mktemp -d "$PWD/.build/native-test-host.XXXXXX") trap 'rm -rf "$work"' EXIT host="$work/NativeTests.app/Contents" mkdir -p "$host/MacOS" cp "$helper" "$host/MacOS/swiftpm-testing-helper" cp Scripts/NativeTestHost.plist "$host/Info.plist" frameworks="$(xcrun --show-sdk-platform-path)/Developer/Library/Frameworks${DYLD_FRAMEWORK_PATH:+:$DYLD_FRAMEWORK_PATH}" # Swift Testing loads the test bundle into this helper, not the generated bundle's main executable. command=(env "DYLD_FRAMEWORK_PATH=$frameworks" "$host/MacOS/swiftpm-testing-helper" --test-bundle-path "$test_bundle" "$@" "$test_bundle" --testing-library swift-testing) language=${PARCEL_LOCALIZATION_LANGUAGE:-} if [[ ${PARCEL_PSEUDO_LOCALIZATION:-0} == 1 ]]; then language=en-XA; fi if [[ -n $language ]]; then case "$language" in en|es|fr|de|ja|zh-Hans|ko|pt-BR|en-XA) command+=(-AppleLanguages "($language)") ;; *) printf 'Unsupported native-test language: %s\n' "$language" >&2; exit 2 ;; esac fi if [[ -n ${PARCEL_HEAVY_LOCK_HELD:-} ]]; then "${command[@]}" else printf 'parcel: waiting for the shared build/test lock (/tmp/parcel-heavy.lock)\n' >&2 PARCEL_HEAVY_LOCK_HELD=$$ /usr/bin/lockf -k /tmp/parcel-heavy.lock "${command[@]}" fi