Repository navigation
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·146 lines (130 loc) · 6.79 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·146 lines (130 loc) · 6.79 KB
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/env bash
#
# Build / install / register SelectedTextTTS without Xcode (Command Line Tools only).
#
# Usage:
# ./build.sh Build the .app, install to ~/Applications, register Services.
# ./build.sh dev Build, then run the binary directly in the foreground so
# stdout/stderr (and os_log) are visible in THIS terminal.
# ./build.sh build Build the .app into ./build only (no install, no register).
# ./build.sh logs Tail this app's unified logs.
# ./build.sh clean Remove ./build.
#
set -euo pipefail
APP_NAME="Codebasic TTS"
OLD_APP_NAME="SelectedTextTTS" # previous bundle name, cleaned up on install
BUNDLE_ID="com.seongjoo.SelectedTextTTS"
HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="$HERE/build"
APP_DIR="$BUILD_DIR/$APP_NAME.app"
MACOS_DIR="$APP_DIR/Contents/MacOS"
RES_DIR="$APP_DIR/Contents/Resources"
INSTALL_DIR="$HOME/Applications"
LSREGISTER="/System/Library/Frameworks/CoreServices.framework/Frameworks/LaunchServices.framework/Support/lsregister"
build() {
echo "==> Compiling Swift sources"
rm -rf "$APP_DIR"
mkdir -p "$MACOS_DIR" "$RES_DIR"
# shellcheck disable=SC2046
swiftc -O \
-o "$MACOS_DIR/$APP_NAME" \
$(find "$HERE/Sources" -name '*.swift') \
-framework AppKit -framework SwiftUI -framework AVFoundation \
-framework Carbon -framework ApplicationServices \
-lsqlite3
cp "$HERE/Resources/Info.plist" "$APP_DIR/Contents/Info.plist"
[ -f "$HERE/Resources/AppIcon.icns" ] && cp "$HERE/Resources/AppIcon.icns" "$RES_DIR/AppIcon.icns"
printf 'APPL????' > "$APP_DIR/Contents/PkgInfo"
# Prefer a STABLE self-signed identity so TCC grants (Accessibility, needed for
# the global hotkeys) survive rebuilds. Ad-hoc signing rebinds the designated
# requirement to the cdhash every build, which silently invalidates the grant.
# Create the cert once (see README "Stable signing"); falls back to ad-hoc.
# Note: no -v — a self-signed local cert is untrusted (CSSMERR_TP_NOT_TRUSTED),
# so it's excluded by -v, but codesign still signs with it and the resulting
# designated requirement (cert-leaf hash) is stable across rebuilds, which is
# all TCC needs.
SIGN_ID="${CODESIGN_IDENTITY:-Codebasic TTS Local}"
if security find-identity -p codesigning 2>/dev/null | grep -qF "$SIGN_ID"; then
echo "==> Code signing with stable identity: $SIGN_ID"
codesign --force --deep --sign "$SIGN_ID" "$APP_DIR" >/dev/null 2>&1 || \
echo " (codesign with '$SIGN_ID' failed)"
else
echo "==> Ad-hoc code signing (no '$SIGN_ID' identity → Accessibility grant resets each rebuild)"
codesign --force --sign - "$APP_DIR" >/dev/null 2>&1 || \
echo " (codesign skipped/failed — fine for local runs)"
fi
echo "==> Built: $APP_DIR"
}
install_and_register() {
echo "==> Stopping any running instance (so 'open' launches the new binary, not the old one)"
pkill -f "$APP_NAME.app/Contents/MacOS/$APP_NAME" 2>/dev/null || true
pkill -f "$OLD_APP_NAME.app/Contents/MacOS/$OLD_APP_NAME" 2>/dev/null || true
sleep 1
echo "==> Removing the old '$OLD_APP_NAME' bundle if present (renamed to '$APP_NAME')"
if [ -d "$INSTALL_DIR/$OLD_APP_NAME.app" ]; then
"$LSREGISTER" -u "$INSTALL_DIR/$OLD_APP_NAME.app" 2>/dev/null || true
rm -rf "$INSTALL_DIR/$OLD_APP_NAME.app"
fi
echo "==> Installing to $INSTALL_DIR (Launch Services only scans ~/Applications and /Applications)"
mkdir -p "$INSTALL_DIR"
rm -rf "$INSTALL_DIR/$APP_NAME.app"
cp -R "$APP_DIR" "$INSTALL_DIR/$APP_NAME.app"
echo "==> API keys are managed in-app (Settings → 음성 합성 / 텍스트 생성); none are"
echo " provisioned from the repo. Keys live in Application Support, entered via the UI."
echo "==> Registering with Launch Services"
"$LSREGISTER" -f "$INSTALL_DIR/$APP_NAME.app"
echo "==> Refreshing the Services / pasteboard server"
/System/Library/CoreServices/pbs -update >/dev/null 2>&1 || true
/System/Library/CoreServices/pbs -flush >/dev/null 2>&1 || true
echo "==> Launching the installed app (registers the dynamic service)"
open "$INSTALL_DIR/$APP_NAME.app"
cat <<EOF
Done. Regular Dock app — the management window opens on launch; closing it keeps
the app running in the background. Click the Dock icon to reopen.
To smoke-test the Services path:
1. In TextEdit (or any app), select some text.
2. Right-click → Services → "Codebasic TTS".
3. It speaks via ElevenLabs; a floating HUD shows pause/stop (focus stays on
the source window). Watch logs: ./build.sh logs
EOF
}
case "${1:-install}" in
build) build ;;
dev)
build
echo "==> Running in foreground (Ctrl-C to stop). os_log mirrors to stderr here."
exec "$MACOS_DIR/$APP_NAME"
;;
logs)
exec log stream --predicate "subsystem == \"$BUNDLE_ID\"" --level debug
;;
test)
echo "==> Compiling + running unit tests"
mkdir -p "$BUILD_DIR"
swiftc -O "$HERE/Sources/Core/TextSplitter.swift" "$HERE/Sources/Core/CrawlLayout.swift" \
"$HERE/Sources/App/Endpoints.swift" "$HERE/Tests/main.swift" -o "$BUILD_DIR/tests"
"$BUILD_DIR/tests"
swiftc -O "$HERE/Sources/Core/ElevenModelCatalog.swift" "$HERE/Tests/ElevenModelCatalogTests.swift" \
-o "$BUILD_DIR/model-tests"
"$BUILD_DIR/model-tests"
swiftc -O "$HERE/Sources/Core/Logging.swift" "$HERE/Sources/Core/MemoryDiagnostics.swift" \
"$HERE/Tests/MemoryDiagnosticsTests.swift" -o "$BUILD_DIR/memory-tests"
"$BUILD_DIR/memory-tests"
swiftc -O "$HERE/Sources/App/CodexPlan.swift" "$HERE/Sources/App/AntigravityPlan.swift" "$HERE/Sources/App/Secrets.swift" \
"$HERE/Sources/TTS/TextNormalizer.swift" "$HERE/Sources/Core/ExplanationConversation.swift" "$HERE/Sources/Core/Logging.swift" "$HERE/Sources/Core/MemoryDiagnostics.swift" "$HERE/Tests/ConnectionTests.swift" \
-framework AppKit -o "$BUILD_DIR/connection-tests"
"$BUILD_DIR/connection-tests" "$HERE/Tests/Fixtures/fake-codex.py"
swiftc -O "$HERE/Sources/Core/ExplanationConversation.swift" "$HERE/Tests/ExplanationConversationTests.swift" \
-o "$BUILD_DIR/conversation-tests"
"$BUILD_DIR/conversation-tests"
swiftc -O "$HERE/Sources/App/CodexPlan.swift" "$HERE/Sources/App/AntigravityPlan.swift" "$HERE/Sources/App/Secrets.swift" \
"$HERE/Sources/App/Endpoints.swift" "$HERE/Sources/TTS/TextNormalizer.swift" "$HERE/Sources/TTS/EndpointGenerator.swift" \
"$HERE/Sources/Core/ExplanationConversation.swift" "$HERE/Sources/Core/NormalizationCache.swift" \
"$HERE/Sources/Core/Logging.swift" "$HERE/Sources/Core/MemoryDiagnostics.swift" "$HERE/Tests/ExplanationStyleTests.swift" \
-framework AppKit -o "$BUILD_DIR/explanation-style-tests"
"$BUILD_DIR/explanation-style-tests"
;;
clean) rm -rf "$BUILD_DIR"; echo "cleaned" ;;
install|"") build; install_and_register ;;
*) echo "unknown command: $1"; exit 2 ;;
esac