aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMarkus Reiter2017-04-27 10:44:44 +0200
committerMarkus Reiter2017-04-30 21:11:27 +0200
commitf8ad9d7efd5f3f489ed3c1671f16eb2a2eaef822 (patch)
treeb49a1211a472e686fed66010e2ddd38ca92cd2a9 /Library
parent314483f75c8893eb68073f5863e7784797d6ea2a (diff)
downloadbrew-f8ad9d7efd5f3f489ed3c1671f16eb2a2eaef822.tar.bz2
Use `PATH` where possible.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/brew.rb12
-rw-r--r--Library/Homebrew/cmd/sh.rb2
-rw-r--r--Library/Homebrew/diagnostic.rb2
-rw-r--r--Library/Homebrew/extend/ENV/shared.rb11
-rw-r--r--Library/Homebrew/extend/ENV/super.rb2
-rw-r--r--Library/Homebrew/global.rb2
-rw-r--r--Library/Homebrew/requirement.rb6
-rw-r--r--Library/Homebrew/utils.rb6
8 files changed, 23 insertions, 20 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb
index 62cfd79c3..f2e723114 100644
--- a/Library/Homebrew/brew.rb
+++ b/Library/Homebrew/brew.rb
@@ -12,9 +12,9 @@ require "pathname"
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
$:.unshift(HOMEBREW_LIBRARY_PATH.to_s)
require "global"
+require "tap"
if ARGV == %w[--version] || ARGV == %w[-v]
- require "tap"
puts "Homebrew #{HOMEBREW_VERSION}"
puts "Homebrew/homebrew-core #{CoreTap.instance.version_string}"
exit 0
@@ -47,13 +47,15 @@ begin
end
end
+ path = PATH.new(ENV["PATH"])
+
# Add contributed commands to PATH before checking.
- Dir["#{HOMEBREW_LIBRARY}/Taps/*/*/cmd"].each do |tap_cmd_dir|
- ENV["PATH"] += "#{File::PATH_SEPARATOR}#{tap_cmd_dir}"
- end
+ path.append(Pathname.glob(Tap::TAP_DIRECTORY/"*/*/cmd"))
# Add SCM wrappers.
- ENV["PATH"] += "#{File::PATH_SEPARATOR}#{HOMEBREW_SHIMS_PATH}/scm"
+ path.append(HOMEBREW_SHIMS_PATH/"scm")
+
+ ENV["PATH"] = path
if cmd
internal_cmd = require? HOMEBREW_LIBRARY_PATH.join("cmd", cmd)
diff --git a/Library/Homebrew/cmd/sh.rb b/Library/Homebrew/cmd/sh.rb
index 249753355..1e86784cb 100644
--- a/Library/Homebrew/cmd/sh.rb
+++ b/Library/Homebrew/cmd/sh.rb
@@ -23,7 +23,7 @@ module Homebrew
ENV.setup_build_environment
if superenv?
# superenv stopped adding brew's bin but generally users will want it
- ENV["PATH"] = ENV["PATH"].split(File::PATH_SEPARATOR).insert(1, "#{HOMEBREW_PREFIX}/bin").join(File::PATH_SEPARATOR)
+ ENV["PATH"] = PATH.new(PATH.new(ENV["PATH"]).to_a.insert(1, HOMEBREW_PREFIX/"bin"))
end
ENV["PS1"] = 'brew \[\033[1;32m\]\w\[\033[0m\]$ '
ENV["VERBOSE"] = "1"
diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb
index 8cca1ba91..7657af193 100644
--- a/Library/Homebrew/diagnostic.rb
+++ b/Library/Homebrew/diagnostic.rb
@@ -100,7 +100,7 @@ module Homebrew
# See https://github.com/Homebrew/legacy-homebrew/pull/9986
def check_path_for_trailing_slashes
- all_paths = ENV["PATH"].split(File::PATH_SEPARATOR)
+ all_paths = PATH.new(ENV["PATH"]).to_a
bad_paths = all_paths.select { |p| p[-1..-1] == "/" }
return if bad_paths.empty?
diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb
index 2cdc2f83a..6fa9b7778 100644
--- a/Library/Homebrew/extend/ENV/shared.rb
+++ b/Library/Homebrew/extend/ENV/shared.rb
@@ -1,6 +1,7 @@
require "formula"
require "compilers"
require "development_tools"
+require "PATH"
# Homebrew extends Ruby's `ENV` to make our code more readable.
# Implemented in {SharedEnvExtension} and either {Superenv} or
@@ -80,7 +81,7 @@ module SharedEnvExtension
end
def append_path(key, path)
- append key, path, File::PATH_SEPARATOR if File.directory? path
+ self[key] = PATH.new(self[key]).append(path)
end
# Prepends a directory to `PATH`.
@@ -92,7 +93,7 @@ module SharedEnvExtension
# (e.g. <pre>ENV.prepend_path "PATH", which("emacs").dirname</pre>)
def prepend_path(key, path)
return if %w[/usr/bin /bin /usr/sbin /sbin].include? path.to_s
- prepend key, path, File::PATH_SEPARATOR if File.directory? path
+ self[key] = PATH.new(self[key]).prepend(path)
end
def prepend_create_path(key, path)
@@ -196,7 +197,7 @@ module SharedEnvExtension
# @private
def userpaths!
- paths = self["PATH"].split(File::PATH_SEPARATOR)
+ paths = PATH.new(self["PATH"]).to_a
# put Superenv.bin and opt path at the first
new_paths = paths.select { |p| p.start_with?("#{HOMEBREW_REPOSITORY}/Library/ENV", "#{HOMEBREW_PREFIX}/opt") }
# XXX hot fix to prefer brewed stuff (e.g. python) over /usr/bin.
@@ -211,7 +212,7 @@ module SharedEnvExtension
nil
end
end - %w[/usr/X11/bin /opt/X11/bin]
- self["PATH"] = new_paths.uniq.join(File::PATH_SEPARATOR)
+ self["PATH"] = PATH.new(new_paths.uniq)
end
def fortran
@@ -244,7 +245,7 @@ module SharedEnvExtension
else
if (gfortran = which("gfortran", (HOMEBREW_PREFIX/"bin").to_s))
ohai "Using Homebrew-provided fortran compiler."
- elsif (gfortran = which("gfortran", ORIGINAL_PATHS.join(File::PATH_SEPARATOR)))
+ elsif (gfortran = which("gfortran", PATH.new(ORIGINAL_PATHS)))
ohai "Using a fortran compiler found at #{gfortran}."
end
if gfortran
diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb
index 90215da28..ac60e13cd 100644
--- a/Library/Homebrew/extend/ENV/super.rb
+++ b/Library/Homebrew/extend/ENV/super.rb
@@ -104,7 +104,7 @@ module Superenv
path = PATH.new(Superenv.bin)
# Formula dependencies can override standard tools.
- path.append(deps.map { |d| d.opt_bin.to_s })
+ path.append(deps.map(&:opt_bin))
path.append(homebrew_extra_paths)
path.append("/usr/bin", "/bin", "/usr/sbin", "/sbin")
diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb
index b0bf647a1..c73d66c58 100644
--- a/Library/Homebrew/global.rb
+++ b/Library/Homebrew/global.rb
@@ -56,7 +56,7 @@ HOMEBREW_PULL_OR_COMMIT_URL_REGEX = %r[https://github\.com/([\w-]+)/([\w-]+)?/(?
require "compat" unless ARGV.include?("--no-compat") || ENV["HOMEBREW_NO_COMPAT"]
ENV["HOMEBREW_PATH"] ||= ENV["PATH"]
-ORIGINAL_PATHS = ENV["HOMEBREW_PATH"].split(File::PATH_SEPARATOR).map do |p|
+ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).to_a.map do |p|
begin
Pathname.new(p).expand_path
rescue
diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb
index a4bdabdd1..6146382a3 100644
--- a/Library/Homebrew/requirement.rb
+++ b/Library/Homebrew/requirement.rb
@@ -96,7 +96,7 @@ class Requirement
# PATH.
parent = satisfied_result_parent
return unless parent
- return if ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s)
+ return if PATH.new(ENV["PATH"]).to_a.include?(parent.to_s)
ENV.append_path("PATH", parent)
end
@@ -151,11 +151,11 @@ class Requirement
end
def which(cmd)
- super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR))
+ super(cmd, PATH.new(ORIGINAL_PATHS))
end
def which_all(cmd)
- super(cmd, ORIGINAL_PATHS.join(File::PATH_SEPARATOR))
+ super(cmd, PATH.new(ORIGINAL_PATHS))
end
class << self
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb
index 2ac195cdb..98a6ce6da 100644
--- a/Library/Homebrew/utils.rb
+++ b/Library/Homebrew/utils.rb
@@ -293,7 +293,7 @@ def quiet_system(cmd, *args)
end
def which(cmd, path = ENV["PATH"])
- path.split(File::PATH_SEPARATOR).each do |p|
+ PATH.new(path).to_a.each do |p|
begin
pcmd = File.expand_path(cmd, p)
rescue ArgumentError
@@ -307,7 +307,7 @@ def which(cmd, path = ENV["PATH"])
end
def which_all(cmd, path = ENV["PATH"])
- path.to_s.split(File::PATH_SEPARATOR).map do |p|
+ PATH.new(path).to_a.map do |p|
begin
pcmd = File.expand_path(cmd, p)
rescue ArgumentError
@@ -416,7 +416,7 @@ def nostdout
end
def paths(env_path = ENV["PATH"])
- @paths ||= env_path.split(File::PATH_SEPARATOR).collect do |p|
+ @paths ||= PATH.new(env_path).to_a.collect do |p|
begin
File.expand_path(p).chomp("/")
rescue ArgumentError