From f46e4596c031309cc10807b87faa3a765bd36366 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 3 Jul 2018 15:41:33 +0100 Subject: [PATCH] Cleanup HOMEBREW_TEMP handling - Ensure that `HOMEBREW_TEMP` is only displayed in `brew config` when it's non-default. - Attempt to create a missing `HOMEBREW_TEMP` directory rather than failing to `realpath`. Note this will still fail on permissions errors which is to be expected. --- Library/Homebrew/brew.sh | 9 ++-- Library/Homebrew/config.rb | 6 ++- Library/Homebrew/dev-cmd/update-test.rb | 65 +++++++++++++------------ Library/Homebrew/system_config.rb | 5 ++ 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/Library/Homebrew/brew.sh b/Library/Homebrew/brew.sh index 727119d9bdbd7..d60da9db99497 100644 --- a/Library/Homebrew/brew.sh +++ b/Library/Homebrew/brew.sh @@ -105,8 +105,7 @@ then fi HOMEBREW_CACHE="${HOMEBREW_CACHE:-${HOME}/Library/Caches/Homebrew}" - - HOMEBREW_TEMP="${HOMEBREW_TEMP:-/private/tmp}" + HOMEBREW_SYSTEM_TEMP="/private/tmp" else HOMEBREW_PROCESSOR="$(uname -m)" HOMEBREW_PRODUCT="${HOMEBREW_SYSTEM}brew" @@ -116,10 +115,11 @@ else CACHE_HOME="${XDG_CACHE_HOME:-${HOME}/.cache}" HOMEBREW_CACHE="${HOMEBREW_CACHE:-${CACHE_HOME}/Homebrew}" - - HOMEBREW_TEMP="${HOMEBREW_TEMP:-/tmp}" + HOMEBREW_SYSTEM_TEMP="/tmp" fi +HOMEBREW_TEMP="${HOMEBREW_TEMP:-${HOMEBREW_SYSTEM_TEMP}}" + if [[ -n "$HOMEBREW_FORCE_BREWED_CURL" && -x "$HOMEBREW_PREFIX/opt/curl/bin/curl" ]] && "$HOMEBREW_PREFIX/opt/curl/bin/curl" --version >/dev/null @@ -147,6 +147,7 @@ export HOMEBREW_BREW_FILE export HOMEBREW_PREFIX export HOMEBREW_REPOSITORY export HOMEBREW_LIBRARY +export HOMEBREW_SYSTEM_TEMP export HOMEBREW_TEMP # Declared in brew.sh diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index 6247060fb6110..64f83e0c1534a 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -39,7 +39,11 @@ HOMEBREW_LOGS = Pathname.new(ENV["HOMEBREW_LOGS"] || "~/Library/Logs/Homebrew/").expand_path # Must use /tmp instead of $TMPDIR because long paths break Unix domain sockets -HOMEBREW_TEMP = Pathname.new(ENV["HOMEBREW_TEMP"]).realpath +HOMEBREW_TEMP = begin + tmp = Pathname.new(ENV["HOMEBREW_TEMP"]) + tmp.mkpath unless tmp.exist? + tmp.realpath +end unless defined? HOMEBREW_LIBRARY_PATH # Root of the Homebrew code base diff --git a/Library/Homebrew/dev-cmd/update-test.rb b/Library/Homebrew/dev-cmd/update-test.rb index 685fa3abdd4d7..072abdcca3dce 100644 --- a/Library/Homebrew/dev-cmd/update-test.rb +++ b/Library/Homebrew/dev-cmd/update-test.rb @@ -31,49 +31,50 @@ def update_test ENV["HOMEBREW_UPDATE_TEST"] = "1" - if args.to_tag? + branch = if args.to_tag? ENV["HOMEBREW_UPDATE_TO_TAG"] = "1" - branch = "stable" + "stable" else - branch = "master" + "master" end - cd HOMEBREW_REPOSITORY - start_commit = if commit = args.commit - commit - elsif date = args.before - Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp - elsif args.to_tag? - tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") - previous_tag = tags.lines[1] - previous_tag ||= begin - if (HOMEBREW_REPOSITORY/".git/shallow").exist? - safe_system "git", "fetch", "--tags", "--depth=1" - tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") - elsif OS.linux? - tags = Utils.popen_read("git tag --list | sort -rV") + start_commit, end_commit = nil + cd HOMEBREW_REPOSITORY do + start_commit = if commit = args.commit + commit + elsif date = args.before + Utils.popen_read("git", "rev-list", "-n1", "--before=#{date}", "origin/master").chomp + elsif args.to_tag? + tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") + previous_tag = tags.lines[1] + previous_tag ||= begin + if (HOMEBREW_REPOSITORY/".git/shallow").exist? + safe_system "git", "fetch", "--tags", "--depth=1" + tags = Utils.popen_read("git", "tag", "--list", "--sort=-version:refname") + elsif OS.linux? + tags = Utils.popen_read("git tag --list | sort -rV") + end + tags.lines[1] end - tags.lines[1] + previous_tag = previous_tag.to_s.chomp + odie "Could not find previous tag in:\n#{tags}" if previous_tag.empty? + previous_tag + else + Utils.popen_read("git", "rev-parse", "origin/master").chomp end - previous_tag = previous_tag.to_s.chomp - odie "Could not find previous tag in:\n#{tags}" if previous_tag.empty? - previous_tag - else - Utils.popen_read("git", "rev-parse", "origin/master").chomp - end - odie "Could not find start commit!" if start_commit.empty? + odie "Could not find start commit!" if start_commit.empty? - start_commit = Utils.popen_read("git", "rev-parse", start_commit).chomp - odie "Could not find start commit!" if start_commit.empty? + start_commit = Utils.popen_read("git", "rev-parse", start_commit).chomp + odie "Could not find start commit!" if start_commit.empty? - end_commit = Utils.popen_read("git", "rev-parse", "HEAD").chomp - odie "Could not find end commit!" if end_commit.empty? + end_commit = Utils.popen_read("git", "rev-parse", "HEAD").chomp + odie "Could not find end commit!" if end_commit.empty? + end puts "Start commit: #{start_commit}" puts "End commit: #{end_commit}" - mktemp("update-test") do |staging| - staging.retain! if args.keep_tmp? + mkdir "update-test" do curdir = Pathname.new(Dir.pwd) oh1 "Setup test environment..." @@ -107,5 +108,7 @@ def update_test EOS end end + ensure + FileUtils.rm_r "update-test" unless args.keep_tmp? end end diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index 512ca16d54085..0f7c56b1be27c 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -116,6 +116,7 @@ def dump_verbose_config(f = $stdout) HOMEBREW_CELLAR: "/usr/local/Cellar", HOMEBREW_CACHE: "#{ENV["HOME"]}/Library/Caches/Homebrew", HOMEBREW_RUBY_WARNINGS: "-W0", + HOMEBREW_TEMP: ENV["HOMEBREW_SYSTEM_TEMP"], }.freeze boring_keys = %w[ HOMEBREW_BROWSER @@ -134,6 +135,7 @@ def dump_verbose_config(f = $stdout) HOMEBREW_MACOS_VERSION HOMEBREW_RUBY_PATH HOMEBREW_SYSTEM + HOMEBREW_SYSTEM_TEMP HOMEBREW_OS_VERSION HOMEBREW_PATH HOMEBREW_PROCESSOR @@ -155,6 +157,9 @@ def dump_verbose_config(f = $stdout) if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}" end + if defaults_hash[:HOMEBREW_TEMP] != HOMEBREW_TEMP.to_s + f.puts "HOMEBREW_TEMP: #{HOMEBREW_TEMP}" + end unless ENV["HOMEBREW_ENV"] ENV.sort.each do |key, value| next unless key.start_with?("HOMEBREW_")