summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-09-02 22:54:15 +0800
committerruki <[email protected]>2024-09-02 22:54:15 +0800
commitb7dbf58d81a5731ec404afe57b2af4fa783d6b72 (patch)
tree23d3e5daf7a2e360fb37fd7f782022f5bb1da308
parent4e9459eca8abe50b31f498541173948f2153f7b4 (diff)
improve to get shell path
-rw-r--r--xmake/core/base/os.lua32
1 files changed, 31 insertions, 1 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index 9160aa534..2dba50509 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -288,6 +288,36 @@ function os._run_exit_cbs(ok, errors)
end
end
+-- get shell path, e.g. sh, bash
+function os._get_shell_path(opt)
+ opt = opt or {}
+ local setenvs = opt.setenvs or opt.envs or {}
+ local addenvs = opt.addenvs or {}
+ local paths = {}
+ local p = setenvs.PATH
+ if type(p) == "string" then
+ p = path.splitenv(p)
+ end
+ if p then
+ table.join2(paths, p)
+ end
+ p = addenvs.PATH
+ if type(p) == "string" then
+ p = path.splitenv(p)
+ end
+ if p then
+ table.join2(paths, p)
+ end
+ for _, p in ipairs(paths) do
+ for _, name in ipairs({"sh", "bash"}) do
+ local filepath = path.join(p, name)
+ if os.isexec(filepath) then
+ return filepath
+ end
+ end
+ end
+end
+
-- match files or directories
--
-- @param pattern the search pattern
@@ -808,7 +838,7 @@ function os.execv(program, argv, opt)
-- because `/bin/sh` is not real file path, maybe we need to convert it.
local host = os.host()
if host == "windows" then
- filename = "sh"
+ filename = os._get_shell_path(opt) or "sh"
argv = table.join(shellfile, argv)
else
line = line:sub(3)