Skip to content

Stop the installer raising the macOS command line developer tools dialog - #8478

Closed
danielhanchen wants to merge 1 commit into
mainfrom
macos-avoid-clt-install-dialog
Closed

danielhanchen wants to merge 1 commit into
mainfrom
macos-avoid-clt-install-dialog

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

The problem

On a Mac that has never had the Xcode Command Line Tools installed, /usr/bin/git, lipo, install_name_tool, clang and around 90 others are not real binaries. They are libxcselect shims: each calls xcselect_invoke_xcrun, and when no developer dir resolves it posts to com.apple.dt.CommandLineTools.installondemand over a CFMessagePort in the GUI session, which draws the "requires the command line developer tools" dialog naming the tool.

The dialog needs the shim to be executed. Resolving its path does not fire it, which is why command -v git is both safe and useless: /usr/bin/git exists on every Mac whether or not the tools are installed.

Users installing on a fresh Mac are getting that dialog.

What this fixes

Two places on the consumer path execute a shim.

_has_working_git ran git --version to decide whether git works, so on a clean Mac the probe raised the dialog it exists to detect. It now answers from the resolved path when that path is exactly /usr/bin/git and no toolchain is selected.

Deliberately narrow. A Homebrew, MacPorts or Xcode.app git earlier on PATH is a real binary and is still probed by executing it, so a Mac with a working git but no CLT selected behaves exactly as before. An earlier version of this gated on "no CLT implies no working git" and broke that case; tests/sh/test_macos_clt_gate.sh caught it. xcode-select -p only asks which toolchain is selected and never prompts (it is absent from its own man page's shim list), which is the same idiom Homebrew, Salt, Chef, MacPorts and nvm all use.

The venv arch probe called lipo first, falling back to file -L. lipo is a shim, and 2>/dev/null hides its stderr but not a GUI dialog. file is base system and always answers, so the order is swapped. Both spellings feed the same case below, matching Mach-O 64-bit executable arm64 or universal binary ... [x86_64] [arm64] against lipo's arm64 / x86_64 arm64, so the branch taken is unchanged. clean-machine-assert.sh:152 already made exactly this swap for its own use.

Why CI never caught it

The cctools binaries were missing from clean-machine-env.sh's TOOLS list, so trace mode generated no wrapper for them and the absent list never checked them. install_name_tool, lipo, otool, objdump, vtool, strip and nm are added, which is what makes any of this regression testable.

tests/sh/test_macos_clt_gate.sh gains two cases pinning the contract:

  • with a shim git and no toolchain selected, the probe answers no without executing it, proven by a stub that records execution into a marker file
  • with a real git elsewhere on PATH, the stub is executed

The first assertion passed vacuously when written (a wrong temp path meant the marker could never be created) and was corrected by making its pair fail first. 18 to 23 passing.

The remaining source, which this PR does not fix

The dialog most users actually see comes from uv, not from this repo. install_name_tool appears nowhere in our tree.

uv shells out to a bare install_name_tool to fix the managed CPython dylib's install name (crates/uv-python/src/macos_dylib.rs), reached from installation.rs on any automatic managed-Python download. Two aggravating details:

  • install.sh passes --python-preference only-managed to stop uv executing the /usr/bin/python3 shim, but that forces the managed CPython download, which is exactly what triggers install_name_tool. The existing mitigation makes the dialog more likely, not less.
  • uv python install iterates downloaded.chain(satisfied), so it re-invokes install_name_tool on already-installed interpreters. The dialog recurs rather than appearing once.

Upstream is aware and unfixed: astral-sh/uv#14843 is open, and astral-sh/uv#14893 ("Provide a way to skip install_name_tool invocation?") was filed by the Anki developer with the identical bundled-uv symptom. The proposed xcode-select -p guard is unmerged, and PR #14869 is unmerged too.

There is no supported way to silence it from our side. XCODE_SELECT_NO_PROMPT and defaults write keys do not exist, in the man page, in libxcselect.dylib's symbols, or anywhere else. The two real options, both larger than this PR and worth deciding separately:

  1. Bundle the Python runtime in the app, pre-relocated on CI where CLT exists, with UV_NO_MANAGED_PYTHON=1. Removes the call by construction and is robust to uv changing internals. Costs bundle size and we own Python updates.
  2. Set DEVELOPER_DIR to a sentinel only once xcode-select -p has already failed, converting the dialog into a silent non-zero exit. Cheap, but it rests on undocumented was_default gating and turns a visible prompt into a silent failure.

Note that CI can verify the call never happens (trace mode, now wired up) but cannot verify the dialog itself, which needs a GUI bootstrap namespace a headless runner does not have.

On a Mac without the Command Line Tools, /usr/bin/git, lipo, install_name_tool
and friends are libxcselect shims. Executing one resolves no developer dir and
posts to com.apple.dt.CommandLineTools.installondemand, which draws the
'requires the command line developer tools' dialog naming the tool. Resolving
the path does not; only execution does.

Two call sites execute a shim on the consumer path:

_has_working_git ran 'git --version' to decide whether git works, so on a clean
Mac the probe raised the dialog it exists to detect. It now answers from the
resolved path when that path is exactly /usr/bin/git and no toolchain is
selected. Deliberately narrow: a Homebrew, MacPorts or Xcode.app git earlier on
PATH is a real binary and is still probed by executing it, so a Mac with a
working git but no CLT selected behaves exactly as before. An earlier version of
this gated on 'no CLT implies no working git' and broke that case, which the
existing test caught. xcode-select -p only asks which toolchain is selected and
never prompts.

The venv arch probe called lipo first and fell back to file -L. lipo is a shim;
2>/dev/null hides its stderr but not a GUI dialog. file is base system and
always answers, so the order is swapped. Both spellings feed the same case
below, against 'Mach-O 64-bit executable arm64' or 'universal binary ...
[x86_64] [arm64]' rather than lipo's 'arm64' / 'x86_64 arm64', so the branch
taken is unchanged. clean-machine-assert.sh already made this same swap for its
own use.

The cctools binaries were missing from the clean machine CI tool list, so none
of this was visible: trace mode generated no wrapper and the absent list never
checked them. install_name_tool, lipo, otool, objdump, vtool, strip and nm are
added, which is what makes these fixes regression testable.

test_macos_clt_gate.sh gains two cases pinning the contract: with a shim git and
no toolchain selected the probe answers no WITHOUT executing it, proven by a
stub that records execution into a marker file, and with a real git elsewhere on
PATH the stub IS executed. The first assertion passed vacuously when written
(wrong temp path meant the marker could never be created) and was fixed by
making its pair fail first. 18 to 23 passing.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: feb85dd190

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +55 to +56
TOOLS="xcode-select xcrun clang clang++ cc c++ gcc g++ git cmake make brew ninja cargo rustc
install_name_tool lipo otool objdump vtool strip nm"

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Avoid failing the trace row on uv's known relocation call

In the nonexperimental macos-15 trace row of .github/workflows/clean-machine-install-ci.yml, the installer creates an explicit uv-managed CPython and then runs clean-machine-assert.sh notools; adding install_name_tool here wraps and records the macOS relocation call that this change itself identifies as still being made by uv. Since notools treats every recorded tool except read-only xcode-select as a failure and this row does not allowlist install_name_tool, a fresh runner that downloads managed CPython will fail the required post-install assertion even though the installation succeeds. Either eliminate that invocation first or account for the known upstream call without making this required trace job permanently red.

Useful? React with 👍 / 👎.

Comment thread install.sh
Comment on lines +2121 to +2122
[ "$(command -v git)" = "${_CLT_GIT_SHIM:-/usr/bin/git}" ] &&
! xcode-select -p >/dev/null 2>&1; then

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Probe Intel's real /usr/bin/git before rejecting it

On the supported Intel macOS configuration, /usr/bin/git can be a functional non-CLT binary even while xcode-select -p fails—the repository's clean-machine workflow and assertion explicitly document and allow this on macos-15-intel. This path-only check nevertheless classifies it as the CLT shim and returns without executing it, so a --local install on such an Intel Mac incorrectly reports that git is unavailable and demands the Command Line Tools despite already having working git.

Useful? React with 👍 / 👎.

@wasimysaid

Copy link
Copy Markdown
Collaborator

Superseded by #8479. I cherry-picked feb85dd190 into that PR as 8407e950a, preserving Daniel’s authorship, and retained the git/lipo/cctools changes alongside the scoped uv install_name_tool guard. Closing this one as agreed.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. What shall we delve into next?

Reviewed commit: feb85dd190

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants