diff options
author | sodacris <[email protected]> | 2024-11-22 19:58:38 +0800 |
---|---|---|
committer | git <[email protected]> | 2024-11-22 13:36:21 +0000 |
commit | 0989400a925cd201defdca9eb28eb87200b30785 (patch) | |
tree | 53c3144856db822b4ae9eb25e7f073eb213cb55a | |
parent | 80cfa57234255667a86d46096093099349a7262a (diff) |
[rubygems/rubygems] fix bundle which commands on windows
https://github.com/rubygems/rubygems/commit/9e0018d9fe
-rw-r--r-- | lib/bundler.rb | 21 | ||||
-rw-r--r-- | spec/bundler/bundler/bundler_spec.rb | 10 |
2 files changed, 23 insertions, 8 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb index c1d7c46e4d..1140de5467 100644 --- a/lib/bundler.rb +++ b/lib/bundler.rb @@ -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 diff --git a/spec/bundler/bundler/bundler_spec.rb b/spec/bundler/bundler/bundler_spec.rb index 7cfc12a6f6..27bcb92659 100644 --- a/spec/bundler/bundler/bundler_spec.rb +++ b/spec/bundler/bundler/bundler_spec.rb @@ -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 |