Use ORIGINAL_PATHS over envs; reject nil PATH
This commit is contained in:
parent
8ada737d40
commit
02164a35db
@ -53,8 +53,8 @@ begin
|
|||||||
args = Homebrew::CLI::Parser.new.parse(ARGV.dup.freeze, ignore_invalid_options: true)
|
args = Homebrew::CLI::Parser.new.parse(ARGV.dup.freeze, ignore_invalid_options: true)
|
||||||
Context.current = args.context
|
Context.current = args.context
|
||||||
|
|
||||||
path = PATH.new(ENV["PATH"])
|
path = PATH.new(ENV.fetch("PATH"))
|
||||||
homebrew_path = PATH.new(ENV["HOMEBREW_PATH"])
|
homebrew_path = PATH.new(ENV.fetch("HOMEBREW_PATH"))
|
||||||
|
|
||||||
# Add shared wrappers.
|
# Add shared wrappers.
|
||||||
path.prepend(HOMEBREW_SHIMS_PATH/"shared")
|
path.prepend(HOMEBREW_SHIMS_PATH/"shared")
|
||||||
|
|||||||
@ -39,7 +39,7 @@ module Cask
|
|||||||
executable_path,
|
executable_path,
|
||||||
**args,
|
**args,
|
||||||
env: { "PATH" => PATH.new(
|
env: { "PATH" => PATH.new(
|
||||||
HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV["PATH"]
|
HOMEBREW_PREFIX/"bin", HOMEBREW_PREFIX/"sbin", ENV.fetch("PATH")
|
||||||
) },
|
) },
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -78,7 +78,7 @@ class Caveats
|
|||||||
|
|
||||||
s << " #{Utils::Shell.export_value("CPPFLAGS", "-I#{f.opt_include}")}\n" if f.include.directory?
|
s << " #{Utils::Shell.export_value("CPPFLAGS", "-I#{f.opt_include}")}\n" if f.include.directory?
|
||||||
|
|
||||||
if which("pkg-config", ENV["HOMEBREW_PATH"]) &&
|
if which("pkg-config", ORIGINAL_PATHS) &&
|
||||||
((f.lib/"pkgconfig").directory? || (f.share/"pkgconfig").directory?)
|
((f.lib/"pkgconfig").directory? || (f.share/"pkgconfig").directory?)
|
||||||
s << <<~EOS
|
s << <<~EOS
|
||||||
|
|
||||||
@ -109,7 +109,7 @@ class Caveats
|
|||||||
|
|
||||||
def function_completion_caveats(shell)
|
def function_completion_caveats(shell)
|
||||||
return unless keg
|
return unless keg
|
||||||
return unless which(shell.to_s, ENV["HOMEBREW_PATH"])
|
return unless which(shell.to_s, ORIGINAL_PATHS)
|
||||||
|
|
||||||
completion_installed = keg.completion_installed?(shell)
|
completion_installed = keg.completion_installed?(shell)
|
||||||
functions_installed = keg.functions_installed?(shell)
|
functions_installed = keg.functions_installed?(shell)
|
||||||
|
|||||||
@ -391,7 +391,7 @@ module Homebrew
|
|||||||
end
|
end
|
||||||
|
|
||||||
def cleanup_portable_ruby
|
def cleanup_portable_ruby
|
||||||
rubies = [which("ruby"), which("ruby", ENV["HOMEBREW_PATH"])].compact
|
rubies = [which("ruby"), which("ruby", ORIGINAL_PATHS)].compact
|
||||||
system_ruby = Pathname.new("/usr/bin/ruby")
|
system_ruby = Pathname.new("/usr/bin/ruby")
|
||||||
rubies << system_ruby if system_ruby.exist?
|
rubies << system_ruby if system_ruby.exist?
|
||||||
|
|
||||||
|
|||||||
@ -42,7 +42,7 @@ module Homebrew
|
|||||||
|
|
||||||
# As this command is simplifying user-run commands then let's just use a
|
# As this command is simplifying user-run commands then let's just use a
|
||||||
# user path, too.
|
# user path, too.
|
||||||
ENV["PATH"] = ENV["HOMEBREW_PATH"]
|
ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s
|
||||||
|
|
||||||
if args.no_named?
|
if args.no_named?
|
||||||
git_log HOMEBREW_REPOSITORY, args: args
|
git_log HOMEBREW_REPOSITORY, args: args
|
||||||
|
|||||||
@ -93,11 +93,11 @@ module Commands
|
|||||||
|
|
||||||
# Ruby commands which are run by being `require`d.
|
# Ruby commands which are run by being `require`d.
|
||||||
def external_ruby_cmd_path(cmd)
|
def external_ruby_cmd_path(cmd)
|
||||||
which("brew-#{cmd}.rb", PATH.new(ENV["PATH"]).append(Tap.cmd_directories))
|
which("brew-#{cmd}.rb", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories))
|
||||||
end
|
end
|
||||||
|
|
||||||
def external_cmd_path(cmd)
|
def external_cmd_path(cmd)
|
||||||
which("brew-#{cmd}", PATH.new(ENV["PATH"]).append(Tap.cmd_directories))
|
which("brew-#{cmd}", PATH.new(ENV.fetch("PATH")).append(Tap.cmd_directories))
|
||||||
end
|
end
|
||||||
|
|
||||||
def path(cmd)
|
def path(cmd)
|
||||||
|
|||||||
@ -67,7 +67,7 @@ module Homebrew
|
|||||||
|
|
||||||
# As this command is simplifying user-run commands then let's just use a
|
# As this command is simplifying user-run commands then let's just use a
|
||||||
# user path, too.
|
# user path, too.
|
||||||
ENV["PATH"] = ENV["HOMEBREW_PATH"]
|
ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s
|
||||||
|
|
||||||
# Use the user's browser, too.
|
# Use the user's browser, too.
|
||||||
ENV["BROWSER"] = Homebrew::EnvConfig.browser
|
ENV["BROWSER"] = Homebrew::EnvConfig.browser
|
||||||
|
|||||||
@ -108,7 +108,7 @@ module Homebrew
|
|||||||
|
|
||||||
# As this command is simplifying user-run commands then let's just use a
|
# As this command is simplifying user-run commands then let's just use a
|
||||||
# user path, too.
|
# user path, too.
|
||||||
ENV["PATH"] = ENV["HOMEBREW_PATH"]
|
ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s
|
||||||
|
|
||||||
# Use the user's browser, too.
|
# Use the user's browser, too.
|
||||||
ENV["BROWSER"] = Homebrew::EnvConfig.browser
|
ENV["BROWSER"] = Homebrew::EnvConfig.browser
|
||||||
|
|||||||
@ -36,7 +36,7 @@ module Homebrew
|
|||||||
|
|
||||||
# As this command is simplifying user-run commands then let's just use a
|
# As this command is simplifying user-run commands then let's just use a
|
||||||
# user path, too.
|
# user path, too.
|
||||||
ENV["PATH"] = ENV["HOMEBREW_PATH"]
|
ENV["PATH"] = PATH.new(ORIGINAL_PATHS).to_s
|
||||||
|
|
||||||
args.named.to_formulae.each do |formula|
|
args.named.to_formulae.each do |formula|
|
||||||
current_revision = formula.revision
|
current_revision = formula.revision
|
||||||
|
|||||||
@ -38,7 +38,7 @@ module Homebrew
|
|||||||
ENV.setup_build_environment
|
ENV.setup_build_environment
|
||||||
if superenv?(args.env)
|
if superenv?(args.env)
|
||||||
# superenv stopped adding brew's bin but generally users will want it
|
# superenv stopped adding brew's bin but generally users will want it
|
||||||
ENV["PATH"] = PATH.new(ENV["PATH"]).insert(1, HOMEBREW_PREFIX/"bin")
|
ENV["PATH"] = PATH.new(ENV.fetch("PATH")).insert(1, HOMEBREW_PREFIX/"bin")
|
||||||
end
|
end
|
||||||
|
|
||||||
ENV["VERBOSE"] = "1" if args.verbose?
|
ENV["VERBOSE"] = "1" if args.verbose?
|
||||||
|
|||||||
@ -123,7 +123,7 @@ module Homebrew
|
|||||||
safe_system "git", "reset", "--hard", start_commit
|
safe_system "git", "reset", "--hard", start_commit
|
||||||
|
|
||||||
# update ENV["PATH"]
|
# update ENV["PATH"]
|
||||||
ENV["PATH"] = PATH.new(ENV["PATH"]).prepend(curdir/"bin")
|
ENV["PATH"] = PATH.new(ENV.fetch("PATH")).prepend(curdir/"bin")
|
||||||
|
|
||||||
# run brew help to install portable-ruby (if needed)
|
# run brew help to install portable-ruby (if needed)
|
||||||
quiet_system "brew", "help"
|
quiet_system "brew", "help"
|
||||||
|
|||||||
@ -1139,7 +1139,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy
|
|||||||
private
|
private
|
||||||
|
|
||||||
def env
|
def env
|
||||||
{ "PATH" => PATH.new("/usr/bin", Formula["cvs"].opt_bin, ENV["PATH"]) }
|
{ "PATH" => PATH.new("/usr/bin", Formula["cvs"].opt_bin, ENV.fetch("PATH")) }
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
@ -1214,7 +1214,7 @@ class MercurialDownloadStrategy < VCSDownloadStrategy
|
|||||||
private
|
private
|
||||||
|
|
||||||
def env
|
def env
|
||||||
{ "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]) }
|
{ "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV.fetch("PATH")) }
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
@ -1280,7 +1280,7 @@ class BazaarDownloadStrategy < VCSDownloadStrategy
|
|||||||
|
|
||||||
def env
|
def env
|
||||||
{
|
{
|
||||||
"PATH" => PATH.new(Formula["bazaar"].opt_bin, ENV["PATH"]),
|
"PATH" => PATH.new(Formula["bazaar"].opt_bin, ENV.fetch("PATH")),
|
||||||
"BZR_HOME" => HOMEBREW_TEMP,
|
"BZR_HOME" => HOMEBREW_TEMP,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
@ -1345,7 +1345,7 @@ class FossilDownloadStrategy < VCSDownloadStrategy
|
|||||||
private
|
private
|
||||||
|
|
||||||
def env
|
def env
|
||||||
{ "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV["PATH"]) }
|
{ "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV.fetch("PATH")) }
|
||||||
end
|
end
|
||||||
|
|
||||||
sig { returns(String) }
|
sig { returns(String) }
|
||||||
|
|||||||
@ -28,7 +28,7 @@ module Stdenv
|
|||||||
|
|
||||||
self["HOMEBREW_ENV"] = "std"
|
self["HOMEBREW_ENV"] = "std"
|
||||||
|
|
||||||
PATH.new(ENV["HOMEBREW_PATH"]).reverse_each { |p| prepend_path "PATH", p }
|
ORIGINAL_PATHS.reverse_each { |p| prepend_path "PATH", p }
|
||||||
prepend_path "PATH", HOMEBREW_SHIMS_PATH/"shared"
|
prepend_path "PATH", HOMEBREW_SHIMS_PATH/"shared"
|
||||||
|
|
||||||
# Set the default pkg-config search path, overriding the built-in paths
|
# Set the default pkg-config search path, overriding the built-in paths
|
||||||
|
|||||||
@ -421,9 +421,9 @@ class Formula
|
|||||||
return unless head.downloader.cached_location.exist?
|
return unless head.downloader.cached_location.exist?
|
||||||
|
|
||||||
path = if ENV["HOMEBREW_ENV"]
|
path = if ENV["HOMEBREW_ENV"]
|
||||||
ENV["PATH"]
|
ENV.fetch("PATH")
|
||||||
else
|
else
|
||||||
ENV["HOMEBREW_PATH"]
|
PATH.new(ORIGINAL_PATHS)
|
||||||
end
|
end
|
||||||
|
|
||||||
with_env(PATH: path) do
|
with_env(PATH: path) do
|
||||||
@ -1103,7 +1103,7 @@ class Formula
|
|||||||
TMP: HOMEBREW_TEMP,
|
TMP: HOMEBREW_TEMP,
|
||||||
_JAVA_OPTIONS: "-Djava.io.tmpdir=#{HOMEBREW_TEMP}",
|
_JAVA_OPTIONS: "-Djava.io.tmpdir=#{HOMEBREW_TEMP}",
|
||||||
HOMEBREW_PATH: nil,
|
HOMEBREW_PATH: nil,
|
||||||
PATH: ENV["HOMEBREW_PATH"],
|
PATH: PATH.new(ORIGINAL_PATHS),
|
||||||
}
|
}
|
||||||
|
|
||||||
with_env(new_env) do
|
with_env(new_env) do
|
||||||
@ -2077,7 +2077,7 @@ class Formula
|
|||||||
TEMP: HOMEBREW_TEMP,
|
TEMP: HOMEBREW_TEMP,
|
||||||
TMP: HOMEBREW_TEMP,
|
TMP: HOMEBREW_TEMP,
|
||||||
TERM: "dumb",
|
TERM: "dumb",
|
||||||
PATH: PATH.new(ENV["PATH"], HOMEBREW_PREFIX/"bin"),
|
PATH: PATH.new(ENV.fetch("PATH"), HOMEBREW_PREFIX/"bin"),
|
||||||
HOMEBREW_PATH: nil,
|
HOMEBREW_PATH: nil,
|
||||||
}.merge(common_stage_test_env)
|
}.merge(common_stage_test_env)
|
||||||
test_env[:_JAVA_OPTIONS] += " -Djava.io.tmpdir=#{HOMEBREW_TEMP}"
|
test_env[:_JAVA_OPTIONS] += " -Djava.io.tmpdir=#{HOMEBREW_TEMP}"
|
||||||
|
|||||||
@ -299,7 +299,7 @@ module FormulaCellarChecks
|
|||||||
objdump = Formula["llvm"].opt_bin/"llvm-objdump" if Formula["llvm"].any_version_installed?
|
objdump = Formula["llvm"].opt_bin/"llvm-objdump" if Formula["llvm"].any_version_installed?
|
||||||
objdump ||= Formula["binutils"].opt_bin/"objdump" if Formula["binutils"].any_version_installed?
|
objdump ||= Formula["binutils"].opt_bin/"objdump" if Formula["binutils"].any_version_installed?
|
||||||
objdump ||= which("objdump")
|
objdump ||= which("objdump")
|
||||||
objdump ||= which("objdump", ENV["HOMEBREW_PATH"])
|
objdump ||= which("objdump", ORIGINAL_PATHS)
|
||||||
|
|
||||||
unless objdump
|
unless objdump
|
||||||
return <<~EOS
|
return <<~EOS
|
||||||
|
|||||||
@ -119,8 +119,8 @@ require "cli/args"
|
|||||||
|
|
||||||
require "PATH"
|
require "PATH"
|
||||||
|
|
||||||
ENV["HOMEBREW_PATH"] ||= ENV["PATH"]
|
ENV["HOMEBREW_PATH"] ||= ENV.fetch("PATH")
|
||||||
ORIGINAL_PATHS = PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
|
ORIGINAL_PATHS = PATH.new(ENV.fetch("HOMEBREW_PATH")).map do |p|
|
||||||
Pathname.new(p).expand_path
|
Pathname.new(p).expand_path
|
||||||
rescue
|
rescue
|
||||||
nil
|
nil
|
||||||
|
|||||||
@ -103,7 +103,7 @@ class Requirement
|
|||||||
parent = satisfied_result_parent
|
parent = satisfied_result_parent
|
||||||
return unless parent
|
return unless parent
|
||||||
return if ["#{HOMEBREW_PREFIX}/bin", "#{HOMEBREW_PREFIX}/bin"].include?(parent.to_s)
|
return if ["#{HOMEBREW_PREFIX}/bin", "#{HOMEBREW_PREFIX}/bin"].include?(parent.to_s)
|
||||||
return if PATH.new(ENV["PATH"]).include?(parent.to_s)
|
return if PATH.new(ENV.fetch("PATH")).include?(parent.to_s)
|
||||||
|
|
||||||
ENV.prepend_path("PATH", parent)
|
ENV.prepend_path("PATH", parent)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -34,7 +34,7 @@ describe Cask::Artifact::Installer, :cask do
|
|||||||
expect(command).to receive(:run!).with(
|
expect(command).to receive(:run!).with(
|
||||||
executable,
|
executable,
|
||||||
a_hash_including(
|
a_hash_including(
|
||||||
env: { "PATH" => PATH.new("#{HOMEBREW_PREFIX}/bin", "#{HOMEBREW_PREFIX}/sbin", ENV["PATH"]) },
|
env: { "PATH" => PATH.new("#{HOMEBREW_PREFIX}/bin", "#{HOMEBREW_PREFIX}/sbin", ENV.fetch("PATH")) },
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,7 @@ describe "brew custom-external-command", :integration_test do
|
|||||||
SH
|
SH
|
||||||
FileUtils.chmod "+x", file
|
FileUtils.chmod "+x", file
|
||||||
|
|
||||||
expect { brew cmd, "PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}" }
|
expect { brew cmd, "PATH" => "#{path}#{File::PATH_SEPARATOR}#{ENV.fetch("PATH")}" }
|
||||||
.to output("I am #{cmd}.\n").to_stdout
|
.to output("I am #{cmd}.\n").to_stdout
|
||||||
.and not_to_output.to_stderr
|
.and not_to_output.to_stderr
|
||||||
.and be_a_success
|
.and be_a_success
|
||||||
|
|||||||
@ -20,7 +20,7 @@ describe Homebrew::Diagnostic::Checks do
|
|||||||
FileUtils.chmod 0755, anaconda
|
FileUtils.chmod 0755, anaconda
|
||||||
FileUtils.chmod 0755, python
|
FileUtils.chmod 0755, python
|
||||||
|
|
||||||
ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
|
ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV.fetch("PATH")}"
|
||||||
|
|
||||||
expect(checks.check_for_anaconda).to match("Anaconda")
|
expect(checks.check_for_anaconda).to match("Anaconda")
|
||||||
end
|
end
|
||||||
@ -75,10 +75,12 @@ describe Homebrew::Diagnostic::Checks do
|
|||||||
|
|
||||||
specify "#check_user_path_3" do
|
specify "#check_user_path_3" do
|
||||||
sbin = HOMEBREW_PREFIX/"sbin"
|
sbin = HOMEBREW_PREFIX/"sbin"
|
||||||
ENV["HOMEBREW_PATH"] =
|
(sbin/"something").mkpath
|
||||||
|
|
||||||
|
homebrew_path =
|
||||||
"#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
|
"#{HOMEBREW_PREFIX}/bin#{File::PATH_SEPARATOR}" +
|
||||||
ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
|
ENV["HOMEBREW_PATH"].gsub(/(?:^|#{Regexp.escape(File::PATH_SEPARATOR)})#{Regexp.escape(sbin)}/, "")
|
||||||
(sbin/"something").mkpath
|
stub_const("ORIGINAL_PATHS", PATH.new(homebrew_path).map { |path| Pathname.new(path).expand_path }.compact)
|
||||||
|
|
||||||
expect(checks.check_user_path_1).to be_nil
|
expect(checks.check_user_path_1).to be_nil
|
||||||
expect(checks.check_user_path_2).to be_nil
|
expect(checks.check_user_path_2).to be_nil
|
||||||
@ -93,8 +95,7 @@ describe Homebrew::Diagnostic::Checks do
|
|||||||
file = "#{path}/foo-config"
|
file = "#{path}/foo-config"
|
||||||
FileUtils.touch file
|
FileUtils.touch file
|
||||||
FileUtils.chmod 0755, file
|
FileUtils.chmod 0755, file
|
||||||
ENV["HOMEBREW_PATH"] = ENV["PATH"] =
|
ENV["PATH"] = "#{path}#{File::PATH_SEPARATOR}#{ENV.fetch("PATH")}"
|
||||||
"#{path}#{File::PATH_SEPARATOR}#{ENV["PATH"]}"
|
|
||||||
|
|
||||||
expect(checks.check_for_config_scripts)
|
expect(checks.check_for_config_scripts)
|
||||||
.to match('"config" scripts exist')
|
.to match('"config" scripts exist')
|
||||||
|
|||||||
@ -150,7 +150,7 @@ RSpec.configure do |config|
|
|||||||
skip "Subversion is not installed." unless quiet_system svn_shim, "--version"
|
skip "Subversion is not installed." unless quiet_system svn_shim, "--version"
|
||||||
|
|
||||||
svn_shim_path = Pathname(Utils.popen_read(svn_shim, "--homebrew=print-path").chomp.presence)
|
svn_shim_path = Pathname(Utils.popen_read(svn_shim, "--homebrew=print-path").chomp.presence)
|
||||||
svn_paths = PATH.new(ENV["PATH"])
|
svn_paths = PATH.new(ENV.fetch("PATH"))
|
||||||
svn_paths.prepend(svn_shim_path.dirname)
|
svn_paths.prepend(svn_shim_path.dirname)
|
||||||
|
|
||||||
if OS.mac?
|
if OS.mac?
|
||||||
@ -164,7 +164,7 @@ RSpec.configure do |config|
|
|||||||
svnadmin = which("svnadmin", svn_paths)
|
svnadmin = which("svnadmin", svn_paths)
|
||||||
skip "svnadmin is not installed." unless svnadmin
|
skip "svnadmin is not installed." unless svnadmin
|
||||||
|
|
||||||
ENV["PATH"] = PATH.new(ENV["PATH"])
|
ENV["PATH"] = PATH.new(ENV.fetch("PATH"))
|
||||||
.append(svn.dirname)
|
.append(svn.dirname)
|
||||||
.append(svnadmin.dirname)
|
.append(svnadmin.dirname)
|
||||||
end
|
end
|
||||||
|
|||||||
@ -73,7 +73,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin
|
|||||||
env["PATH"],
|
env["PATH"],
|
||||||
(HOMEBREW_LIBRARY_PATH/"test/support/helper/cmd").realpath.to_s,
|
(HOMEBREW_LIBRARY_PATH/"test/support/helper/cmd").realpath.to_s,
|
||||||
(HOMEBREW_PREFIX/"bin").realpath.to_s,
|
(HOMEBREW_PREFIX/"bin").realpath.to_s,
|
||||||
ENV["PATH"],
|
ENV.fetch("PATH"),
|
||||||
].compact.join(File::PATH_SEPARATOR)
|
].compact.join(File::PATH_SEPARATOR)
|
||||||
|
|
||||||
env.merge!(
|
env.merge!(
|
||||||
|
|||||||
@ -274,17 +274,19 @@ describe "globally-scoped helper methods" do
|
|||||||
|
|
||||||
describe "#with_env" do
|
describe "#with_env" do
|
||||||
it "sets environment variables within the block" do
|
it "sets environment variables within the block" do
|
||||||
expect(ENV["PATH"]).not_to eq("/bin")
|
expect(ENV.fetch("PATH")).not_to eq("/bin")
|
||||||
with_env(PATH: "/bin") do
|
with_env(PATH: "/bin") do
|
||||||
expect(ENV["PATH"]).to eq("/bin")
|
expect(ENV.fetch("PATH", nil)).to eq("/bin")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
it "restores ENV after the block" do
|
it "restores ENV after the block" do
|
||||||
with_env(PATH: "/bin") do
|
with_env(PATH: "/bin") do
|
||||||
expect(ENV["PATH"]).to eq("/bin")
|
expect(ENV.fetch("PATH", nil)).to eq("/bin")
|
||||||
end
|
end
|
||||||
expect(ENV["PATH"]).not_to eq("/bin")
|
path = ENV.fetch("PATH", nil)
|
||||||
|
expect(path).not_to be_nil
|
||||||
|
expect(path).not_to eq("/bin")
|
||||||
end
|
end
|
||||||
|
|
||||||
it "restores ENV if an exception is raised" do
|
it "restores ENV if an exception is raised" do
|
||||||
@ -294,7 +296,9 @@ describe "globally-scoped helper methods" do
|
|||||||
end
|
end
|
||||||
}.to raise_error(StandardError)
|
}.to raise_error(StandardError)
|
||||||
|
|
||||||
expect(ENV["PATH"]).not_to eq("/bin")
|
path = ENV.fetch("PATH", nil)
|
||||||
|
expect(path).not_to be_nil
|
||||||
|
expect(path).not_to eq("/bin")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ module UnpackStrategy
|
|||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
system_command! "cabextract",
|
system_command! "cabextract",
|
||||||
args: ["-d", unpack_dir, "--", path],
|
args: ["-d", unpack_dir, "--", path],
|
||||||
env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["cabextract"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@ -39,7 +39,7 @@ module UnpackStrategy
|
|||||||
system_command! "fossil",
|
system_command! "fossil",
|
||||||
args: ["open", path, *args],
|
args: ["open", path, *args],
|
||||||
chdir: unpack_dir,
|
chdir: unpack_dir,
|
||||||
env: { "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["fossil"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -32,7 +32,7 @@ module UnpackStrategy
|
|||||||
"-force-overwrite", "-quiet", "-no-directory",
|
"-force-overwrite", "-quiet", "-no-directory",
|
||||||
"-output-directory", unpack_dir, "--", path
|
"-output-directory", unpack_dir, "--", path
|
||||||
],
|
],
|
||||||
env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["unar"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -29,7 +29,7 @@ module UnpackStrategy
|
|||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
system_command! "lha",
|
system_command! "lha",
|
||||||
args: ["xq2w=#{unpack_dir}", path],
|
args: ["xq2w=#{unpack_dir}", path],
|
||||||
env: { "PATH" => PATH.new(Formula["lha"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["lha"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,7 +31,7 @@ module UnpackStrategy
|
|||||||
quiet_flags = verbose ? [] : ["-q"]
|
quiet_flags = verbose ? [] : ["-q"]
|
||||||
system_command! "lzip",
|
system_command! "lzip",
|
||||||
args: ["-d", *quiet_flags, unpack_dir/basename],
|
args: ["-d", *quiet_flags, unpack_dir/basename],
|
||||||
env: { "PATH" => PATH.new(Formula["lzip"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["lzip"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,7 +31,7 @@ module UnpackStrategy
|
|||||||
quiet_flags = verbose ? [] : ["-q"]
|
quiet_flags = verbose ? [] : ["-q"]
|
||||||
system_command! "unlzma",
|
system_command! "unlzma",
|
||||||
args: [*quiet_flags, "--", unpack_dir/basename],
|
args: [*quiet_flags, "--", unpack_dir/basename],
|
||||||
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -17,7 +17,7 @@ module UnpackStrategy
|
|||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
system_command! "hg",
|
system_command! "hg",
|
||||||
args: ["--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir],
|
args: ["--cwd", path, "archive", "--subrepos", "-y", "-t", "files", unpack_dir],
|
||||||
env: { "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["mercurial"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -29,7 +29,7 @@ module UnpackStrategy
|
|||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
system_command! "7zr",
|
system_command! "7zr",
|
||||||
args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"],
|
args: ["x", "-y", "-bd", "-bso0", path, "-o#{unpack_dir}"],
|
||||||
env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["p7zip"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -29,7 +29,7 @@ module UnpackStrategy
|
|||||||
def extract_to_dir(unpack_dir, basename:, verbose:)
|
def extract_to_dir(unpack_dir, basename:, verbose:)
|
||||||
system_command! "unrar",
|
system_command! "unrar",
|
||||||
args: ["x", "-inul", path, unpack_dir],
|
args: ["x", "-inul", path, unpack_dir],
|
||||||
env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["unrar"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -31,7 +31,7 @@ module UnpackStrategy
|
|||||||
quiet_flags = verbose ? [] : ["-q"]
|
quiet_flags = verbose ? [] : ["-q"]
|
||||||
system_command! "unxz",
|
system_command! "unxz",
|
||||||
args: [*quiet_flags, "-T0", "--", unpack_dir/basename],
|
args: [*quiet_flags, "-T0", "--", unpack_dir/basename],
|
||||||
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["xz"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -37,7 +37,7 @@ module UnpackStrategy
|
|||||||
quiet_flags = verbose ? [] : ["-qq"]
|
quiet_flags = verbose ? [] : ["-qq"]
|
||||||
result = system_command! "unzip",
|
result = system_command! "unzip",
|
||||||
args: [*quiet_flags, "-o", path, "-d", unpack_dir],
|
args: [*quiet_flags, "-o", path, "-d", unpack_dir],
|
||||||
env: { "PATH" => PATH.new(unzip&.opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(unzip&.opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose,
|
verbose: verbose,
|
||||||
print_stderr: false
|
print_stderr: false
|
||||||
|
|
||||||
|
|||||||
@ -31,7 +31,7 @@ module UnpackStrategy
|
|||||||
quiet_flags = verbose ? [] : ["-q"]
|
quiet_flags = verbose ? [] : ["-q"]
|
||||||
system_command! "unzstd",
|
system_command! "unzstd",
|
||||||
args: [*quiet_flags, "-T0", "--rm", "--", unpack_dir/basename],
|
args: [*quiet_flags, "-T0", "--rm", "--", unpack_dir/basename],
|
||||||
env: { "PATH" => PATH.new(Formula["zstd"].opt_bin, ENV["PATH"]) },
|
env: { "PATH" => PATH.new(Formula["zstd"].opt_bin, ENV.fetch("PATH")) },
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -305,7 +305,7 @@ module Kernel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def with_homebrew_path(&block)
|
def with_homebrew_path(&block)
|
||||||
with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"]), &block)
|
with_env(PATH: PATH.new(ORIGINAL_PATHS), &block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def with_custom_locale(locale, &block)
|
def with_custom_locale(locale, &block)
|
||||||
@ -329,7 +329,7 @@ module Kernel
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def which(cmd, path = ENV["PATH"])
|
def which(cmd, path = ENV.fetch("PATH"))
|
||||||
PATH.new(path).each do |p|
|
PATH.new(path).each do |p|
|
||||||
begin
|
begin
|
||||||
pcmd = File.expand_path(cmd, p)
|
pcmd = File.expand_path(cmd, p)
|
||||||
@ -343,7 +343,7 @@ module Kernel
|
|||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def which_all(cmd, path = ENV["PATH"])
|
def which_all(cmd, path = ENV.fetch("PATH"))
|
||||||
PATH.new(path).map do |p|
|
PATH.new(path).map do |p|
|
||||||
begin
|
begin
|
||||||
pcmd = File.expand_path(cmd, p)
|
pcmd = File.expand_path(cmd, p)
|
||||||
@ -362,7 +362,7 @@ module Kernel
|
|||||||
|
|
||||||
# Find Atom, Sublime Text, VS Code, Textmate, BBEdit / TextWrangler, or vim
|
# Find Atom, Sublime Text, VS Code, Textmate, BBEdit / TextWrangler, or vim
|
||||||
editor = %w[atom subl code mate edit vim].find do |candidate|
|
editor = %w[atom subl code mate edit vim].find do |candidate|
|
||||||
candidate if which(candidate, ENV["HOMEBREW_PATH"])
|
candidate if which(candidate, ORIGINAL_PATHS)
|
||||||
end
|
end
|
||||||
editor ||= "vim"
|
editor ||= "vim"
|
||||||
|
|
||||||
@ -499,7 +499,7 @@ module Kernel
|
|||||||
|
|
||||||
executable = [
|
executable = [
|
||||||
which(name),
|
which(name),
|
||||||
which(name, ENV["HOMEBREW_PATH"]),
|
which(name, ORIGINAL_PATHS),
|
||||||
HOMEBREW_PREFIX/"bin/#{name}",
|
HOMEBREW_PREFIX/"bin/#{name}",
|
||||||
].compact.first
|
].compact.first
|
||||||
return executable if executable.exist?
|
return executable if executable.exist?
|
||||||
@ -508,11 +508,7 @@ module Kernel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def paths
|
def paths
|
||||||
@paths ||= PATH.new(ENV["HOMEBREW_PATH"]).map do |p|
|
@paths ||= ORIGINAL_PATHS.uniq.map(&:to_s)
|
||||||
File.expand_path(p).chomp("/")
|
|
||||||
rescue ArgumentError
|
|
||||||
onoe "The following PATH component is invalid: #{p}"
|
|
||||||
end.uniq.compact
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def parse_author!(author)
|
def parse_author!(author)
|
||||||
|
|||||||
@ -124,7 +124,7 @@ module Utils
|
|||||||
gnupg_bin = HOMEBREW_PREFIX/"opt/gnupg/bin"
|
gnupg_bin = HOMEBREW_PREFIX/"opt/gnupg/bin"
|
||||||
return unless gnupg_bin.directory?
|
return unless gnupg_bin.directory?
|
||||||
|
|
||||||
ENV["PATH"] = PATH.new(ENV["PATH"])
|
ENV["PATH"] = PATH.new(ENV.fetch("PATH"))
|
||||||
.prepend(gnupg_bin)
|
.prepend(gnupg_bin)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user