Build/Actions/buildAction.lua
Reece dd109c82cb [+] Base64 utils
[+] Vala compiler support
[+] Improve guess-platform-code
[*] Clean up
2021-09-14 14:15:46 +01:00

106 lines
2.9 KiB
Lua

local getExeFileExt = function()
if os.host() == "windows" then
return ".exe"
end
return ""
end
local testPath = function(cwd, exe, ext)
local path = cwd .. "/" .. exe .. ext
if (not os.isfile(path)) then
return nil
end
return os.realpath(path)
end
local getPremakeExec = function()
local exec = premake_exe;
if (exec) then
return exec
end
if (_PREMAKE_COMMAND) then
premake_exe = _PREMAKE_COMMAND
return premake_exe
end
local cwd = os.getcwd()
local ext = getExeFileExt()
local mods = {"auroramake", "premake5", "premake", "genie"}
for k, v in pairs(mods) do
premake_exe = testPath(cwd, v, ext)
if (premake_exe) then
return premake_exe
end
end
premake_exe = "premake5"
return premake_exe
end
local addBuildCommand = function(when, scriptType, path, cwdRelToProject, args)
local scriptPath = path
local cwd = getroot()
if (os.host() == "linux") then
command = "cd \"" .. cwd .. "\" && "
elseif (os.host() == "windows") then
command = "call "
end
local cur = getProjectInfo(getCurrentProjectName())
command = command .. getPremakeExec()
command = command .. " --file=\"" .. os.realpath(cwd .. "/Build_Scripts/Actions/buildActionBootstrap.lua") .. "\""
--command = command .. " --project_name=\"%{prj.name}\""
command = command .. " --project_name=\"" .. cur.name .. "\""
command = command .. " --project_arch=\"%{cfg.architecture}\""
command = command .. " --project_platform=\"%{cfg.system}\""
if (cwdRelToProject) then
command = command .. " --actualcwd=\"" .. cur.path .. "\""
else
command = command .. " --actualcwd=\"" .. os.realpath(cwd) .. "\""
end
if (cur and cur.path) then
command = command .. " --project_root=\"" .. cur.path .. "\""
end
command = command .. " --scripts=\"" .. os.realpath(cwd .. "/Build_Scripts") .. "\""
if (when == "post") then
local postBuildSuffix = " --cur_binary=\"%{cfg.buildtarget.abspath}\""
command = command .. postBuildSuffix
end
local cliArgs = ""
local argsEscaped = ""
if (args) then
argsEscaped = args:gsub("\"", "\\\"")
cliArgs = " " .. argsEscaped
end
if (scriptType == "lua") then
if (os.isfile(path) and os.realpath(path) == path) then
command = command .. " --luaabsscript=\"" .. path .. "\""
else
command = command .. " --luascript=\"" .. path .. "\""
end
command = command .. " --additional=\"" .. base64.encode(argsEscaped) .. "\""
elseif (scriptType == "bin") then
command = command .. " --binscript=\"" .. path .. cliArgs .. "\""
end
--command = command:gsub("\\","\\\\")
if (when == "post") then
postbuildcommands(command)
elseif (when == "pre") then
prebuildcommands(command)
end
end
return addBuildCommand