From ad3a9264764487b11aa074ba519fde4e9252efab Mon Sep 17 00:00:00 2001 From: Reece Date: Sat, 5 Mar 2022 19:34:41 +0000 Subject: [PATCH] [+] Resource compiler --- Core/Actions/Actions.lua | 19 +++++------ Core/Actions/buildActionBootstrap.lua | 23 ++++++++----- Core/JSON/jsonProjectHandlers.lua | 20 +++++++++-- Core/ResourceCompiler/ResourceCompiler.lua | 33 ++++++++++++++++++ Core/ResourceCompiler/run.lua | 39 ++++++++++++++++++++++ Core/Vala/Vala.lua | 2 +- Public/api.lua | 7 +++- 7 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 Core/ResourceCompiler/run.lua diff --git a/Core/Actions/Actions.lua b/Core/Actions/Actions.lua index a77b9fe..e14277d 100644 --- a/Core/Actions/Actions.lua +++ b/Core/Actions/Actions.lua @@ -139,35 +139,32 @@ local addBuildCommand = function(when, scriptType, path, cwdRelToProject, args) command = command .. " --cwd" end + local slow = nil + if (cur and cur.path) then + slow = _G.path.join(cur.path, path) 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 - local buf = args--base64.encode(args) + local buf = json.encode(args) local hash = string.sha1(buf) io.writefile(_G.path.join(Aurora.Settings.sAbsCompilerWd, hash .. ".args"), buf) command = command .. " --additional=\"" .. hash .. "\"" end if (scriptType == "lua") then - - if (os.isfile(Aurora.Settings.sAbsRepoScripts .. path)) then + if (os.isfile(_G.path.join(Aurora.Settings.sAbsRepoScripts, path))) then command = command .. " --luascript=\"" .. path .. "\"" + elseif (slow and os.isfile(slow)) then + command = command .. " --luaabsscript=\"" .. _G.path.getrelative(settings.sAbsRoot, slow) .. "\"" 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 .. "\"" + command = command .. " --binscript=\"" .. _G.path.getrelative(settings.sAbsRoot, path) .. "\"" elseif (scriptType == "cmd") then command = command .. " --cmd=\"" .. base64.encode(path) .. "\"" diff --git a/Core/Actions/buildActionBootstrap.lua b/Core/Actions/buildActionBootstrap.lua index 5de697f..1e0525a 100644 --- a/Core/Actions/buildActionBootstrap.lua +++ b/Core/Actions/buildActionBootstrap.lua @@ -7,11 +7,14 @@ function auFetchGlobal(name) return ret end -local function escapeBinaryPath(path) +local function escapeBinaryPath(bin) + bin = path.translate(bin, path.getDefaultSeparator()) + if (os.host() == "windows") then - return "\"" .. path .. "\"" + return "\"" .. bin .. "\"" end - return path:gsub(" ", "\\ ") + + return bin:gsub(" ", "\\ ") end require("./../../Utilities/Utilities") @@ -78,17 +81,19 @@ local args = _OPTIONS["additional"] if (args) then local path = _G.path.join(Aurora.Settings.sAbsCompilerWd, args .. ".args") local argFileContents = io.readfile(path) - args = argFileContents + args = json.decode(argFileContents) end -local binSuffx = "" -if (args) then - binSuffx = " " .. args -end local binScript = _OPTIONS["binscript"] 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 local cmd = _OPTIONS["cmd"] diff --git a/Core/JSON/jsonProjectHandlers.lua b/Core/JSON/jsonProjectHandlers.lua index 043d5da..8eca6f8 100644 --- a/Core/JSON/jsonProjectHandlers.lua +++ b/Core/JSON/jsonProjectHandlers.lua @@ -291,6 +291,21 @@ local function auBlockProjectKeyDllexport(processor, value) __pushFilter(value, "value", defines, processor) 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) __pushFilter(value, "value", function(obj) @@ -368,7 +383,8 @@ auProjectBlockHandlers = noRootInclude = auBlockProjectKeyImplNoRootInclude, events = auBlockProjectKeyBuildEvent, actions = auBlockProjectKeyBuildAction, - features = auBlockKeyFeature + features = auBlockKeyFeature, + resourceScript = auBlockProjectKeyResourceScript } auProjectBlockHandlers["soft-depends"] = auBlockProjectKeySoftDepends @@ -397,7 +413,7 @@ auProjectRefHandlers["depends"] = auBlockProjectRefKeyDepends "impInclude", "implInclude", "impIncludes", "implIncludes", "clangIgnore", "msvcIgnore", "excludes", "depends", "require", "eval", "lua", "events", "actions", "staticImpDefines", "features", - "links", "soft-depends" + "links", "soft-depends", "resourceScript" } local kReferenceTasks = {"eval", "includes", "include", "includes"} --, "features"} diff --git a/Core/ResourceCompiler/ResourceCompiler.lua b/Core/ResourceCompiler/ResourceCompiler.lua index e69de29..d00e098 100644 --- a/Core/ResourceCompiler/ResourceCompiler.lua +++ b/Core/ResourceCompiler/ResourceCompiler.lua @@ -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 \ No newline at end of file diff --git a/Core/ResourceCompiler/run.lua b/Core/ResourceCompiler/run.lua new file mode 100644 index 0000000..04fe510 --- /dev/null +++ b/Core/ResourceCompiler/run.lua @@ -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) \ No newline at end of file diff --git a/Core/Vala/Vala.lua b/Core/Vala/Vala.lua index 290756d..8a545b3 100644 --- a/Core/Vala/Vala.lua +++ b/Core/Vala/Vala.lua @@ -104,7 +104,7 @@ local function addVala(extended) auAddBuildAction("pre", "bin", exec, true, args) 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 diff --git a/Public/api.lua b/Public/api.lua index 8503ad4..c5d4fb0 100644 --- a/Public/api.lua +++ b/Public/api.lua @@ -2,6 +2,7 @@ local buildAction = auRequire("Core/Actions") local target = auRequire("Core/Target") local main = auRequire("Core/Main") +local resourceCompiler = auRequire("Core/ResourceCompiler") -- executes inline under iprocessor::process function auAddBuildAction(...) @@ -143,10 +144,14 @@ end function auGetCurrentProjectMeta() local temp = auGetCurrentProjectProcessor() - if (not temp) then return end + if (not temp) then return end return auGetCurrentProjectProcessor():getMeta() end function auIsProjectIntialized(name) return main.isProjectLoaded(name) end + +function auAddResource(...) + resourceCompiler(...) +end \ No newline at end of file