Skip to content

Commit

Permalink
Merge pull request #4415 from MikeMcQuaid/tmp-cleanup
Browse files Browse the repository at this point in the history
Cleanup HOMEBREW_TEMP handling
  • Loading branch information
MikeMcQuaid authored Jul 3, 2018
2 parents 517bf7e + f46e459 commit 0dcf753
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 36 deletions.
9 changes: 5 additions & 4 deletions Library/Homebrew/brew.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion Library/Homebrew/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
65 changes: 34 additions & 31 deletions Library/Homebrew/dev-cmd/update-test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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..."
Expand Down Expand Up @@ -107,5 +108,7 @@ def update_test
EOS
end
end
ensure
FileUtils.rm_r "update-test" unless args.keep_tmp?
end
end
5 changes: 5 additions & 0 deletions Library/Homebrew/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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_")
Expand Down

0 comments on commit 0dcf753

Please sign in to comment.