From 29538c89cd767f767f1d12b160801c5fd5002cfe Mon Sep 17 00:00:00 2001 From: Claudia Date: Sun, 5 Apr 2020 15:30:50 +0200 Subject: [PATCH] =?UTF-8?q?Set=20TMPDIR=20for=20Xcode=E2=80=99s=20`make`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Library/Homebrew/utils/gems.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Library/Homebrew/utils/gems.rb b/Library/Homebrew/utils/gems.rb index b8ef90c237..5125dd5c9f 100644 --- a/Library/Homebrew/utils/gems.rb +++ b/Library/Homebrew/utils/gems.rb @@ -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