[+] Resource compiler

This commit is contained in:
Reece Wilson 2022-03-05 19:34:41 +00:00
parent dc4d50bc2c
commit ad3a926476
7 changed files with 119 additions and 24 deletions

View File

@ -139,35 +139,32 @@ local addBuildCommand = function(when, scriptType, path, cwdRelToProject, args)
command = command .. " --cwd" command = command .. " --cwd"
end end
local slow = nil
if (cur and cur.path) then if (cur and cur.path) then
slow = _G.path.join(cur.path, path)
command = command .. " --project_root=\"" .. _G.path.getrelative(settings.sAbsRoot, cur.path) .. "\"" command = command .. " --project_root=\"" .. _G.path.getrelative(settings.sAbsRoot, cur.path) .. "\""
end end
local cliArgs = ""
local argsEscaped = ""
if (args) then if (args) then
argsEscaped = args:gsub("\"", "\\\"") local buf = json.encode(args)
cliArgs = " " .. argsEscaped
end
if (args) then
local buf = args--base64.encode(args)
local hash = string.sha1(buf) local hash = string.sha1(buf)
io.writefile(_G.path.join(Aurora.Settings.sAbsCompilerWd, hash .. ".args"), buf) io.writefile(_G.path.join(Aurora.Settings.sAbsCompilerWd, hash .. ".args"), buf)
command = command .. " --additional=\"" .. hash .. "\"" command = command .. " --additional=\"" .. hash .. "\""
end end
if (scriptType == "lua") then if (scriptType == "lua") then
if (os.isfile(_G.path.join(Aurora.Settings.sAbsRepoScripts, path))) then
if (os.isfile(Aurora.Settings.sAbsRepoScripts .. path)) then
command = command .. " --luascript=\"" .. path .. "\"" command = command .. " --luascript=\"" .. path .. "\""
elseif (slow and os.isfile(slow)) then
command = command .. " --luaabsscript=\"" .. _G.path.getrelative(settings.sAbsRoot, slow) .. "\""
else else
command = command .. " --luaabsscript=\"" .. _G.path.getrelative(settings.sAbsRoot, path) .. "\"" command = command .. " --luaabsscript=\"" .. _G.path.getrelative(settings.sAbsRoot, path) .. "\""
end end
elseif (scriptType == "bin") then elseif (scriptType == "bin") then
command = command .. " --binscript=\"" .. _G.path.getrelative(settings.sAbsRoot, path) .. cliArgs .. "\"" command = command .. " --binscript=\"" .. _G.path.getrelative(settings.sAbsRoot, path) .. "\""
elseif (scriptType == "cmd") then elseif (scriptType == "cmd") then
command = command .. " --cmd=\"" .. base64.encode(path) .. "\"" command = command .. " --cmd=\"" .. base64.encode(path) .. "\""

View File

@ -7,11 +7,14 @@ function auFetchGlobal(name)
return ret return ret
end end
local function escapeBinaryPath(path) local function escapeBinaryPath(bin)
bin = path.translate(bin, path.getDefaultSeparator())
if (os.host() == "windows") then if (os.host() == "windows") then
return "\"" .. path .. "\"" return "\"" .. bin .. "\""
end end
return path:gsub(" ", "\\ ")
return bin:gsub(" ", "\\ ")
end end
require("./../../Utilities/Utilities") require("./../../Utilities/Utilities")
@ -78,17 +81,19 @@ local args = _OPTIONS["additional"]
if (args) then if (args) then
local path = _G.path.join(Aurora.Settings.sAbsCompilerWd, args .. ".args") local path = _G.path.join(Aurora.Settings.sAbsCompilerWd, args .. ".args")
local argFileContents = io.readfile(path) local argFileContents = io.readfile(path)
args = argFileContents args = json.decode(argFileContents)
end end
local binSuffx = ""
if (args) then
binSuffx = " " .. args
end
local binScript = _OPTIONS["binscript"] local binScript = _OPTIONS["binscript"]
if (binScript) then if (binScript) then
os.exit(os.execute(path.join(Aurora.Settings.sAbsRoot, binScript) .. binSuffx))
local binSuffx = ""
if (args) then
binSuffx = " " .. args
end
os.exit(os.execute(escapeBinaryPath(path.join(Aurora.Settings.sAbsRoot, binScript)) .. binSuffx))
end end
local cmd = _OPTIONS["cmd"] local cmd = _OPTIONS["cmd"]

View File

@ -291,6 +291,21 @@ local function auBlockProjectKeyDllexport(processor, value)
__pushFilter(value, "value", defines, processor) __pushFilter(value, "value", defines, processor)
end end
local function auBlockProjectKeyDllexport(processor, value)
__pushFilter(value, "value", defines, processor)
end
local function auBlockProjectKeyResourceScript(processor, value, map, tasks)
__pushFilter(value, nil, function(value)
auForEachKV(value, function(key, value)
if (auIsArray(value)) then
auAddResource(value, nil, key)
else
auAddResource(value.files, value.arguments, key)
end
end)
end, processor)
end
local function auBlockProjectKeySoftDepends(processor, value) local function auBlockProjectKeySoftDepends(processor, value)
__pushFilter(value, "value", function(obj) __pushFilter(value, "value", function(obj)
@ -368,7 +383,8 @@ auProjectBlockHandlers =
noRootInclude = auBlockProjectKeyImplNoRootInclude, noRootInclude = auBlockProjectKeyImplNoRootInclude,
events = auBlockProjectKeyBuildEvent, events = auBlockProjectKeyBuildEvent,
actions = auBlockProjectKeyBuildAction, actions = auBlockProjectKeyBuildAction,
features = auBlockKeyFeature features = auBlockKeyFeature,
resourceScript = auBlockProjectKeyResourceScript
} }
auProjectBlockHandlers["soft-depends"] = auBlockProjectKeySoftDepends auProjectBlockHandlers["soft-depends"] = auBlockProjectKeySoftDepends
@ -397,7 +413,7 @@ auProjectRefHandlers["depends"] = auBlockProjectRefKeyDepends
"impInclude", "implInclude", "impIncludes", "implIncludes", "clangIgnore", "impInclude", "implInclude", "impIncludes", "implIncludes", "clangIgnore",
"msvcIgnore", "excludes", "depends", "require", "msvcIgnore", "excludes", "depends", "require",
"eval", "lua", "events", "actions", "staticImpDefines", "features", "eval", "lua", "events", "actions", "staticImpDefines", "features",
"links", "soft-depends" "links", "soft-depends", "resourceScript"
} }
local kReferenceTasks = {"eval", "includes", "include", "includes"} --, "features"} local kReferenceTasks = {"eval", "includes", "include", "includes"} --, "features"}

View File

@ -0,0 +1,33 @@
local function resourceCompile(files, additional, script)
auForEach(files, _G.files)
local absFiles = {}
auForEach(files, function(file)
table.insert(absFiles, os.realpath(file))
end)
local cur = auGetCurrentProjectMeta()
local projScript = nil
if (cur and cur.path) then
projScript = path.join(cur.path, script)
end
local userScript = path.join(Aurora.Settings.sAbsRepoScripts, script)
if (os.isfile(userScript)) then
script = userScript
elseif (projScript and os.isfile(projScript)) then
script = projScript
end
local meta = {
script = script,
files = absFiles,
ext = additional,
hash = string.sha1(json.encode(files) .. json.encode(additional or ""))
}
auAddBuildAction("pre", "lua", path.join(Aurora.Settings.sAbsScripts, "Core", "ResourceCompiler", "run.lua"), true, meta)
end
return resourceCompile

View File

@ -0,0 +1,39 @@
local timestampMap = {}
local timestampMapCache = {}
auForEach(auBuild.args.files, function(file)
timestampMap[file] = os.stat(file).mtime
end)
local cachePath = path.join(Aurora.Settings.sAbsCompilerWd, auBuild.args.hash) .. ".rsc"
if (os.isfile(cachePath)) then
timestampMapCache = json.decode(io.readfile(cachePath))
end
io.writefile(cachePath, json.encode(timestampMap))
local changedFiles = {}
local unchangedFiles = {}
if (type(timestampMapCache) == "table") then
auForEachKV(timestampMap, function(file, changed)
if (timestampMapCache[file] == changed) then
table.insert(unchangedFiles, file)
else
table.insert(changedFiles, file)
end
end)
else
auForEachKV(timestampMap, function(file, changed)
table.insert(changedFiles, file)
end)
end
auResourceCompiler = {
unchangedFiles = unchangedFiles,
changedFiles = changedFiles,
arguments = auBuild.args.ext
}
auRequireAbs(auBuild.args.script)

View File

@ -104,7 +104,7 @@ local function addVala(extended)
auAddBuildAction("pre", "bin", exec, true, args) auAddBuildAction("pre", "bin", exec, true, args)
if (myBrainHurts) then if (myBrainHurts) then
auAddBuildAction("pre", "lua", path.translate(path.join(Aurora.Settings.sAbsRepoScripts, "Core", "Vala", "valaSym2Def.lua"), path.getDefaultSeparator()), true) auAddBuildAction("pre", "lua", path.translate(path.join(Aurora.Settings.sAbsScripts, "Core", "Vala", "valaSym2Def.lua"), path.getDefaultSeparator()), true)
end end
end end

View File

@ -2,6 +2,7 @@
local buildAction = auRequire("Core/Actions") local buildAction = auRequire("Core/Actions")
local target = auRequire("Core/Target") local target = auRequire("Core/Target")
local main = auRequire("Core/Main") local main = auRequire("Core/Main")
local resourceCompiler = auRequire("Core/ResourceCompiler")
-- executes inline under iprocessor::process -- executes inline under iprocessor::process
function auAddBuildAction(...) function auAddBuildAction(...)
@ -150,3 +151,7 @@ end
function auIsProjectIntialized(name) function auIsProjectIntialized(name)
return main.isProjectLoaded(name) return main.isProjectLoaded(name)
end end
function auAddResource(...)
resourceCompiler(...)
end