diff --git a/Core/ResourceCompiler/ResourceCompiler.lua b/Core/ResourceCompiler/ResourceCompiler.lua index 30c8b32..1dd9936 100644 --- a/Core/ResourceCompiler/ResourceCompiler.lua +++ b/Core/ResourceCompiler/ResourceCompiler.lua @@ -26,7 +26,7 @@ local function resourceCompile(files, additional, script) script = script, files = absFiles, ext = additional, - hash = string.sha1(json.encode(files) .. json.encode(additional or "")) + hash = string.sha1(json.encode(files) .. json.encode(additional or "") .. script .. cur.name) } auAddBuildAction("pre", "lua", path.join(Aurora.Settings.sAbsScripts, "Core", "ResourceCompiler", "run.lua"), true, meta) diff --git a/Features/detail/use-version-write-prjver-run.lua b/Features/detail/use-version-write-prjver-run.lua new file mode 100644 index 0000000..0299980 --- /dev/null +++ b/Features/detail/use-version-write-prjver-run.lua @@ -0,0 +1,200 @@ +local version = auBuild.projectRoot .. "/Version.json" +local versionH = auBuild.projectRoot .. "/Source/AuVersion.h" +local versionHPP = auBuild.projectRoot .. "/Source/AuVersion.hpp" +local versionC = auBuild.projectRoot .. "/Source/AuVersion.c" + +local projectName = auBuild.projectName + +local manifest = json.decode(io.readfile(version)) + +if (manifest.patch and manifest.incrementPatchOnBuild) then + manifest.patch = manifest.patch + 1; +end + +local includeGit = manifest.includeGit + +local commitString = "" + +if (includeGit) then + local cmd = nil + if (auBuild.shortGitCommit) then + local result, errorCode = os.outputof("git rev-parse --short HEAD") + commitString = result + else + local result, errorCode = os.outputof("git rev-parse --verify HEAD") + commitString = result + end +end + +io.writefile(version, json.encode_pretty(manifest)) + +if (manifest.patch) then + manifest.patch = manifest.patch - 1; +end + +local hheader = manifest.hheader or "" + +local chTemplate = [[ +// Aurora Build Pipeline: Auto-generated Version File + +#include "AuroraTypes.h" +#include "AuroraEnvironment.h" // For "AURORA_SYMBOL_EXPORT", if required +%s +%suint32_ct Get%sVersionHash(); + +%suint16_ct Get%sPatchVersion(); + +%suint16_ct Get%sMinorVersion(); + +%suint16_ct Get%sMajorVersion();%s +]] + + +local vis = nil + +if (manifest.visability) then + vis = manifest.visability .. " " +else + vis = "" +end + +local cppTemplate = [[ +// Aurora Build Pipeline: Auto-generated Version File + +extern "C" +{ + #include "AuVersion.h" +} +]] + +local cHeaderGitExt = "" + +if (includeGit) then + cHeaderGitExt = [[ + + +%sconst char *Get%sCommitString();]] + + cHeaderGitExt = string.format(cHeaderGitExt, vis, projectName) +end + +local formattedChTemplate = string.format(chTemplate, + hheader, + vis, projectName, + vis, projectName, + vis, projectName, + vis, projectName, + cHeaderGitExt +) + +if (not os.isfile(versionH)) then + io.writefile(versionH, formattedChTemplate) +end + +if (not os.isfile(versionHPP)) then + io.writefile(versionHPP, cppTemplate) +end + + +local cheader = manifest.cheader or "" + +local cTemplate = [[ +// Aurora Build Pipeline: Auto-generated Version File + +#define FNV1_MAGIC_VAL32 0x811c9dc5u +#define FNV1_MAGIC_PRIME32 0x01000193u + +#include "AuroraCommon.h" +#include "AuroraEnvironment.h" // For "AURORA_SYMBOL_EXPORT", if required +%s +%suint16_ct Get%sPatchVersion() +{ + return %s; +} + +%suint16_ct Get%sMinorVersion() +{ + return %s; +} + +%suint16_ct Get%sMajorVersion() +{ + return %s; +} + +%suint32_ct Get%sVersionHash() +{ + uint32_ct result = FNV1_MAGIC_VAL32; + static uint32_ct g_result = 0; + + if (g_result) + { + return g_result; + } + +%s + uint32_ct i = 0; + for (; i < sizeof(info); i++) + { + result ^= (uint32_ct)(((const char *)&info)[i]) * (uint32_ct)(FNV1_MAGIC_PRIME32); + } + + return g_result = result; +} +%s]] + +local hashTemplateA = [[ + struct dummy + { + uint16_ct a; + uint16_ct b; + uint16_ct c; + } info; + + info.a = Get%sPatchVersion(); + info.b = Get%sMinorVersion(); + info.c = Get%sMajorVersion(); +]] + +local hashTemplateB = [[ + const char info[sizeof(%s)] = %s; +]] + +local hashTemplate = nil + +if (not includeGit) then + hashTemplate = string.format(hashTemplateA, projectName, projectName, projectName) +else + hashTemplate = string.format(hashTemplateB, "\"" .. commitString .. "\"", "\"" .. commitString .. "\"") +end + +local strVerHash = "" +local strPatch = manifest.patch or "0" +local strMinor = manifest.minor or "0" +local strMajor = manifest.major or "0" +local gitFooter = "" + + +if (includeGit) then + gitFooter = [[ + +%sconst char *Get%sCommitString() +{ + return %s; +} + ]] + + gitFooter = string.format(gitFooter, vis, projectName, "\"" .. commitString .. "\"") +end + + +local formattedCTemplate = string.format(cTemplate, + cheader, + vis, projectName, strPatch, + vis, projectName, strMinor, + vis, projectName, strMajor, + vis, projectName, hashTemplate, + gitFooter +) + +io.writefile(versionC, formattedCTemplate) \ No newline at end of file diff --git a/Features/use-version-write-prjver.lua b/Features/use-version-write-prjver.lua new file mode 100644 index 0000000..a5383ee --- /dev/null +++ b/Features/use-version-write-prjver.lua @@ -0,0 +1,8 @@ +local function feature() + files "Source/AuVersion.h" + files "Source/AuVersion.hpp" + files "Source/AuVersion.c" + auAddBuildAction("pre", "lua", path.join(Aurora.Settings.sAbsScripts, "Features", "detail", "use-version-write-prjver-run.lua"), true) +end + +return feature \ No newline at end of file