Build/Core/Actions/buildActionBootstrap.lua

212 lines
4.6 KiB
Lua

local aurora = {}
_G["Aurora"] = aurora
function auFetchGlobal(name)
local ret = aurora[name] or {}
aurora[name] = ret
return ret
end
local function escapeBinaryPath(bin)
bin = path.translate(bin, path.getDefaultSeparator())
bin = os.realpath(bin)
if (os.host() == "windows") then
return "\"" .. bin .. "\""
end
return bin:gsub(" ", "\\ ")
end
require("./../../Utilities/Utilities")
local triggers =
{
"binscript",
"luascript",
"cwd",
"cmd",
"settings",
"project_name",
"project_arch",
"project_platform",
"project_root",
"additional",
"project_type",
"luaabsscript",
"projectname_",
"projectbins_",
"projectnameex_",
"project_config",
"project_name"
}
auForEach(triggers, function(trigger)
newoption
{
trigger = trigger,
description = ""
}
end)
local settings = _OPTIONS["settings"]
if (settings) then
Aurora.Settings = json.decode(base64.decode(settings))
require("./../../Public/paths")
end
require("./../Target/platform")
local preconfig = path.join(Aurora.Settings.sAbsRoot, "preconfig.lua")
if (os.isfile(preconfig)) then
auRequireAbs(preconfig)
end
local projRoot = path.join(Aurora.Settings.sAbsRoot, _OPTIONS["project_root"] or "./")
local projectBins = _OPTIONS["projectbins_"]
if (projectBins) then
projectBins = os.realpath(path.join(projRoot, projectBins))
end
local cwd = _OPTIONS["cwd"]
if (cwd) then
os.chdir(projRoot)
else
os.chdir(Aurora.Settings.sAbsRoot)
end
local args = _OPTIONS["additional"]
if (args) then
local path = _G.path.join(Aurora.Settings.sAbsCompilerWd, args .. ".args")
local argFileContents = io.readfile(path)
args = json.decode(argFileContents)
end
local binScript = _OPTIONS["binscript"]
if (binScript) then
local binSuffx = ""
if (args) then
binSuffx = " " .. args
end
local cmd = escapeBinaryPath(path.join(Aurora.Settings.sAbsRoot, binScript)) .. binSuffx
if (os.host() == "windows") then
cmd = "call " .. cmd
end
print("Running binary: ", cmd)
os.exit(os.execute(cmd))
end
local cmd = _OPTIONS["cmd"]
if (cmd) then
local cmd = base64.decode(cmd)
if (args) then
cmd = cmd .. " " .. args
end
if (os.host() == "windows") then
cmd = "call " .. cmd
end
print("Running command: ", cmd)
os.exit(os.execute(cmd))
end
local projName = _OPTIONS["project_name"]
local projType = _OPTIONS["project_type"]
local projPlatform = _OPTIONS["project_platform"]
local projCfg = _OPTIONS["project_config"]
local projArch = _OPTIONS["project_arch"]
local target = auRequire("Core/Target")
for k, v in pairs(Aurora.Architectures) do
if (projArch == v.architecture) then
projArch = k
break
end
end
if (string.ends(projPlatform, projArch)) then
projPlatform = projPlatform:sub(1, - #projArch - 1)
end
if (string.find(projCfg, "|")) then
projCfg = projCfg:match("([^,]+)|([^,]+)")
end
target.defineOutputNames(projPlatform)
local platform = Aurora.Platforms[projPlatform]
local platformStyle = projPlatform
if (platform) then
if (platform.outputName) then
platformStyle = platform.outputName
end
end
local targetName = string.format("%s.%s.%s.%s", projName, projCfg, platformStyle, projArch)
local fileName = targetName
if (platform) then
fileName = fileName .. ((platform.exts or {})[projType] or "")
end
if (projectBins) then
local projectName = _OPTIONS["projectname_"]
local projectNameEx = _OPTIONS["projectnameex_"] == "true"
local extension = (platform.exts or {})["ConsoleApp"]
local binName = projectName
if (projectNameEx) then
binName = string.format("%s.%s.%s.%s", binName, projCfg, projPlatform, projArch)
end
local binSuffx = ""
if (args) then
binSuffx = " " .. args
end
binName = binName .. extension
local cmd = escapeBinaryPath(path.join(projectBins, binName)) .. binSuffx
if (os.host() == "windows") then
cmd = "call " .. cmd
end
print("Running project: ", cmd)
os.exit(os.execute(cmd))
end
auBuild =
{
platform = projPlatform,
architecture = projArch,
projectName = projName,
projectType = projType,
projectRoot = projRoot,
projectTargetName = targetName,
projectTargetFileName = fileName,
args = args,
root = cwd
}
local luaScript = _OPTIONS["luascript"]
local luaAbsScript = _OPTIONS["luaabsscript"]
if (luaScript) then
auRequireAbs(path.join(Aurora.Settings.sAbsRepoScripts, luaScript))
elseif (luaAbsScript) then
auRequireAbs(path.join(Aurora.Settings.sAbsRoot, luaAbsScript))
end
os.exit()