forked from warpdotdev/warp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-tui
More file actions
executable file
·149 lines (133 loc) · 4.94 KB
/
Copy pathrun-tui
File metadata and controls
executable file
·149 lines (133 loc) · 4.94 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
147
148
149
#!/bin/bash
#
# Run a local `warp_tui` build.
#
# Selects the internal `local` channel when the `warp-channel-config` generator
# is available (mirroring `./script/run`), otherwise falls back to the OSS
# channel so contributors without repo access can still run the TUI. Unlike the
# GUI `./script/run`, the TUI is a console binary, so there is no `.app` bundle
# step.
#
# On macOS the binary is built with `cargo build` and then codesigned with a
# stable "Apple Development" identity (mirroring `./script/macos/run`). Keychain
# item ACLs key off the code signature, so a stable signature means rebuilds
# don't re-prompt for your keychain password. Ad-hoc signatures from a plain
# `cargo run` change on every build, which is what causes repeated prompts.
#
# Extra arguments are forwarded to `cargo` (e.g. `--release`); use `--` to
# pass arguments through to the binary itself.
set -e
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
cd "${REPO_ROOT}"
./script/install_channel_config || echo "Skipping internal channel config installation (no repo access)."
if command -v warp-channel-config &>/dev/null; then
BIN="warp-tui"
CHANNEL="local"
else
BIN="warp-tui-oss"
CHANNEL="oss"
fi
# Split cargo arguments from binary arguments (after `--`), tracking the profile
# and target triple so we can locate the built binary (for codesigning on macOS)
# and stage resources beside it, matching where Cargo actually writes the output.
CARGO_ARGS=()
BIN_ARGS=()
PROFILE_DIR="debug"
TARGET_TRIPLE=""
while (( "$#" )); do
case "$1" in
--)
shift
BIN_ARGS=("$@")
break
;;
--release)
PROFILE_DIR="release"
CARGO_ARGS+=("$1")
shift
;;
--profile)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
PROFILE_DIR="$2"
CARGO_ARGS+=("$1" "$2")
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
--target)
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
TARGET_TRIPLE="$2"
CARGO_ARGS+=("$1" "$2")
shift 2
else
echo "Error: Argument for $1 is missing" >&2
exit 1
fi
;;
--target=*)
TARGET_TRIPLE="${1#--target=}"
CARGO_ARGS+=("$1")
shift
;;
*)
CARGO_ARGS+=("$1")
shift
;;
esac
done
# Build with the `standalone` feature so `bundled_resources_dir()` resolves the
# sibling `resources/` directory next to the executable at runtime (matching how
# the packaged TUI is built in script/macos/bundle). Without it, the app can't
# locate its bundled skills when run outside a `.app` bundle.
CARGO_ARGS+=(--features standalone)
# Resolve Cargo's actual target directory rather than assuming ./target
# (honors CARGO_TARGET_DIR / build.target-dir).
TARGET_DIR="$(cargo metadata --no-deps --format-version 1 | jq -r .target_directory)"
if [ -z "$TARGET_DIR" ] || [ "$TARGET_DIR" = "null" ]; then
TARGET_DIR="${REPO_ROOT}/target"
fi
# Cargo writes to target/<triple>/<profile> when building for an explicit
# --target, and target/<profile> otherwise. Mirror that layout so we stage
# resources beside — and exec — the exact binary Cargo produced.
BUILD_DIR="${TARGET_DIR}"
if [ -n "${TARGET_TRIPLE}" ]; then
BUILD_DIR="${BUILD_DIR}/${TARGET_TRIPLE}"
fi
BUILD_DIR="${BUILD_DIR}/${PROFILE_DIR}"
# Stage bundled skills and the settings schema next to the binary so the
# standalone TUI can resolve them at runtime. License generation remains skipped
# for local runs. Reuse the selected Cargo profile for schema generation so its
# dependencies do not need to be rebuilt in a separate profile.
prepare_tui_bundled_resources() {
echo "Preparing bundled resources at ${BUILD_DIR}/resources (channel: ${CHANNEL})..."
if [ "${PROFILE_DIR}" = "debug" ]; then
NO_LICENSES=1 "${REPO_ROOT}/script/prepare_bundled_resources" \
"${BUILD_DIR}/resources" "${CHANNEL}"
else
NO_LICENSES=1 "${REPO_ROOT}/script/prepare_bundled_resources" \
"${BUILD_DIR}/resources" "${CHANNEL}" "${PROFILE_DIR}"
fi
}
if [[ "$(uname -s)" = "Darwin" ]]; then
echo "Building cargo build -p warp_tui --bin ${BIN} (channel: ${CHANNEL})"
cargo build -p warp_tui --bin "${BIN}" "${CARGO_ARGS[@]}"
prepare_tui_bundled_resources
TUI_BIN_PATH="${BUILD_DIR}/${BIN}"
SIGNING_CERT="$(security find-identity -p codesigning -v | grep "Apple Development" | awk '{print $2}' | head -1)"
if [ -n "$SIGNING_CERT" ]; then
echo "Codesigning ${TUI_BIN_PATH}..."
codesign --force --sign "$SIGNING_CERT" "$TUI_BIN_PATH"
else
echo "Warning: no Apple Development signing identity found; skipping codesign (keychain may re-prompt on rebuilds)." >&2
fi
exec "$TUI_BIN_PATH" "${BIN_ARGS[@]}"
else
echo "Building cargo build -p warp_tui --bin ${BIN} (channel: ${CHANNEL})"
cargo build -p warp_tui --bin "${BIN}" "${CARGO_ARGS[@]}"
prepare_tui_bundled_resources
TUI_BIN_PATH="${BUILD_DIR}/${BIN}"
echo "Running ${TUI_BIN_PATH}"
exec "${TUI_BIN_PATH}" "${BIN_ARGS[@]}"
fi