2023-09-18 02:09:58 +00:00
|
|
|
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
|
2023-10-25 10:49:09 +00:00
|
|
|
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
|
2023-09-18 02:09:58 +00:00
|
|
|
local cWeekBase = "A"
|
|
|
|
if (bWeekTest) then cWeekBase = "a" else cWeekBase = "A" end
|
2023-10-25 10:49:09 +00:00
|
|
|
if (iWeekIdxOffset > 4) then iWeekIdxOffset = 4 end
|
2023-09-18 02:09:58 +00:00
|
|
|
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
|
2023-09-18 02:09:58 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local function DoAction()
|
2023-09-12 14:31:59 +00:00
|
|
|
local projectName = auBuild.projectName
|
|
|
|
local version = auBuild.projectRoot .. "/Version.json"
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local manifest = json.decode(io.readfile(version))
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local prjex = ""
|
|
|
|
if (not manifest.noPrjName) then
|
|
|
|
prjex = projectName
|
|
|
|
else
|
|
|
|
prjex = "Au"
|
|
|
|
end
|
2023-08-31 17:27:47 +00:00
|
|
|
|
2023-09-12 14:31:59 +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
|
|
|
|
2023-09-18 02:09:58 +00:00
|
|
|
local patchVer = 0
|
|
|
|
|
|
|
|
if (manifest.patch) then
|
|
|
|
patchVer = manifest.patch
|
|
|
|
|
|
|
|
if (manifest.incrementPatchOnBuild) then
|
|
|
|
manifest.patch = patchVer + 1;
|
|
|
|
end
|
2023-09-12 14:31:59 +00:00
|
|
|
end
|
2023-09-18 02:09:58 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local includeGit = manifest.includeGit
|
2023-09-18 02:09:58 +00:00
|
|
|
local includeARD = manifest.includeARD
|
|
|
|
local includeARDExtended = manifest.includeARDExtended
|
|
|
|
local includeARDFull = manifest.includeARDFull
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-18 02:09:58 +00:00
|
|
|
local relString = ""
|
2023-09-12 14:31:59 +00:00
|
|
|
local commitString = ""
|
2023-08-31 17:27:47 +00:00
|
|
|
|
2023-09-12 14:31:59 +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
|
2023-09-18 02:09:58 +00:00
|
|
|
|
|
|
|
if (includeARD) then
|
|
|
|
relString = GetSnapshotName(includeARDFull)
|
|
|
|
|
|
|
|
if (includeARDExtended) then
|
|
|
|
relString = relString .. patchVer
|
|
|
|
end
|
|
|
|
end
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
io.writefile(version, json.encode_pretty(manifest))
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
if (manifest.patch) then
|
2023-09-18 02:09:58 +00:00
|
|
|
manifest.patch = patchVer
|
2023-09-12 14:31:59 +00:00
|
|
|
end
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local hheader = manifest.hheader or ""
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +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
|
|
|
]]
|
|
|
|
|
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local vis = nil
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-18 02:09:58 +00:00
|
|
|
if (manifest.visibility) then
|
|
|
|
vis = manifest.visibility .. " "
|
2023-09-12 14:31:59 +00:00
|
|
|
else
|
|
|
|
vis = ""
|
|
|
|
end
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +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
|
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
]]
|
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local cHeaderGitExt = ""
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
if (includeGit) then
|
|
|
|
cHeaderGitExt = [[
|
2023-08-30 21:39:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
%sconst char *Get%sCommitString();]]
|
2023-09-12 14:31:59 +00:00
|
|
|
|
|
|
|
cHeaderGitExt = string.format(cHeaderGitExt, vis, projectName)
|
|
|
|
end
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-18 02:09:58 +00:00
|
|
|
if (includeARD) then
|
|
|
|
local hARDFooter = [[
|
|
|
|
|
|
|
|
|
|
|
|
%sconst char *Get%sAuroraReleaseDate();]]
|
|
|
|
|
|
|
|
cHeaderGitExt = cHeaderGitExt .. string.format(hARDFooter, vis, projectName)
|
|
|
|
end
|
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
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
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
if (not os.isfile(versionHPP)) then
|
|
|
|
io.writefile(versionHPP, string.format(cppTemplate, projectName))
|
|
|
|
end
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local cheader = manifest.cheader or ""
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +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]]
|
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
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
|
|
|
]]
|
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local hashTemplateB = [[
|
2023-08-30 21:39:19 +00:00
|
|
|
const char info[sizeof(%s)] = %s;
|
|
|
|
]]
|
|
|
|
|
2023-09-12 14:31:59 +00:00
|
|
|
local hashTemplate = nil
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-12 14:31:59 +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
|
|
|
|
2023-09-12 14:31:59 +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
|
|
|
|
2023-09-12 14:31:59 +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
|
|
|
}]]
|
2023-09-12 14:31:59 +00:00
|
|
|
|
|
|
|
gitFooter = string.format(gitFooter, vis, projectName, "\"" .. commitString .. "\"")
|
|
|
|
end
|
2023-08-30 21:39:19 +00:00
|
|
|
|
2023-09-18 02:09:58 +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
|
|
|
|
2023-09-12 14:31:59 +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
|
|
|
|
2023-09-18 02:09:58 +00:00
|
|
|
return DoAction
|