Skip to content

Commit 6c4edfd

Browse files
knoctesteipete
andauthored
fix(public/install.sh): fail early if req buildtools are missing (#49)
* fix(public/install.sh): fail early if req buildtools are missing Would fix some of the issues some people have been reporting in: https://github.com/openclaw/openclaw/discussions/5462 [AI assisted via Codex 5.2] * fix(install): auto-install build tools after npm native build failures * fix(install): auto-install build tools on native npm failures * fix: land installer build-tool auto-recovery (#49) (thanks @knocte) --------- Co-authored-by: Peter Steinberger <steipete@gmail.com>
1 parent 39827f7 commit 6c4edfd

File tree

3 files changed

+189
-1
lines changed

3 files changed

+189
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 2026-02-13
44

5+
- Installer: auto-detect missing native build toolchain from npm logs, attempt OS-specific install, and retry package install instead of failing early (#49, thanks @knocte).
56
- Installer: render gum choose header on two lines (real newline, not literal `\n`) for checkout detection prompt (#55, thanks @echoja).
67

78
## 2026-02-10

public/install.sh

Lines changed: 121 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,112 @@ cleanup_openclaw_bin_conflict() {
506506
return 1
507507
}
508508

509+
npm_log_indicates_missing_build_tools() {
510+
local log="$1"
511+
if [[ -z "$log" || ! -f "$log" ]]; then
512+
return 1
513+
fi
514+
515+
grep -Eiq "(not found: make|make: command not found|cmake: command not found|CMAKE_MAKE_PROGRAM is not set|Could not find CMAKE|gyp ERR! find Python|no developer tools were found|is not able to compile a simple test program|Failed to build llama\\.cpp|It seems that \"make\" is not installed in your system|It seems that the used \"cmake\" doesn't work properly)" "$log"
516+
}
517+
518+
install_build_tools_linux() {
519+
require_sudo
520+
521+
if command -v apt-get &> /dev/null; then
522+
if is_root; then
523+
run_quiet_step "Updating package index" apt-get update -qq
524+
run_quiet_step "Installing build tools" apt-get install -y -qq build-essential python3 make g++ cmake
525+
else
526+
run_quiet_step "Updating package index" sudo apt-get update -qq
527+
run_quiet_step "Installing build tools" sudo apt-get install -y -qq build-essential python3 make g++ cmake
528+
fi
529+
return 0
530+
fi
531+
532+
if command -v dnf &> /dev/null; then
533+
if is_root; then
534+
run_quiet_step "Installing build tools" dnf install -y -q gcc gcc-c++ make cmake python3
535+
else
536+
run_quiet_step "Installing build tools" sudo dnf install -y -q gcc gcc-c++ make cmake python3
537+
fi
538+
return 0
539+
fi
540+
541+
if command -v yum &> /dev/null; then
542+
if is_root; then
543+
run_quiet_step "Installing build tools" yum install -y -q gcc gcc-c++ make cmake python3
544+
else
545+
run_quiet_step "Installing build tools" sudo yum install -y -q gcc gcc-c++ make cmake python3
546+
fi
547+
return 0
548+
fi
549+
550+
if command -v apk &> /dev/null; then
551+
if is_root; then
552+
run_quiet_step "Installing build tools" apk add --no-cache build-base python3 cmake
553+
else
554+
run_quiet_step "Installing build tools" sudo apk add --no-cache build-base python3 cmake
555+
fi
556+
return 0
557+
fi
558+
559+
ui_warn "Could not detect package manager for auto-installing build tools"
560+
return 1
561+
}
562+
563+
install_build_tools_macos() {
564+
local ok=true
565+
566+
if ! xcode-select -p >/dev/null 2>&1; then
567+
ui_info "Installing Xcode Command Line Tools (required for make/clang)"
568+
xcode-select --install >/dev/null 2>&1 || true
569+
if ! xcode-select -p >/dev/null 2>&1; then
570+
ui_warn "Xcode Command Line Tools are not ready yet"
571+
ui_info "Complete the installer dialog, then re-run this installer"
572+
ok=false
573+
fi
574+
fi
575+
576+
if ! command -v cmake >/dev/null 2>&1; then
577+
if command -v brew >/dev/null 2>&1; then
578+
run_quiet_step "Installing cmake" brew install cmake
579+
else
580+
ui_warn "Homebrew not available; cannot auto-install cmake"
581+
ok=false
582+
fi
583+
fi
584+
585+
if ! command -v make >/dev/null 2>&1; then
586+
ui_warn "make is still unavailable"
587+
ok=false
588+
fi
589+
if ! command -v cmake >/dev/null 2>&1; then
590+
ui_warn "cmake is still unavailable"
591+
ok=false
592+
fi
593+
594+
[[ "$ok" == "true" ]]
595+
}
596+
597+
auto_install_build_tools_for_npm_failure() {
598+
local log="$1"
599+
if ! npm_log_indicates_missing_build_tools "$log"; then
600+
return 1
601+
fi
602+
603+
ui_warn "Detected missing native build tools; attempting automatic setup"
604+
if [[ "$OS" == "linux" ]]; then
605+
install_build_tools_linux || return 1
606+
elif [[ "$OS" == "macos" ]]; then
607+
install_build_tools_macos || return 1
608+
else
609+
return 1
610+
fi
611+
ui_success "Build tools setup complete"
612+
return 0
613+
}
614+
509615
run_npm_global_install() {
510616
local spec="$1"
511617
local log="$2"
@@ -539,8 +645,22 @@ install_openclaw_npm() {
539645
local log
540646
log="$(mktempfile)"
541647
if ! run_npm_global_install "$spec" "$log"; then
648+
local attempted_build_tool_fix=false
649+
if auto_install_build_tools_for_npm_failure "$log"; then
650+
attempted_build_tool_fix=true
651+
ui_info "Retrying npm install after build tools setup"
652+
if run_npm_global_install "$spec" "$log"; then
653+
ui_success "OpenClaw npm package installed"
654+
return 0
655+
fi
656+
fi
657+
542658
if [[ "$VERBOSE" != "1" ]]; then
543-
ui_warn "npm install failed; showing last log lines"
659+
if [[ "$attempted_build_tool_fix" == "true" ]]; then
660+
ui_warn "npm install still failed after build tools setup; showing last log lines"
661+
else
662+
ui_warn "npm install failed; showing last log lines"
663+
fi
544664
tail -n 80 "$log" >&2 || true
545665
fi
546666

scripts/test-install-sh-unit.sh

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,73 @@ EOF
266266
assert_eq "${PNPM_CMD[*]}" "pnpm" "ensure_pnpm (npm fallback)"
267267
)
268268

269+
echo "==> case: npm_log_indicates_missing_build_tools"
270+
(
271+
root="${TMP_DIR}/case-build-tools-signature"
272+
mkdir -p "${root}"
273+
274+
positive_log="${root}/positive.log"
275+
negative_log="${root}/negative.log"
276+
277+
cat >"${positive_log}" <<'EOF'
278+
gyp ERR! stack Error: not found: make
279+
EOF
280+
cat >"${negative_log}" <<'EOF'
281+
npm ERR! code EEXIST
282+
EOF
283+
284+
if ! npm_log_indicates_missing_build_tools "${positive_log}"; then
285+
fail "npm_log_indicates_missing_build_tools should detect missing build tools"
286+
fi
287+
if npm_log_indicates_missing_build_tools "${negative_log}"; then
288+
fail "npm_log_indicates_missing_build_tools false positive"
289+
fi
290+
)
291+
292+
echo "==> case: install_openclaw_npm (auto-install build tools + retry)"
293+
(
294+
root="${TMP_DIR}/case-install-openclaw-auto-build-tools"
295+
mkdir -p "${root}"
296+
297+
export OS="linux"
298+
export VERBOSE=0
299+
export GUM=""
300+
301+
install_attempts=0
302+
auto_install_called=0
303+
304+
run_npm_global_install() {
305+
local _spec="$1"
306+
local log="$2"
307+
install_attempts=$((install_attempts + 1))
308+
if [[ "$install_attempts" -eq 1 ]]; then
309+
cat >"${log}" <<'EOF'
310+
gyp ERR! stack Error: not found: make
311+
EOF
312+
return 1
313+
fi
314+
cat >"${log}" <<'EOF'
315+
ok
316+
EOF
317+
return 0
318+
}
319+
320+
auto_install_build_tools_for_npm_failure() {
321+
local _log="$1"
322+
auto_install_called=1
323+
return 0
324+
}
325+
326+
ui_info() { :; }
327+
ui_success() { :; }
328+
ui_warn() { :; }
329+
ui_error() { :; }
330+
331+
install_openclaw_npm "openclaw@latest"
332+
assert_eq "$install_attempts" "2" "install_openclaw_npm retry count"
333+
assert_eq "$auto_install_called" "1" "install_openclaw_npm auto-install hook"
334+
)
335+
269336
echo "==> case: install_openclaw_from_git (deps step uses run_pnpm function)"
270337
(
271338
root="${TMP_DIR}/case-install-git-deps"

0 commit comments

Comments
 (0)