Skip to content

Commit

Permalink
Merge pull request #2810 from xmake-io/shell
Browse files Browse the repository at this point in the history
support os.execv with {shell = true}
  • Loading branch information
waruqi authored Sep 13, 2022
2 parents d9eefbd + fcaad7a commit 8f60e9b
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
22 changes: 22 additions & 0 deletions xmake/core/base/os.lua
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,28 @@ function os.execv(program, argv, opt)
end
end

-- run shell file? parse `#!/usr/bin/env bash` in xx.sh
--
-- e.g. os.execv("./configure", {"--help"}) => os.execv("/usr/bin/env", {"bash", "./configure", "--help"})
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
head = head:sub(3)
local shellargv = {}
local splitinfo = head: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
file:close()
end

-- uses the given environments?
local envs = nil
if opt.envs then
Expand Down
8 changes: 4 additions & 4 deletions xmake/modules/package/tools/autoconf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,16 @@ function configure(package, configs, opt)
-- generate configure file
if not os.isfile("configure") then
if os.isfile("autogen.sh") then
os.vrunv("sh", {"./autogen.sh"}, {envs = autogen_envs(package, opt)})
os.vrunv("./autogen.sh", {}, {shell = true, envs = autogen_envs(package, opt)})
elseif os.isfile("configure.ac") or os.isfile("configure.in") then
local autoreconf = find_tool("autoreconf")
assert(autoreconf, "autoreconf not found!")
os.vrunv("sh", {autoreconf.program, "--install", "--symlink"}, {envs = autogen_envs(package, opt)})
os.vrunv(autoreconf.program, {"--install", "--symlink"}, {shell = true, envs = autogen_envs(package, opt)})
end
end

-- pass configurations
local argv = {"./configure"}
local argv = {}
for name, value in pairs(_get_configs(package, configs)) do
value = tostring(value):trim()
if value ~= "" then
Expand All @@ -414,7 +414,7 @@ function configure(package, configs, opt)
end

-- do configure
os.vrunv("sh", argv, {envs = envs})
os.vrunv("./configure", argv, {shell = true, envs = envs})
end

-- do make
Expand Down
6 changes: 3 additions & 3 deletions xmake/modules/private/action/trybuild/autotools.lua
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ function build()
-- generate configure
if not os.isfile("configure") then
if os.isfile("autogen.sh") then
os.vexecv("sh", {"./autogen.sh"})
os.vexecv("./autogen.sh", {}, {shell = true})
elseif os.isfile("configure.ac") or os.isfile("configure.in") then
local autoreconf = find_tool("autoreconf")
assert(autoreconf, "autoreconf not found!")
os.vexecv("sh", {autoreconf.program, "--install", "--symlink"})
os.vexecv(autoreconf.program, {"--install", "--symlink"}, {shell = true})
end
end

-- do configure
local configfile = find_file("[mM]akefile", os.curdir())
if not configfile or os.mtime(config.filepath()) > os.mtime(configfile) then
os.vexecv("sh", table.join("./configure", _get_configs(artifacts_dir)), {envs = _get_buildenvs()})
os.vexecv("./configure", _get_configs(artifacts_dir), {shell = true, envs = _get_buildenvs()})
end

-- do build
Expand Down

0 comments on commit 8f60e9b

Please sign in to comment.