Skip to content
Snippets Groups Projects
Commit f8ad9d7e authored by Markus Reiter's avatar Markus Reiter
Browse files

Use `PATH` where possible.

parent 314483f7
No related branches found
No related tags found
No related merge requests found
......@@ -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)
......
......@@ -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"
......
......@@ -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?
......
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
......
......@@ -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")
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment