build: defer libwhich lookup in symlink_system_library#61243
build: defer libwhich lookup in symlink_system_library#61243IanButterworth merged 2 commits intomasterfrom
Conversation
Switch `libname_$2` and `libpath_$2` in `base/Makefile` from immediate (`:=`) to recursive (`=`) assignment in `symlink_system_library`. This avoids running `libwhich -p` while parsing the makefile. With immediate expansion, these probes are executed unconditionally, even when the corresponding `USE_SYSTEM_*` setting is disabled. On macOS, probing some names can abort in `libwhich` and pollute normal `make`, `make clean`, or `make cleanall` output. By deferring expansion to recipe execution, lookups happen only when the symlink target is actually needed. This fixes in particular annoying segfaults in libwhich on macOS when it tries to inspect libcrypto or libssl. Since USE_SYSTEM_OPENSSL=0 by default, the failed lookups don't matter but they look scary and if CrashReporter is active, can be also rather annoying. Resolves #57670 Co-authored-by: Codex <codex@openai.com>
base/Makefile
Outdated
| libname_$2 := $$(notdir $(call versioned_libname,$2,$3)) | ||
| libpath_$2 := $$(shell $$(call spawn,$$(LIBWHICH)) -p $$(libname_$2) 2>/dev/null) | ||
| libname_$2 = $$(notdir $(call versioned_libname,$2,$3)) | ||
| libpath_$2 = $$(shell $$(call spawn,$$(LIBWHICH)) -p $$(libname_$2) 2>/dev/null) |
There was a problem hiding this comment.
$(shell inside a recursive expansion is an antipattern, because the expansion point becomes unpredictable. My suggestion would be a simply-expanded $(eval inside the target definition. See e.g. https://stackoverflow.com/questions/1909188/define-make-variable-at-rule-execution-time
There was a problem hiding this comment.
Actually, I might be wrong about when $(eval runs. In that case these could be made shell variables. My point is to avoid the $(shell) in the recursive expansion.
There was a problem hiding this comment.
Never mind, just double checked, $(eval is fine.
There was a problem hiding this comment.
Although in this case may need to be $$(eval of course.
There was a problem hiding this comment.
OK, I (or rather Codex 😂) rewrote it with a different approach which I hope addresses your concern (at least it does seem sensible to me)
There was a problem hiding this comment.
Yes, codex did the In that case these could be made shell variables suggestion I made above, which works fine.
894fdaf to
4610f79
Compare
Run `libwhich -p` inside the symlink recipe shell instead of using `$(shell ...)` in a recursively expanded make variable. This keeps evaluation timing explicit and avoids unpredictable expansion behavior from recursive `$(shell ...)`. The lookup still happens only when the symlink target is built, so default builds and clean targets do not trigger unnecessary probes. This fixes in particular annoying segfaults in libwhich on macOS when it tries to inspect libcrypto or libssl. Since USE_SYSTEM_OPENSSL=0 by default, the failed lookups don't matter but they look scary and if CrashReporter is active, can be also rather annoying. Resolves #57670 Co-authored-by: Codex <codex@openai.com>
4610f79 to
1c6dec4
Compare
Co-authored-by: Codex <codex@openai.com> (cherry picked from commit 18827b7)
Co-authored-by: Codex <codex@openai.com> (cherry picked from commit 18827b7)
Run
libwhich -pinside the symlink recipe shell instead ofusing
$(shell ...)in a recursively expanded make variable.This keeps evaluation timing explicit and avoids unpredictable
expansion behavior from recursive
$(shell ...).The lookup still happens only when the symlink target is built,
so default builds and clean targets do not trigger unnecessary
probes.
This fixes in particular annoying segfaults in libwhich on macOS when
it tries to inspect libcrypto or libssl. Since USE_SYSTEM_OPENSSL=0
by default, the failed lookups don't matter but they look scary and
if CrashReporter is active, can be also rather annoying.
Resolves #57670
Co-authored-by: Codex codex@openai.com