@@ -495,18 +495,27 @@ def mkdir_p(path)
495495 end
496496
497497 def which ( executable )
498- if File . file? ( executable ) && File . executable? ( executable )
499- executable
500- elsif paths = ENV [ "PATH" ]
498+ executable_path = find_executable ( executable )
499+ return executable_path if executable_path
500+
501+ if ( paths = ENV [ "PATH" ] )
501502 quote = '"'
502503 paths . split ( File ::PATH_SEPARATOR ) . find do |path |
503504 path = path [ 1 ..-2 ] if path . start_with? ( quote ) && path . end_with? ( quote )
504- executable_path = File . expand_path ( executable , path )
505- return executable_path if File . file? ( executable_path ) && File . executable? ( executable_path )
505+ executable_path = find_executable ( File . expand_path ( executable , path ) )
506+ return executable_path if executable_path
506507 end
507508 end
508509 end
509510
511+ def find_executable ( path )
512+ extensions = RbConfig ::CONFIG [ "EXECUTABLE_EXTS" ] &.split
513+ extensions = [ RbConfig ::CONFIG [ "EXEEXT" ] ] unless extensions &.any?
514+ candidates = extensions . map { |ext | "#{ path } #{ ext } " }
515+
516+ candidates . find { |candidate | File . file? ( candidate ) && File . executable? ( candidate ) }
517+ end
518+
510519 def read_file ( file )
511520 SharedHelpers . filesystem_access ( file , :read ) do
512521 File . open ( file , "r:UTF-8" , &:read )
@@ -559,7 +568,7 @@ def clear_gemspec_cache
559568
560569 def git_present?
561570 return @git_present if defined? ( @git_present )
562- @git_present = Bundler . which ( "git#{ RbConfig :: CONFIG [ "EXEEXT" ] } " )
571+ @git_present = Bundler . which ( "git" )
563572 end
564573
565574 def feature_flag
0 commit comments