Build/Core/Actions/Actions.lua

187 lines
5.5 KiB
Lua
Raw Normal View History

local isUnixPremake = os.host() == "linux" or os.host() == "mac"
local isWin32 = os.host() == "windows"
local isCmakeToolChain = false
2021-11-21 17:23:31 +00:00
local function getExeFileExt()
if isWin32 then
return ".exe"
end
return ""
end
2021-11-21 17:23:31 +00:00
local function testPath(cwd, exe, ext)
local path = cwd .. "/" .. exe .. ext
if (not os.isfile(path)) then
return nil
end
return os.realpath(path)
end
local function getAuBinsForPlatform()
local cwd = auGetAuroraRoot()
if (isUnixPremake) then
cwd = cwd .. auGetSetting("sRelUnixBins")
end
if (isWin32) then
cwd = cwd .. auGetSetting("sRelWin32")
end
return cwd
end
local getPremakeExec = function()
local exec = premake_exe;
if (exec) then
return exec
end
if (isCmakeToolChain) then
premake_exe = auGetSetting("sDefaultCmakePremakeBin")
return premake_exe
end
if (isUnixPremake or isWin32) then
local cwd = getAuBinsForPlatform()
local ext = getExeFileExt()
local mods = {auGetSetting("sDefaultCmakePremakeBin"), "auroramake", "aumake", "premake5", "genie"}
for k, v in pairs(mods) do
local abs = testPath(cwd, v, ext)
if (abs and isUnixPremake) then
premake_exe = v .. ext
else
premake_exe = abs
end
if (premake_exe) then
return premake_exe
end
end
end
if (isWin32) then
if (_PREMAKE_COMMAND) then
premake_exe = _PREMAKE_COMMAND
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 = auGetRoot()
local host = os.host()
local cdAware = isUnixPremake
local command = ""
if (isCmakeToolChain) then
command = ""
elseif (cdAware and scriptType == "lua") then
command = "cd \"" .. getAuBinsForPlatform() .. "\" && "
elseif (cdAware) then
command = "cd \"" .. cwd .. "\" && "
elseif (host == "windows") then
command = "call "
end
local cur = auGetCurrentProjectMeta()
command = command .. getPremakeExec()
local oldBootstrapPrefix = Aurora.Settings.sAbsRepoScripts
local bootstrap = Aurora.Settings.sAbsScripts .. "/Core/Actions/buildActionBootstrap.lua"
command = command .. " --file=\"" .. os.realpath(bootstrap) .. "\""
--command = command .. " --project_name=\"%{prj.name}\""
command = command .. " --project_name=\"" .. cur.name .. "\""
command = command .. " --project_type=\"" .. cur.projectType .. "\""
command = command .. " --project_config=\"%{cfg.longname}\""
command = command .. " --project_arch=\"%{cfg.architecture}\""
command = command .. " --project_platform=\"%{cfg.platform}\""
-- Aurora.Settings could take up too much of the win32 max command line buffer (8191 characters)
-- This seems like a lot, but it should be well within the 9k limit
-- Abs can be skipped and i really dont believe we need the other settings
local settings =
{
sAbsRoot = Aurora.Settings.sAbsRoot,
sRelAuRoot = Aurora.Settings.sRelAuRoot,
sRelScripts = Aurora.Settings.sRelScripts,
sRelRepoScripts = Aurora.Settings.sRelRepoScripts,
sRelDebug = Aurora.Settings.sRelDebug,
sRelStage = Aurora.Settings.sRelStage,
sRelShip = Aurora.Settings.sRelShip,
sRelWd = Aurora.Settings.sRelWd,
sRelSymbols = Aurora.Settings.sRelSymbols,
sRelLinkLibs = Aurora.Settings.sRelLinkLibs
}
command = command .. " --settings=" .. base64.encode(json.encode(settings))
-- the last thing i couldn't port
-- we don't need it
--if (when == "post") then
-- local postBuildSuffix = " --cur_binary=\"%{cfg.buildtarget.abspath}\""
-- command = command .. postBuildSuffix
--end
if (cwdRelToProject) then
command = command .. " --cwd"
end
if (cur and cur.path) then
command = command .. " --project_root=\"" .. _G.path.getrelative(settings.sAbsRoot, cur.path) .. "\""
end
local cliArgs = ""
local argsEscaped = ""
if (args) then
argsEscaped = args:gsub("\"", "\\\"")
cliArgs = " " .. argsEscaped
end
if (args) then
command = command .. " --additional=\"" .. base64.encode(args) .. "\""
end
if (scriptType == "lua") then
if (os.isfile(Aurora.Settings.sAbsRepoScripts .. path)) then
command = command .. " --luascript=\"" .. path .. "\""
else
command = command .. " --luaabsscript=\"" .. _G.path.getrelative(settings.sAbsRoot, path) .. "\""
end
elseif (scriptType == "bin") then
command = command .. " --binscript=\"" .. _G.path.getrelative(settings.sAbsRoot, path) .. cliArgs .. "\""
elseif (scriptType == "cmd") then
command = command .. " --cmd=\"" .. base64.encode(path) .. "\""
elseif (scriptType == "project") then
command = command .. " --projectbins_=\"%{cfg.targetdir}\""
command = command .. " --projectname_=" .. path
command = command .. " --projectnameex_=" .. tostring(Aurora.Settings.bDefinePartialABIInTargetName)
end
if (when == "post") then
postbuildcommands(command)
elseif (when == "pre") then
prebuildcommands(command)
end
end
return addBuildCommand