Skip to content

Commit b7dbf58

Browse files
committed
improve to get shell path
1 parent 4e9459e commit b7dbf58

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

xmake/core/base/os.lua

+31-1
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,36 @@ function os._run_exit_cbs(ok, errors)
288288
end
289289
end
290290

291+
-- get shell path, e.g. sh, bash
292+
function os._get_shell_path(opt)
293+
opt = opt or {}
294+
local setenvs = opt.setenvs or opt.envs or {}
295+
local addenvs = opt.addenvs or {}
296+
local paths = {}
297+
local p = setenvs.PATH
298+
if type(p) == "string" then
299+
p = path.splitenv(p)
300+
end
301+
if p then
302+
table.join2(paths, p)
303+
end
304+
p = addenvs.PATH
305+
if type(p) == "string" then
306+
p = path.splitenv(p)
307+
end
308+
if p then
309+
table.join2(paths, p)
310+
end
311+
for _, p in ipairs(paths) do
312+
for _, name in ipairs({"sh", "bash"}) do
313+
local filepath = path.join(p, name)
314+
if os.isexec(filepath) then
315+
return filepath
316+
end
317+
end
318+
end
319+
end
320+
291321
-- match files or directories
292322
--
293323
-- @param pattern the search pattern
@@ -808,7 +838,7 @@ function os.execv(program, argv, opt)
808838
-- because `/bin/sh` is not real file path, maybe we need to convert it.
809839
local host = os.host()
810840
if host == "windows" then
811-
filename = "sh"
841+
filename = os._get_shell_path(opt) or "sh"
812842
argv = table.join(shellfile, argv)
813843
else
814844
line = line:sub(3)

0 commit comments

Comments
 (0)