@@ -495,18 +495,27 @@ def mkdir_p(path)
495
495
end
496
496
497
497
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" ] )
501
502
quote = '"'
502
503
paths . split ( File ::PATH_SEPARATOR ) . find do |path |
503
504
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
506
507
end
507
508
end
508
509
end
509
510
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
+
510
519
def read_file ( file )
511
520
SharedHelpers . filesystem_access ( file , :read ) do
512
521
File . open ( file , "r:UTF-8" , &:read )
@@ -559,7 +568,7 @@ def clear_gemspec_cache
559
568
560
569
def git_present?
561
570
return @git_present if defined? ( @git_present )
562
- @git_present = Bundler . which ( "git#{ RbConfig :: CONFIG [ "EXEEXT" ] } " )
571
+ @git_present = Bundler . which ( "git" )
563
572
end
564
573
565
574
def feature_flag
0 commit comments