File size: 4,940 Bytes
3fbbdd9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/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:-<unset>}'." >&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"