Skip to content

Commit f8ad9d7

Browse files
committed
Use PATH where possible.
1 parent 314483f commit f8ad9d7

File tree

8 files changed

+23
-20
lines changed

8 files changed

+23
-20
lines changed

Library/Homebrew/brew.rb

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
1313
$:.unshift(HOMEBREW_LIBRARY_PATH.to_s)
1414
require "global"
15+
require "tap"
1516

1617
if ARGV == %w[--version] || ARGV == %w[-v]
17-
require "tap"
1818
puts "Homebrew #{HOMEBREW_VERSION}"
1919
puts "Homebrew/homebrew-core #{CoreTap.instance.version_string}"
2020
exit 0
@@ -47,13 +47,15 @@ def require?(path)
4747
end
4848
end
4949

50+
path = PATH.new(ENV["PATH"])
51+
5052
# Add contributed commands to PATH before checking.
51-
Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/cmd"].each do |tap_cmd_dir|
52-
ENV["PATH"] += "#{File::PATH_SEPARATOR}#{tap_cmd_dir}"
53-
end
53+
path.append(Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd"))
5454

5555
# Add SCM wrappers.
56-
ENV["PATH"] += "#{File::PATH_SEPARATOR}#{HOMEBREW_SHIMS_PATH}/scm"
56+
path.append(HOMEBREW_SHIMS_PATH/"scm")
57+
58+
ENV["PATH"] = path
5759

5860
if cmd
5961
internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd)

Library/Homebrew/cmd/sh.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def sh
2323
ENV.setup_build_environment
2424
if superenv?
2525
# superenv stopped adding brew's bin but generally users will want it
26-
ENV["PATH"] = ENV["PATH"].split(File::PATH_SEPARATOR).insert(1, "#{HOMEBREW_PREFIX}/bin").join(File::PATH_SEPARATOR)
26+
ENV["PATH"] = PATH.new(PATH.new(ENV["PATH"]).to_a.insert(1, HOMEBREW_PREFIX/"bin"))
2727
end
2828
ENV["PS1"] = 'brew \[\033[1;32m\]\w\[\033[0m\]$ '
2929
ENV["VERBOSE"] = "1"

Library/Homebrew/diagnostic.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def check_for_installed_developer_tools
100100

101101
# See https://github.com/Homebrew/legacy-homebrew/pull/9986
102102
def check_path_for_trailing_slashes
103-
all_paths = ENV["PATH"].split(File::PATH_SEPARATOR)
103+
all_paths = PATH.new(ENV["PATH"]).to_a
104104
bad_paths = all_paths.select { |p| p[-1..-1] == "/" }
105105
return if bad_paths.empty?
106106

Library/Homebrew/extend/ENV/shared.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "formula"
22
require "compilers"
33
require "development_tools"
4+
require "PATH"
45

56
# Homebrew extends Ruby's `ENV` to make our code more readable.
67
# Implemented in {SharedEnvExtension} and either {Superenv} or
@@ -80,7 +81,7 @@ def prepend(keys, value, separator = " ")
8081
end
8182

8283
def append_path(key, path)
83-
append key, path, File::PATH_SEPARATOR if File.directory? path
84+
self[key] = PATH.new(self[key]).append(path)
8485
end
8586

8687
# Prepends a directory to `PATH`.
@@ -92,7 +93,7 @@ def append_path(key, path)
9293
# (e.g. <pre>ENV.prepend_path "PATH", which("emacs").dirname</pre>)
9394
def prepend_path(key, path)
9495
return if %w[/usr/bin /bin /usr/sbin /sbin].include? path.to_s
95-
prepend key, path, File::PATH_SEPARATOR if File.directory? path
96+
self[key] = PATH.new(self[key]).prepend(path)
9697
end
9798

9899
def prepend_create_path(key, path)
@@ -196,7 +197,7 @@ def ncurses_define
196197

197198
# @private
198199
def userpaths!
199-
paths = self["PATH"].split(File::PATH_SEPARATOR)
200+
paths = PATH.new(self["PATH"]).to_a
200201
# put Superenv.bin and opt path at the first
201202
new_paths = paths.select { |p| p.start_with?("#{HOMEBREW_REPOSITORY}/Library/ENV", "#{HOMEBREW_PREFIX}/opt") }
202203
# XXX hot fix to prefer brewed stuff (e.g. python) over /usr/bin.
@@ -211,7 +212,7 @@ def userpaths!
211212
nil
212213
end
213214
end - %w[/usr/X11/bin /opt/X11/bin]
214-
self["PATH"] = new_paths.uniq.join(File::PATH_SEPARATOR)
215+
self["PATH"] = PATH.new(new_paths.uniq)
215216
end
216217

217218
def fortran
@@ -244,7 +245,7 @@ def fortran
244245
else
245246
if (gfortran = which("gfortran", (HOMEBREW_PREFIX/"bin").to_s))
246247
ohai "Using Homebrew-provided fortran compiler."
247-
elsif (gfortran = which("gfortran", ORIGINAL_PATHS.join(File::PATH_SEPARATOR)))
248+
elsif (gfortran = which("gfortran", PATH.new(ORIGINAL_PATHS)))
248249
ohai "Using a fortran compiler found at #{gfortran}."
249250
end
250251
if gfortran

Library/Homebrew/extend/ENV/super.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def determine_path
104104
path = PATH.new(Superenv.bin)
105105

106106
# Formula dependencies can override standard tools.
107-
path.append(deps.map { |d| d.opt_bin.to_s })
107+
path.append(deps.map(&:opt_bin))
108108
path.append(homebrew_extra_paths)
109109
path.append("/usr/bin", "/bin", "/usr/sbin", "/sbin")
110110

Library/Homebrew/global.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def raise_deprecation_exceptions?
5656
require "compat" unless ARGV.include?("--no-compat") || ENV["HOMEBREW_NO_COMPAT"]
5757

5858
ENV["HOMEBREW_PATH"] ||= ENV["PATH"]
59-
ORIGINAL_PATHS = ENV["HOMEBREW_PATH"].split(File::PATH_SEPARATOR).map do |p|
59+
ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).to_a.map do |p|
6060
begin
6161
Pathname.new(p).expand_path
6262
rescue

Library/Homebrew/requirement.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def modify_build_environment
9696
# PATH.
9797
parent = satisfied_result_parent
9898
return unless parent
99-
return if ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s)
99+
return if PATH.new(ENV["PATH"]).to_a.include?(parent.to_s)
100100
ENV.append_path("PATH", parent)
101101
end
102102

@@ -151,11 +151,11 @@ def infer_name
151151
end
152152

153153
def which(cmd)
154-
super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR))
154+
super(cmd, PATH.new(ORIGINAL_PATHS))
155155
end
156156

157157
def which_all(cmd)
158-
super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR))
158+
super(cmd, PATH.new(ORIGINAL_PATHS))
159159
end
160160

161161
class << self

Library/Homebrew/utils.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ def quiet_system(cmd, *args)
293293
end
294294

295295
def which(cmd, path = ENV["PATH"])
296-
path.split(File::PATH_SEPARATOR).each do |p|
296+
PATH.new(path).to_a.each do |p|
297297
begin
298298
pcmd = File.expand_path(cmd, p)
299299
rescue ArgumentError
@@ -307,7 +307,7 @@ def which(cmd, path = ENV["PATH"])
307307
end
308308

309309
def which_all(cmd, path = ENV["PATH"])
310-
path.to_s.split(File::PATH_SEPARATOR).map do |p|
310+
PATH.new(path).to_a.map do |p|
311311
begin
312312
pcmd = File.expand_path(cmd, p)
313313
rescue ArgumentError
@@ -416,7 +416,7 @@ def nostdout
416416
end
417417

418418
def paths(env_path = ENV["PATH"])
419-
@paths ||= env_path.split(File::PATH_SEPARATOR).collect do |p|
419+
@paths ||= PATH.new(env_path).to_a.collect do |p|
420420
begin
421421
File.expand_path(p).chomp("/")
422422
rescue ArgumentError

0 commit comments

Comments
 (0)