[*] improve feature script cwd awareness

This commit is contained in:
Reece Wilson 2023-09-12 15:31:59 +01:00
parent ad4696983a
commit 21e2df1ebb
2 changed files with 132 additions and 118 deletions

View File

@ -72,12 +72,17 @@ if (projectBins) then
end
local cwd = _OPTIONS["cwd"]
local passThroughCWD = nil
if (cwd) then
os.chdir(projRoot)
passThroughCWD = projRoot
else
os.chdir(Aurora.Settings.sAbsRoot)
passThroughCWD = Aurora.Settings.sAbsRoot
end
local root = Aurora.Settings.sAbsRoot
local args = _OPTIONS["additional"]
if (args) then
local path = _G.path.join(Aurora.Settings.sAbsCompilerWd, args .. ".args")
@ -198,15 +203,22 @@ auBuild =
projectTargetName = targetName,
projectTargetFileName = fileName,
args = args,
root = cwd
root = root,
cwd = passThroughCWD
}
local luaScript = _OPTIONS["luascript"]
local luaAbsScript = _OPTIONS["luaabsscript"]
local fn = nil
if (luaScript) then
auRequireAbs(path.join(Aurora.Settings.sAbsRepoScripts, luaScript))
fn = auRequireAbs(path.join(Aurora.Settings.sAbsRepoScripts, luaScript))
elseif (luaAbsScript) then
auRequireAbs(path.join(Aurora.Settings.sAbsRoot, luaAbsScript))
fn = auRequireAbs(path.join(Aurora.Settings.sAbsRoot, luaAbsScript))
end
if (type(fn) == "function") then
os.chdir(passThroughCWD)
fn()
end
os.exit()

View File

@ -1,30 +1,29 @@
local projectName = auBuild.projectName
local version = auBuild.projectRoot .. "/Version.json"
local function doAction()
local projectName = auBuild.projectName
local version = auBuild.projectRoot .. "/Version.json"
local manifest = json.decode(io.readfile(version))
local manifest = json.decode(io.readfile(version))
local prjex = ""
if (not manifest.noPrjName) then
local prjex = ""
if (not manifest.noPrjName) then
prjex = projectName
else
else
prjex = "Au"
end
end
local versionH = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.h"
local versionHPP = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.hpp"
local versionC = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.c"
local versionH = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.h"
local versionHPP = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.hpp"
local versionC = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.c"
if (manifest.patch and manifest.incrementPatchOnBuild) then
if (manifest.patch and manifest.incrementPatchOnBuild) then
manifest.patch = manifest.patch + 1;
end
end
local includeGit = manifest.includeGit
local includeGit = manifest.includeGit
local commitString = ""
local commitString = ""
os.chdir(auBuild.root)
if (includeGit) then
if (includeGit) then
local cmd = nil
if (auBuild.shortGitCommit) then
local result, errorCode = os.outputof("git rev-parse --short HEAD")
@ -33,17 +32,17 @@ if (includeGit) then
local result, errorCode = os.outputof("git rev-parse --verify HEAD")
commitString = result
end
end
end
io.writefile(version, json.encode_pretty(manifest))
io.writefile(version, json.encode_pretty(manifest))
if (manifest.patch) then
if (manifest.patch) then
manifest.patch = manifest.patch - 1;
end
end
local hheader = manifest.hheader or ""
local hheader = manifest.hheader or ""
local chTemplate = [[
local chTemplate = [[
// Aurora Build Pipeline: Auto-generated Version File
#include "AuroraTypes.h"
@ -61,15 +60,15 @@ local chTemplate = [[
]]
local vis = nil
local vis = nil
if (manifest.visability) then
if (manifest.visability) then
vis = manifest.visability .. " "
else
else
vis = ""
end
end
if (includeGit) then
if (includeGit) then
hheader = hheader .. "\n"
if (shortGitCommit) then
@ -77,9 +76,9 @@ if (includeGit) then
end
hheader = hheader .. "#define VER_" .. string.upper(projectName) .. "_HAS_GIT_VERSION 1\n"
end
end
local cppTemplate = [[
local cppTemplate = [[
// Aurora Build Pipeline: Auto-generated Version File
extern "C"
@ -88,18 +87,18 @@ extern "C"
}
]]
local cHeaderGitExt = ""
local cHeaderGitExt = ""
if (includeGit) then
if (includeGit) then
cHeaderGitExt = [[
%sconst char *Get%sCommitString();]]
cHeaderGitExt = string.format(cHeaderGitExt, vis, projectName)
end
end
local formattedChTemplate = string.format(chTemplate,
local formattedChTemplate = string.format(chTemplate,
hheader,
vis, projectName,
vis, projectName,
@ -107,19 +106,19 @@ local formattedChTemplate = string.format(chTemplate,
vis, projectName,
vis, projectName,
cHeaderGitExt
)
)
if (not os.isfile(versionH)) then
if (not os.isfile(versionH)) then
io.writefile(versionH, formattedChTemplate)
end
end
if (not os.isfile(versionHPP)) then
if (not os.isfile(versionHPP)) then
io.writefile(versionHPP, string.format(cppTemplate, projectName))
end
end
local cheader = manifest.cheader or ""
local cheader = manifest.cheader or ""
local cTemplate = [[
local cTemplate = [[
// Aurora Build Pipeline: Auto-generated Version File
#define FNV1_MAGIC_VAL32 0x811c9dc5u
@ -169,7 +168,7 @@ local cTemplate = [[
}
%s]]
local hashTemplateA = [[
local hashTemplateA = [[
struct dummy
{
uint16_ct a;
@ -182,26 +181,26 @@ local hashTemplateA = [[
info.c = Get%sMajorVersion();
]]
local hashTemplateB = [[
local hashTemplateB = [[
const char info[sizeof(%s)] = %s;
]]
local hashTemplate = nil
local hashTemplate = nil
if (not includeGit) then
if (not includeGit) then
hashTemplate = string.format(hashTemplateA, projectName, projectName, projectName)
else
else
hashTemplate = string.format(hashTemplateB, "\"" .. commitString .. "\"", "\"" .. commitString .. "\"")
end
end
local strVerHash = ""
local strPatch = manifest.patch or "0"
local strMinor = manifest.minor or "0"
local strMajor = manifest.major or "0"
local gitFooter = ""
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
if (includeGit) then
gitFooter = [[
%sconst char *Get%sCommitString()
@ -210,10 +209,10 @@ if (includeGit) then
}]]
gitFooter = string.format(gitFooter, vis, projectName, "\"" .. commitString .. "\"")
end
end
local formattedCTemplate = string.format(cTemplate,
local formattedCTemplate = string.format(cTemplate,
cheader,
vis, projectName, strPatch,
vis, projectName, strMinor,
@ -221,6 +220,9 @@ local formattedCTemplate = string.format(cTemplate,
vis, projectName, hashTemplate,
vis, projectName, manifest.includeGit and "1" or "0", auBuild.shortGitCommit and "1" or "0",
gitFooter
)
)
io.writefile(versionC, formattedCTemplate)
io.writefile(versionC, formattedCTemplate)
end
return doAction