summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2023-09-25 23:19:47 +0800
committerruki <[email protected]>2023-09-25 23:19:47 +0800
commit9ffa3457c8b7d63006a14b86a937c329fd6cd3de (patch)
treef2946e9e55536b46242afcdd1188a1606803013c
parent964f92c7f3afc0e2ac4401f665a3da3e1595575f (diff)
improve os.execv for shell #4241
-rw-r--r--xmake/core/base/os.lua38
1 files changed, 20 insertions, 18 deletions
diff --git a/xmake/core/base/os.lua b/xmake/core/base/os.lua
index b375650c7..7ae34ccc2 100644
--- a/xmake/core/base/os.lua
+++ b/xmake/core/base/os.lua
@@ -776,25 +776,27 @@ function os.execv(program, argv, opt)
if opt.shell and os.isfile(filename) then
local shellfile = filename
local file = io.open(filename, 'r')
- local head = file:read("l")
- if head and head:startswith("#!") then
- -- we cannot run `/bin/sh` directly on msys2/cygwin
- -- because `/bin/sh` is not real file path, maybe we need to convert it.
- local subhost = os.subhost()
- if subhost == "msys" or subhost == "cygwin" then
- filename = "sh"
- argv = table.join(shellfile, argv)
- else
- head = head:sub(3)
- local shellargv = {}
- local splitinfo = head:split("%s")
- filename = splitinfo[1]
- if #splitinfo > 1 then
- shellargv = table.slice(splitinfo, 2)
+ for line in file:lines() do
+ if line and line:startswith("#!") then
+ -- we cannot run `/bin/sh` directly on msys2/cygwin
+ -- because `/bin/sh` is not real file path, maybe we need to convert it.
+ local subhost = os.subhost()
+ if subhost == "msys" or subhost == "cygwin" then
+ filename = "sh"
+ argv = table.join(shellfile, argv)
+ else
+ line = line:sub(3)
+ local shellargv = {}
+ local splitinfo = line:split("%s")
+ filename = splitinfo[1]
+ if #splitinfo > 1 then
+ shellargv = table.slice(splitinfo, 2)
+ end
+ table.insert(shellargv, shellfile)
+ table.join2(shellargv, argv)
+ argv = shellargv
end
- table.insert(shellargv, shellfile)
- table.join2(shellargv, argv)
- argv = shellargv
+ break
end
end
file:close()