#!/usr/bin/env bash # # build.sh — Build CodeEdit (macOS) from source, reproducibly, from scratch. # # Self-contained: on a fresh `git clone` into which only build.sh and launch.sh # have been copied, running `bash build.sh` produces CodeEdit.app. # # CodeEdit is a pure Xcode + Swift Package Manager project. Every third-party # dependency is fetched automatically by xcodebuild straight from Git (the # versions are pinned in # CodeEdit.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved). # There are therefore NO Homebrew / npm / CocoaPods / pip packages to install. # SwiftLint runs during the build as a Swift Package build-tool plugin # (SwiftLintPlugin) that ships its own bundled swiftlint binary, so a # system-wide SwiftLint is NOT required either. # # No source-code changes are needed: the project compiles as-is with the # toolchain described in the task (Xcode 15.4 / Swift 5.10). Deployment target # is macOS 13.0 and SWIFT_VERSION is 5, both fully supported by Xcode 15.4, so # nothing has to be down-graded. If a future change is ever required it must be # expressed here as an inline `git apply <<'PATCH' ... PATCH` block. # set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)" cd "$SCRIPT_DIR" PROJECT="$SCRIPT_DIR/CodeEdit.xcodeproj" SCHEME="CodeEdit" CONFIGURATION="Release" DERIVED_DATA="$SCRIPT_DIR/DerivedData" OUT_DIR="${APP_OUTPUT_DIR:-$SCRIPT_DIR}" APP_NAME="CodeEdit.app" echo "==> CodeEdit build starting" echo " SCRIPT_DIR = $SCRIPT_DIR" echo " OUT_DIR = $OUT_DIR" echo # --------------------------------------------------------------------------- # 1. Toolchain checks. Xcode is expected to be pre-installed on the runner. # --------------------------------------------------------------------------- if ! command -v xcodebuild >/dev/null 2>&1; then echo "ERROR: xcodebuild not found. A full Xcode install is required." >&2 exit 1 fi DEVDIR="$(xcode-select -p 2>/dev/null || true)" case "$DEVDIR" in ""|*CommandLineTools*) echo "ERROR: Active developer directory is '${DEVDIR:-}'." >&2 echo " A full Xcode is required, e.g.:" >&2 echo " sudo xcode-select -s /Applications/Xcode.app" >&2 exit 1 ;; esac xcodebuild -version echo # --------------------------------------------------------------------------- # 2. Resolve Swift Package Manager dependencies (requires network access). # Doing this explicitly first surfaces any fetch problems early and keeps # the step idempotent (re-running just re-verifies the pinned revisions). # --------------------------------------------------------------------------- echo "==> Resolving Swift Package dependencies" xcodebuild -project "$PROJECT" \ -scheme "$SCHEME" \ -derivedDataPath "$DERIVED_DATA" \ -skipPackagePluginValidation \ -skipMacroValidation \ -resolvePackageDependencies echo # --------------------------------------------------------------------------- # 3. Build the app with code signing disabled (per task requirements). # ARCHS defaults to "arm64 x86_64" for Release, producing a universal # binary that runs on both Apple Silicon and Intel. # --------------------------------------------------------------------------- echo "==> Building $SCHEME ($CONFIGURATION)" xcodebuild -project "$PROJECT" \ -scheme "$SCHEME" \ -configuration "$CONFIGURATION" \ -derivedDataPath "$DERIVED_DATA" \ -destination 'platform=macOS' \ -skipPackagePluginValidation \ -skipMacroValidation \ CODE_SIGN_IDENTITY="" \ CODE_SIGNING_ALLOWED=NO \ CODE_SIGNING_REQUIRED=NO \ build echo APP_SRC="$DERIVED_DATA/Build/Products/$CONFIGURATION/$APP_NAME" if [ ! -d "$APP_SRC" ]; then echo "ERROR: build finished but '$APP_SRC' was not produced." >&2 exit 1 fi # --------------------------------------------------------------------------- # 4. Ad-hoc sign the bundle. This is mandatory for the app to launch on # Apple Silicon and harmless on Intel. It is non-fatal: an unsigned bundle # still launches on Intel, so a signing hiccup must not fail the build. # --------------------------------------------------------------------------- echo "==> Ad-hoc signing bundle" if codesign --force --deep --sign - "$APP_SRC" 2>/dev/null; then echo " signed (ad-hoc)" else echo " WARN: ad-hoc signing failed; app should still run unsigned on Intel." fi echo # --------------------------------------------------------------------------- # 5. Publish the finished app to the output directory. # --------------------------------------------------------------------------- mkdir -p "$OUT_DIR" APP_DST="$OUT_DIR/$APP_NAME" if [ "$APP_SRC" != "$APP_DST" ]; then echo "==> Copying app to $APP_DST" rm -rf "$APP_DST" cp -R "$APP_SRC" "$APP_DST" fi echo echo "==> BUILD COMPLETE" echo " App: $APP_DST"