@@ -54,38 +54,41 @@ local function check_lua_dependency(dep)
5454end
5555
5656--- @param dep ExternalDependency
57- --- @return string | nil binary
58- --- @return string | nil version
57+ --- @return boolean is_installed
58+ --- @return string binary
59+ --- @return string version
5960local check_installed = function (dep )
6061 local binaries = dep .get_binaries ()
6162 for _ , binary in ipairs (binaries ) do
62- local is_installed = dep .is_installed or function (bin )
63+ local is_executable = dep .is_installed or function (bin )
6364 return vim .fn .executable (bin ) == 1
6465 end
65- if is_installed (binary ) then
66+ if is_executable (binary ) then
6667 local handle = io.popen (binary .. ' --version' )
6768 if handle then
6869 local binary_version , error_msg = handle :read (' *a' )
6970 handle :close ()
7071 if error_msg then
71- return binary
72+ return false , binary , error_msg
7273 end
73- return binary , binary_version
74+ return true , binary , binary_version
7475 end
75- return binary
76+ return false , binary , ' Unable to determine version. '
7677 end
7778 end
79+ return false , binaries [1 ], ' Could not find an executable binary.'
7880end
7981
8082--- @param dep ExternalDependency
8183local function check_external_dependency (dep )
82- local binary , version = check_installed (dep )
83- if binary then
84+ local is_installed , binary , version_or_err = check_installed (dep )
85+ if is_installed then
8486 --- @cast binary string
85- local mb_version_newline_idx = version and version :find (' \n ' )
86- local mb_version_len = version and (mb_version_newline_idx and mb_version_newline_idx - 1 or version :len ())
87- version = version and version :sub (0 , mb_version_len ) or ' (unknown version)'
88- ok ((' %s: found %s' ):format (dep .name , version ))
87+ local mb_version_newline_idx = version_or_err and version_or_err :find (' \n ' )
88+ local mb_version_len = version_or_err
89+ and (mb_version_newline_idx and mb_version_newline_idx - 1 or version_or_err :len ())
90+ version_or_err = version_or_err and version_or_err :sub (0 , mb_version_len ) or ' (unknown version)'
91+ ok ((' %s: found %s' ):format (dep .name , version_or_err ))
8992 if dep .extra_checks_if_installed then
9093 dep .extra_checks_if_installed (binary )
9194 end
@@ -99,10 +102,10 @@ local function check_external_dependency(dep)
99102 ]] ):format (dep .name , dep .url , dep .info ))
100103 else
101104 error (([[
102- %s: not found.
105+ %s: not found: %s
103106 rustaceanvim requires %s.
104107 %s
105- ]] ):format (dep .name , dep .url , dep .info ))
108+ ]] ):format (dep .name , version_or_err , dep .url , dep .info ))
106109 end
107110 if dep .extra_checks_if_not_installed then
108111 dep .extra_checks_if_not_installed ()
0 commit comments