Build/Features/detail/use-version-write-prjver-run.lua

290 lines
6.9 KiB
Lua
Raw Normal View History

local function GetSnapshotName(full)
local strYear = os.date("%y")
local strMon = os.date("%m")
2023-09-28 16:08:59 +00:00
local iWeekdayOffset = tonumber(os.date("%w"))
local iMonthOffset = tonumber(os.date("%d"))
if (iWeekdayOffset == 0) then iWeekdayOffset = 6
else iWeekdayOffset = iWeekdayOffset - 1 end
2023-09-28 16:08:59 +00:00
local iWeekIdxOffset = math.floor((iMonthOffset - iWeekdayOffset) / 7)
if (iWeekIdxOffset < 0) then iWeekIdxOffset = 0 end
local bWeekTest = iWeekdayOffset > 2
local cWeekBase = "A"
if (bWeekTest) then cWeekBase = "a" else cWeekBase = "A" end
if (iWeekIdxOffset > 4) then iWeekIdxOffset = 4 end
local cWeekChar = string.char(string.byte(cWeekBase) + iWeekIdxOffset)
if (not full) then strYear = strYear:sub(2, 2) end
2023-09-28 16:08:59 +00:00
return strYear .. strMon .. cWeekChar
end
local function DoAction()
local projectName = auBuild.projectName
local version = auBuild.projectRoot .. "/Version.json"
2023-08-30 21:39:19 +00:00
local manifest = json.decode(io.readfile(version))
2023-08-30 21:39:19 +00:00
local prjex = ""
if (not manifest.noPrjName) then
prjex = projectName
else
prjex = "Au"
end
2023-08-31 17:27:47 +00:00
local versionH = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.h"
local versionHPP = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.hpp"
local versionC = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.c"
2023-08-30 21:39:19 +00:00
local patchVer = 0
if (manifest.patch) then
patchVer = manifest.patch
if (manifest.incrementPatchOnBuild) then
manifest.patch = patchVer + 1;
end
end
local includeGit = manifest.includeGit
local includeARD = manifest.includeARD
local includeARDExtended = manifest.includeARDExtended
local includeARDFull = manifest.includeARDFull
2023-08-30 21:39:19 +00:00
local relString = ""
local commitString = ""
2023-08-31 17:27:47 +00:00
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
2023-08-30 21:39:19 +00:00
end
if (includeARD) then
relString = GetSnapshotName(includeARDFull)
if (includeARDExtended) then
relString = relString .. patchVer
end
end
2023-08-30 21:39:19 +00:00
io.writefile(version, json.encode_pretty(manifest))
2023-08-30 21:39:19 +00:00
if (manifest.patch) then
manifest.patch = patchVer
end
2023-08-30 21:39:19 +00:00
local hheader = manifest.hheader or ""
2023-08-30 21:39:19 +00:00
local chTemplate = [[
2023-08-30 21:39:19 +00:00
// 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();
2023-08-31 17:27:47 +00:00
%suint16_ct Get%sMajorVersion();
%suint32_ct Get%sGitVersionDetail();%s
2023-08-30 21:39:19 +00:00
]]
local vis = nil
2023-08-30 21:39:19 +00:00
if (manifest.visibility) then
vis = manifest.visibility .. " "
else
vis = ""
end
2023-08-30 21:39:19 +00:00
if (includeGit) then
hheader = hheader .. "\n"
if (shortGitCommit) then
hheader = hheader .. "#define VER_" .. string.upper(projectName) .. "_USES_SMALL_HASH 1\n"
end
hheader = hheader .. "#define VER_" .. string.upper(projectName) .. "_HAS_GIT_VERSION 1\n"
2023-08-31 17:27:47 +00:00
end
local cppTemplate = [[
2023-08-30 21:39:19 +00:00
// Aurora Build Pipeline: Auto-generated Version File
extern "C"
{
2023-08-31 17:27:47 +00:00
#include "%sVersion.h"
2023-08-30 21:39:19 +00:00
}
]]
local cHeaderGitExt = ""
2023-08-30 21:39:19 +00:00
if (includeGit) then
cHeaderGitExt = [[
2023-08-30 21:39:19 +00:00
%sconst char *Get%sCommitString();]]
cHeaderGitExt = string.format(cHeaderGitExt, vis, projectName)
end
2023-08-30 21:39:19 +00:00
if (includeARD) then
local hARDFooter = [[
%sconst char *Get%sAuroraReleaseDate();]]
cHeaderGitExt = cHeaderGitExt .. string.format(hARDFooter, vis, projectName)
end
local formattedChTemplate = string.format(chTemplate,
hheader,
vis, projectName,
vis, projectName,
vis, projectName,
vis, projectName,
vis, projectName,
cHeaderGitExt
)
if (not os.isfile(versionH)) then
io.writefile(versionH, formattedChTemplate)
end
2023-08-30 21:39:19 +00:00
if (not os.isfile(versionHPP)) then
io.writefile(versionHPP, string.format(cppTemplate, projectName))
end
2023-08-30 21:39:19 +00:00
local cheader = manifest.cheader or ""
2023-08-30 21:39:19 +00:00
local cTemplate = [[
2023-08-30 21:39:19 +00:00
// 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;
}
2023-08-31 17:27:47 +00:00
%suint32_ct Get%sGitVersionDetail()
{
return %su | (%s << 1u);
}
2023-08-30 21:39:19 +00:00
%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();
2023-08-30 21:39:19 +00:00
]]
local hashTemplateB = [[
2023-08-30 21:39:19 +00:00
const char info[sizeof(%s)] = %s;
]]
local hashTemplate = nil
2023-08-30 21:39:19 +00:00
if (not includeGit) then
hashTemplate = string.format(hashTemplateA, projectName, projectName, projectName)
else
hashTemplate = string.format(hashTemplateB, "\"" .. commitString .. "\"", "\"" .. commitString .. "\"")
end
2023-08-30 21:39:19 +00:00
local strVerHash = ""
local strPatch = manifest.patch or "0"
local strMinor = manifest.minor or "0"
local strMajor = manifest.major or "0"
local gitFooter = ""
2023-08-30 21:39:19 +00:00
if (includeGit) then
gitFooter = [[
2023-08-31 17:27:47 +00:00
2023-08-30 21:39:19 +00:00
%sconst char *Get%sCommitString()
{
return %s;
2023-08-31 17:27:47 +00:00
}]]
gitFooter = string.format(gitFooter, vis, projectName, "\"" .. commitString .. "\"")
end
2023-08-30 21:39:19 +00:00
if (manifest.includeARD) then
local atfooter = [[
%sconst char *Get%sAuroraReleaseDate()
{
return %s;
}]]
if (includeGit) then
atfooter = [[
]] .. atfooter
end
atfooter = string.format(atfooter, vis, projectName, "\"" .. relString .. "\"")
gitFooter = gitFooter .. atfooter
end
2023-08-30 21:39:19 +00:00
local formattedCTemplate = string.format(cTemplate,
cheader,
vis, projectName, strPatch,
vis, projectName, strMinor,
vis, projectName, strMajor,
vis, projectName, hashTemplate,
vis, projectName, manifest.includeGit and "1" or "0", auBuild.shortGitCommit and "1" or "0",
gitFooter
)
io.writefile(versionC, formattedCTemplate)
end
2023-08-30 21:39:19 +00:00
return DoAction