Skip to content

Commit 9e437d5

Browse files
abueideclaude
andcommitted
refactor(ios): extract helper functions from devbox_omit_nix_env
Extract devbox path resolution into focused helpers: - ios_resolve_devbox_project_bin() - finds .devbox/bin directory - ios_resolve_devbox_config() - finds devbox.json config file This keeps devbox_omit_nix_env() focused on environment cleanup. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 434c538 commit 9e437d5

1 file changed

Lines changed: 27 additions & 25 deletions

File tree

  • plugins/ios/virtenv/scripts/platform

plugins/ios/virtenv/scripts/platform/core.sh

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -136,34 +136,35 @@ ios_resolve_devbox_bin() {
136136
# Environment Setup
137137
# ============================================================================
138138

139+
# Resolves devbox project bin directory
140+
ios_resolve_devbox_project_bin() {
141+
if [ -n "${DEVBOX_PROJECT_ROOT:-}" ] && [ -d "${DEVBOX_PROJECT_ROOT}/.devbox/bin" ]; then
142+
printf '%s\n' "${DEVBOX_PROJECT_ROOT}/.devbox/bin"
143+
elif [ -n "${DEVBOX_WD:-}" ] && [ -d "${DEVBOX_WD}/.devbox/bin" ]; then
144+
printf '%s\n' "${DEVBOX_WD}/.devbox/bin"
145+
fi
146+
}
147+
148+
# Resolves devbox config path
149+
ios_resolve_devbox_config() {
150+
if [ -n "${DEVBOX_CONFIG:-}" ] && [ -f "$DEVBOX_CONFIG" ]; then
151+
printf '%s\n' "$DEVBOX_CONFIG"
152+
elif [ -n "${DEVBOX_CONFIG_PATH:-}" ] && [ -f "$DEVBOX_CONFIG_PATH" ]; then
153+
printf '%s\n' "$DEVBOX_CONFIG_PATH"
154+
elif [ -n "${DEVBOX_CONFIG_DIR:-}" ] && [ -f "${DEVBOX_CONFIG_DIR%/}/devbox.json" ]; then
155+
printf '%s\n' "${DEVBOX_CONFIG_DIR%/}/devbox.json"
156+
fi
157+
}
158+
139159
# Setup omit-nix-env for iOS (use system Xcode/tools instead of Nix)
140160
devbox_omit_nix_env() {
141161
if [ "${DEVBOX_OMIT_NIX_ENV_APPLIED:-}" = "1" ]; then
142162
return 0
143163
fi
144164

145-
devbox_init_path="${DEVBOX_INIT_PATH:-}"
146-
devbox_bin_dir=""
147-
devbox_project_bin=""
148-
149165
devbox_bin="$(ios_resolve_devbox_bin 2>/dev/null || true)"
150166
if [ -n "$devbox_bin" ]; then
151-
devbox_bin_dir="$(dirname "$devbox_bin")"
152-
if [ -n "${DEVBOX_PROJECT_ROOT:-}" ] && [ -d "${DEVBOX_PROJECT_ROOT}/.devbox/bin" ]; then
153-
devbox_project_bin="${DEVBOX_PROJECT_ROOT}/.devbox/bin"
154-
elif [ -n "${DEVBOX_WD:-}" ] && [ -d "${DEVBOX_WD}/.devbox/bin" ]; then
155-
devbox_project_bin="${DEVBOX_WD}/.devbox/bin"
156-
fi
157-
158-
devbox_config_path=""
159-
if [ -n "${DEVBOX_CONFIG:-}" ] && [ -f "$DEVBOX_CONFIG" ]; then
160-
devbox_config_path="$DEVBOX_CONFIG"
161-
elif [ -n "${DEVBOX_CONFIG_PATH:-}" ] && [ -f "$DEVBOX_CONFIG_PATH" ]; then
162-
devbox_config_path="$DEVBOX_CONFIG_PATH"
163-
elif [ -n "${DEVBOX_CONFIG_DIR:-}" ] && [ -f "${DEVBOX_CONFIG_DIR%/}/devbox.json" ]; then
164-
devbox_config_path="${DEVBOX_CONFIG_DIR%/}/devbox.json"
165-
fi
166-
167+
devbox_config_path="$(ios_resolve_devbox_config)"
167168
if [ -n "$devbox_config_path" ]; then
168169
eval "$("$devbox_bin" --config "$devbox_config_path" shellenv --install --no-refresh-alias --omit-nix-env=true)"
169170
else
@@ -176,7 +177,6 @@ devbox_omit_nix_env() {
176177
# Darwin cleanup — runs unconditionally (even if devbox binary not found)
177178
if [ "$(uname -s)" = "Darwin" ]; then
178179
# Unset standard build variables that Xcode tools read
179-
# (shellenv --omit-nix-env handles the Nix-specific ones like NIX_LDFLAGS)
180180
unset LD LDFLAGS CFLAGS
181181

182182
if [ -x /usr/bin/clang ]; then
@@ -197,16 +197,18 @@ devbox_omit_nix_env() {
197197
unset SDKROOT
198198
fi
199199

200-
# Re-add preserved paths
200+
# Re-add devbox paths to PATH
201+
devbox_init_path="${DEVBOX_INIT_PATH:-}"
201202
if [ -n "$devbox_init_path" ]; then
202203
PATH="${devbox_init_path}:${PATH}"
203204
fi
205+
if [ -n "$devbox_bin" ]; then
206+
PATH="$(dirname "$devbox_bin"):${PATH}"
207+
fi
208+
devbox_project_bin="$(ios_resolve_devbox_project_bin)"
204209
if [ -n "$devbox_project_bin" ]; then
205210
PATH="${devbox_project_bin}:${PATH}"
206211
fi
207-
if [ -n "$devbox_bin_dir" ]; then
208-
PATH="${devbox_bin_dir}:${PATH}"
209-
fi
210212
export PATH
211213

212214
# Flag set AFTER all cleanup succeeds

0 commit comments

Comments
 (0)