mirror of
https://github.com/ruby/ruby.git
synced 2026-01-28 21:14:28 +00:00
[rubygems/rubygems] fix bundle which commands on windows
https://github.com/rubygems/rubygems/commit/9e0018d9fe
This commit is contained in:
parent
80cfa57234
commit
0989400a92
@ -495,18 +495,27 @@ module Bundler
|
||||
end
|
||||
|
||||
def which(executable)
|
||||
if File.file?(executable) && File.executable?(executable)
|
||||
executable
|
||||
elsif paths = ENV["PATH"]
|
||||
executable_path = find_executable(executable)
|
||||
return executable_path if executable_path
|
||||
|
||||
if (paths = ENV["PATH"])
|
||||
quote = '"'
|
||||
paths.split(File::PATH_SEPARATOR).find do |path|
|
||||
path = path[1..-2] if path.start_with?(quote) && path.end_with?(quote)
|
||||
executable_path = File.expand_path(executable, path)
|
||||
return executable_path if File.file?(executable_path) && File.executable?(executable_path)
|
||||
executable_path = find_executable(File.expand_path(executable, path))
|
||||
return executable_path if executable_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def find_executable(path)
|
||||
extensions = RbConfig::CONFIG["EXECUTABLE_EXTS"]&.split
|
||||
extensions = [RbConfig::CONFIG["EXEEXT"]] unless extensions&.any?
|
||||
candidates = extensions.map {|ext| "#{path}#{ext}" }
|
||||
|
||||
candidates.find {|candidate| File.file?(candidate) && File.executable?(candidate) }
|
||||
end
|
||||
|
||||
def read_file(file)
|
||||
SharedHelpers.filesystem_access(file, :read) do
|
||||
File.open(file, "r:UTF-8", &:read)
|
||||
@ -559,7 +568,7 @@ module Bundler
|
||||
|
||||
def git_present?
|
||||
return @git_present if defined?(@git_present)
|
||||
@git_present = Bundler.which("git#{RbConfig::CONFIG["EXEEXT"]}")
|
||||
@git_present = Bundler.which("git")
|
||||
end
|
||||
|
||||
def feature_flag
|
||||
|
||||
@ -174,7 +174,13 @@ RSpec.describe Bundler do
|
||||
end
|
||||
end
|
||||
|
||||
let(:expected) { "executable" }
|
||||
let(:expected) do
|
||||
if Gem.win_platform?
|
||||
"executable.exe"
|
||||
else
|
||||
"executable"
|
||||
end
|
||||
end
|
||||
|
||||
before do
|
||||
ENV["PATH"] = path.join(File::PATH_SEPARATOR)
|
||||
@ -200,7 +206,7 @@ RSpec.describe Bundler do
|
||||
context "when the executable in inside a quoted path" do
|
||||
let(:expected) do
|
||||
if Gem.win_platform?
|
||||
"C:/e/executable"
|
||||
"C:/e/executable.exe"
|
||||
else
|
||||
"/e/executable"
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user