#!/bin/bash set -euo pipefail cd "$(dirname "$0")/../.." work=$(mktemp -d "${TMPDIR:-/tmp}/parcel-tool-cache.XXXXXX") work=$(CDPATH='' cd "$work" && pwd -P) trap 'rm -rf "$work"' EXIT mkdir -p "$work/project/Scripts" "$work/project/Sources/ParcelDev" "$work/project/Sources/parcel-dev" "$work/project/sdk" "$work/bin" cp Scripts/parcel-dev.sh Scripts/swift-build.sh "$work/project/Scripts/" printf 'fixture package\n' > "$work/project/Package.swift" printf 'fixture source\n' > "$work/project/Sources/ParcelDev/Value.swift" cat > "$work/bin/swift" <<'MOCK' #!/bin/bash set -euo pipefail if [[ $1 == --version ]]; then printf '%s\n' "fixture Swift ${TEST_SWIFT_VERSION:-1}"; exit 0; fi printf '%s\n' "$*" >> "$BUILD_LOG" [[ $1 == build && $2 == --scratch-path && $3 == "$PROJECT/.build/parcel-dev" ]] [[ $4 == -c && $5 == release && $6 == --product && $7 == parcel-dev ]] if [[ ${BUILD_FAIL:-0} != 0 ]]; then exit "$BUILD_FAIL"; fi mkdir -p "$3/release" printf '#!/bin/sh\nprintf "native fixture: %%s\\n" "$*"\n' > "$3/release/parcel-dev" chmod +x "$3/release/parcel-dev" MOCK cat > "$work/bin/xcrun" <<'MOCK' #!/bin/sh set -eu case "$*" in '--find swift') printf '%s\n' "$PROJECT/compiler/swift" ;; '--show-sdk-path') printf '%s\n' "$PROJECT/sdk" ;; *) exit 2 ;; esac MOCK cat > "$work/bin/xcodebuild" <<'MOCK' #!/bin/sh set -eu printf 'Xcode fixture\n' exit "${TEST_XCODE_STATUS:-0}" MOCK chmod +x "$work/bin/swift" "$work/bin/xcrun" "$work/bin/xcodebuild" export PATH="$work/bin:$PATH" BUILD_LOG="$work/builds" PROJECT="$work/project" unset PARCEL_DEV_BINARY binary=$PROJECT/.build/parcel-dev/release/parcel-dev actual=$("$PROJECT/Scripts/parcel-dev.sh" --path) [[ $actual == "$binary" ]] [[ $(wc -l < "$BUILD_LOG") -eq 1 ]] [[ $("$PROJECT/Scripts/parcel-dev.sh" probe) == 'native fixture: probe' ]] [[ $(wc -l < "$BUILD_LOG") -eq 1 ]] touch -t 203001010000 "$PROJECT/Package.swift" [[ $("$PROJECT/Scripts/parcel-dev.sh" --path) == "$binary" ]] [[ $(wc -l < "$BUILD_LOG") -eq 1 ]] printf 'changed package\n' > "$PROJECT/Package.swift" [[ $("$PROJECT/Scripts/parcel-dev.sh" --path) == "$binary" ]] [[ $(wc -l < "$BUILD_LOG") -eq 2 ]] [[ $(BUILD_FAIL=17 "$PROJECT/Scripts/parcel-dev.sh" probe) == 'native fixture: probe' ]] [[ $(wc -l < "$BUILD_LOG") -eq 2 ]] printf 'changed source\n' > "$PROJECT/Sources/ParcelDev/Value.swift" status=0 BUILD_FAIL=17 "$PROJECT/Scripts/parcel-dev.sh" probe > "$work/failure" 2>&1 || status=$? [[ $status == 17 ]] status=0 PARCEL_DEV_BINARY="$work/missing" "$PROJECT/Scripts/parcel-dev.sh" --path > "$work/failure" 2>&1 || status=$? [[ $status == 2 ]] grep -q 'missing or not executable' "$work/failure" [[ $(wc -l < "$BUILD_LOG") -eq 3 ]] [[ ! -f "$PROJECT/.build/parcel-dev/inputs" ]] [[ $("$PROJECT/Scripts/parcel-dev.sh" probe) == 'native fixture: probe' ]] [[ $(wc -l < "$BUILD_LOG") -eq 4 ]] [[ $("$PROJECT/Scripts/parcel-dev.sh" --path) == "$binary" ]] [[ $(wc -l < "$BUILD_LOG") -eq 4 ]] # Root invalidation must preserve dependencies and independently stamped caches. builder="$PROJECT/Scripts/swift-build.sh" state="$PROJECT/.build" mkdir -p "$state/checkouts" "$state/repositories" "$state/artifacts" "$state/independent/debug" printf dependency > "$state/checkouts/retained" printf dependency > "$state/repositories/retained" printf dependency > "$state/artifacts/retained" printf independent > "$state/independent/debug/retained" "$builder" --prepare seed_objects() { mkdir -p "$state/arm64-apple-macosx/debug/ParcelCore.build" "$state/Modules" "$state/plugins/cache" "$state/apple/Intermediates.noindex" printf stale > "$state/arm64-apple-macosx/debug/ParcelCore.build/value.o" printf stale > "$state/Modules/ParcelCore.swiftmodule" printf stale > "$state/build.db" printf stale > "$state/debug.yaml" ln -s arm64-apple-macosx/debug "$state/debug" } objects_gone() { [[ ! -e $state/arm64-apple-macosx && ! -e $state/Modules && ! -e $state/build.db && ! -L $state/debug ]] [[ -f $state/checkouts/retained && -f $state/repositories/retained && -f $state/artifacts/retained ]] [[ -x $binary && -f $state/independent/debug/retained ]] } seed_objects "$builder" --prepare [[ -f $state/arm64-apple-macosx/debug/ParcelCore.build/value.o ]] printf 'resolved 1\n' > "$PROJECT/Package.resolved" "$builder" --prepare objects_gone seed_objects TEST_SWIFT_VERSION=2 "$builder" --prepare objects_gone seed_objects TEST_SWIFT_VERSION=2 "$builder" --clean-modules objects_gone seed_objects status=0 TEST_XCODE_STATUS=23 "$builder" --prepare > "$work/failure" 2>&1 || status=$? [[ $status == 23 && -f $state/build.db ]] rm -f "$state/debug" ln -s "$state/independent" "$state/linked" status=0 "$builder" --clean-modules --scratch-path "$state/linked" > "$work/failure" 2>&1 || status=$? [[ $status == 2 && -f $state/independent/debug/retained ]] printf 'Tool cache and build stamp checks passed.\n'