After the initial setup worked for regular builds, three edge cases needed fixing.
Early exit on clean (BuildPkgTestCMD.sh)
The pre-action runs even when cleaning, but there’s nothing to build and nothing to clean manually — PkgTestCMD lives inside the parent’s BUILD_DIR, so Xcode cleans it automatically. We just exit early.
OBJROOT isolation (BuildPkgTestCMD.sh)
We were already setting SYMROOT to keep build products inside the parent’s BUILD_DIR. Turned out OBJROOT (intermediates) also needed to be isolated, otherwise building PkgTestCMD standalone would conflict and produce “entitlements modified during build” errors.
TARGET_BUILD_DIR (CopyPkgTestCMD.sh + outputPaths)
During archive, Xcode always creates a temporary .app directory and copies the bundle there itself — it knows exactly what files it’s putting in. Copying our binary to BUILT_PRODUCTS_DIR meant injecting a file into that directory after Xcode had already done its packaging, so Xcode had no awareness of it. TARGET_BUILD_DIR is the correct destination: our binary lands inside the .app before Xcode packages it for archive, so Xcode naturally includes it and understands the final state of the bundle.
Topic:
Developer Tools & Services
SubTopic:
Xcode
Tags: