#!/usr/bin/env bash # Generate `apps/cotton/Cotton.xcodeproj` from `project.yml` (design P7). # # An iOS app with two code-signed app extensions, an app group, entitlements # and three per-target Info.plists cannot be expressed in SwiftPM at all — so the # CODE is a Swift package and the APP is a generated Xcode project. `project.yml` # is the only hand-edited file; the `.xcodeproj` and the Info.plists it writes # are gitignored build products. # # This is the successor to `expo prebuild --clean`, and it keeps that rule: # never edit the generated project by hand, regenerate it. # # bash scripts/gen-ios-project.sh # # It takes NO build lock: xcodegen writes a project file and compiles nothing. set -euo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROOT="$(cd "$HERE/.." && pwd)" IOS_DIR="$ROOT/apps/cotton" python3 "$ROOT/scripts/gen-swift-definition-types.py" if ! command -v xcodegen >/dev/null 2>&1; then cat >&2 <<'MSG' gen-ios-project: xcodegen is not on PATH. brew install xcodegen It is pinned by what the build Mac has installed rather than by a lockfile: it writes a project file, and a project file that differs between two machines is caught by the build, not by a hash. MSG exit 1 fi # THE FFI PLACEHOLDER, FIRST. xcodegen reads `Package.swift` through SwiftPM, # and SwiftPM refuses to RESOLVE a package whose `binaryTarget` path does not # exist. The manifest declares `CottonFFIBinary` unconditionally (it used to ask # the filesystem, and the machine-wide manifest cache made one worktree's answer # every worktree's — Cotton note "Repo landmines — why the build's rules exist"), so the path has to be # there. This writes a module-less stub when the real archive is absent, and leaves # the real one alone. Idempotent, and it compiles nothing. bash "$ROOT/scripts/ffi-stub.sh" cd "$IOS_DIR" # THE EXTENSION GATE is applied HERE, before xcodegen sees the spec: # a build setting cannot drop a target from the graph, and an extension # stripped from the built app afterwards has already been built and signed and # leaves a hole Xcode's own `ValidateEmbeddedBinary` refuses. `project.yml` holds the default; an # environment variable of the same name overrides it: # # COTTON_SHARE_ENABLED=NO pnpm ios:project # # The gated spec is a build product and is gitignored. Exit 3 from the gate # means "every gate is on", so the hand-written spec is used unchanged and no # copy is left lying around to be edited by mistake. SPEC=project.yml GATED=.project.gated.yml rm -f "$GATED" if npx tsx "$ROOT/scripts/ios-spec-gate.ts" project.yml "$GATED"; then SPEC="$GATED" fi xcodegen generate --spec "$SPEC" --project . # Xcode has its own lockfile location even though Cotton is a local package. # Seed the generated workspace from the one committed pin set, so a fresh cut # can use -onlyUsePackageVersionsFromResolvedFile without an online resolve. mkdir -p Cotton.xcodeproj/project.xcworkspace/xcshareddata/swiftpm cp Package.resolved Cotton.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved echo "gen-ios-project: Cotton.xcodeproj is current." echo " scheme: tinmen-cotton — run/test in Debug, archive in Release" echo " flavor: Cotton Dev (COTTON_FLAVOR=dev) unless a release lane passes COTTON_FLAVOR=real" echo " build: xcodebuild build -project apps/cotton/Cotton.xcodeproj -scheme tinmen-cotton ..." echo " NOTE: every heavy build on this Mac goes through scripts/with-build-lock.sh"