Expand description
Tool and PATH resolution for every Subspace app.
A desktop app started from Finder, the Dock, a desktop entry or the Start
Menu does not inherit the PATH a terminal has. On macOS launchd gives it
/usr/bin:/bin:/usr/sbin:/sbin, so Azure CLI from Homebrew
(/opt/homebrew/bin/az) is not found. The host calls apply once at
startup, before any thread exists. It asks the user’s login shell (on
Windows, the registry) for the PATH a terminal has and merges it with the
inherited one. When the shell fails, it adds the PATH that worked last
time (PathCache) and then the usual install folders of the platform
(FALLBACK_DIRECTORIES). Child processes inherit the result.
The same login shell also supplies the proxy and certificate variables
(network) that this process lacks. They are never written to the cache.
Every lookup of an external program uses find_tool: PATH first, then
the path where the tool was found last time. Do not add other PATH
lookups.
Modules§
- network
- The network variables a child process such as the Azure CLI gets: proxy settings and certificate bundles.
Structs§
- Cached
Path - A saved
PATHthatsuper::applyused because the shell failed. - Cached
Tool - A saved tool path that a lookup tried after
PATHhad no such tool. - Path
Cache - The cache file.
- Resolved
- The outcome of
apply: the mergedPATHand how it was made. - Startup
- What the host passes to
apply.
Enums§
- Cache
Source - Where a saved
PATHcame from. - Capture
- The result of asking the login shell (or, on Windows, the registry) for
the
PATHa terminal has. - Source
- Where the effective
PATHcame from, for display and diagnostics. - Tool
Error - Why
find_toolfound nothing. The texts match Goexec.LookPath.
Constants§
- CACHED_
SHELL_ TIMEOUT - The shorter limit when a saved
PATHcan stand in for a slow shell. - CACHE_
FILE - The cache file name, beside the product’s
state.json. - DISABLE_
ENV - Set to
0to keep the inheritedPATH. - DISABLE_
ENV_ ALIAS - The short name of
DISABLE_ENV; either one set to0works. - FALLBACK_
DIRECTORIES - The list for this platform.
- LINUX_
DIRECTORIES - Linux install folders. The deb and rpm packages put
azin/usr/bin, which everyPATHalready holds. - MACOS_
DIRECTORIES - macOS install folders.
- SHELL_
TIMEOUT - How long the login shell may take to start and print its environment
when no saved
PATHexists. This is the worst-case delay of a start: a fast shell returns at the end marker, so only a slow or stuck shell waits this long. Startup files that load nvm or endpoint-security agents can take several seconds just after the computer starts. There is one attempt, never a second one. - WINDOWS_
DIRECTORIES - Windows install folders. There is no
%LOCALAPPDATA%entry: the Azure CLI MSI installs per machine only, and the ZIP package goes to a folder the user chooses, which no list can know.
Functions§
- applied
- What
applyset, if it ran. - apply⚠
- Resolve the full
PATH, set it and the missing network variables for this process, and save thePATHwhen it is known good. - cache_
path <state dir>/path-cache.json.- find_
tool - Find an external program. A name with a path separator is used as given.
Otherwise the first executable match wins, in this order: each
PATHfolder; the path where the tool was found last time, if it still exists and is executable; the platform’s usual install folders (super::FALLBACK_DIRECTORIES) that exist. The last two steps run only aftersuper::apply: they use its cache file and its folders, so a test that never applies the startupPATHnever finds a tool outsidePATH. The last step also covers a start from a terminal whosePATHlacks, for example, Homebrew. APATHor install-folder result is saved, as an absolute path, when it differs from the saved path; an install-folder result is logged once per tool. - find_
tool_ readonly - Resolve a tool using the same search order as
find_toolwithout saving paths or recording and logging cache or fallback use. No process is started. - read_
cache - The cache in
file, orNonewhen it is missing, unreadable, not JSON, of another schema or of the wrong shape. Such a file is replaced at the next good save. A relative tool path in the file is dropped: it depends on a working directory that is not known. - shell_
timeout - The login-shell time limit: shorter when a saved
PATHexists.