mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Set TMPDIR for Xcode’s make
This fixes an issue where at least in Xcode 11.0, `make` uses `/var/tmp` as a fallback for temporary files unless `TMPDIR` is set: ``` $ strings "$(xcrun -f make)" | grep -B 3 fopen TMPDIR /var/tmp/ GmXXXXXX fopen (temporary file) ``` Given that Homebrew filtered `TMPDIR`, and the `/var/tmp` directory may not be writable for non-root users, this would cause Homebrew’s build environment to error out: ``` $ brew ruby -e 'puts ENV["TMPDIR"]; puts `: | make -f -`' ``` ``` Ignoring bigdecimal-2.0.0 because its extensions are not built. Try: gem pristine bigdecimal --version 2.0.0 […] Ignoring zlib-1.1.0 because its extensions are not built. Try: gem pristine zlib --version 1.1.0 make: *** fopen (temporary file): Permission denied. Stop. ``` In practice, this would break `brew audit`, `brew style`, and other commands, which would run `make` to build native gem extensions. This commit sets `TMPDIR` to `${HOMEBREW_TEMP}` in the gem environment, which mirrors the behaviour we already have in other places. We choose `HOMEBREW_TEMP` because that’s user-controlled but also falls back to `/tmp` in case `TMPDIR` is not set in the user’s environment. Thanks to Bo Anderson for helping find the bug. CC: Bo Anderson <mail@boanderson.me>
This commit is contained in:
parent
b9fc765e56
commit
29538c89cd
@ -44,6 +44,10 @@ module Homebrew
|
||||
ENV["GEM_HOME"] = gem_home
|
||||
ENV["GEM_PATH"] = ENV["GEM_HOME"]
|
||||
|
||||
# Set TMPDIR so Xcode's `make` doesn't fall back to `/var/tmp/`,
|
||||
# which may be not user-writable.
|
||||
ENV["TMPDIR"] = ENV["HOMEBREW_TEMP"]
|
||||
|
||||
# Make RubyGems notice environment changes.
|
||||
require "rubygems"
|
||||
Gem.clear_paths
|
||||
|
Loading…
x
Reference in New Issue
Block a user