@@ -492,6 +492,45 @@ module Sys
492492 import Base. Sys: isapple, isbsd, islinux, isunix, iswindows
493493 end
494494
495+ @static if VERSION < v " 0.7.0-DEV.5171"
496+ function isexecutable (path:: AbstractString )
497+ if iswindows ()
498+ isfile (path)
499+ else
500+ ccall (:access , Cint, (Ptr{UInt8}, Cint), path, 0x01 ) == 0
501+ end
502+ end
503+
504+ function which (program:: AbstractString )
505+ progs = String[]
506+ base = basename (program)
507+ if iswindows ()
508+ isempty (last (splitext (base))) || push! (progs, base)
509+ for p = [" .exe" , " .com" ]
510+ push! (progs, base * p)
511+ end
512+ else
513+ push! (progs, base)
514+ end
515+ dirs = String[]
516+ dir = dirname (program)
517+ if isempty (dir)
518+ pathsep = iswindows () ? ' ;' : ' :'
519+ append! (dirs, map (abspath, split (get (ENV , " PATH" , " " ), pathsep)))
520+ iswindows () && pushfirst! (dirs, pwd ())
521+ else
522+ push! (dirs, abspath (dir))
523+ end
524+ for d in dirs, p in progs
525+ path = joinpath (d, p)
526+ isexecutable (path) && return realpath (path)
527+ end
528+ error (" $program not found" )
529+ end
530+ else
531+ import Base. Sys: which, isexecutable
532+ end
533+
495534 # https://github.com/JuliaLang/julia/pull/25102
496535 # NOTE: This needs to be in an __init__ because JULIA_HOME is not
497536 # defined when building system images.
0 commit comments