[*] 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 end
local cwd = _OPTIONS["cwd"] local cwd = _OPTIONS["cwd"]
local passThroughCWD = nil
if (cwd) then if (cwd) then
os.chdir(projRoot) os.chdir(projRoot)
passThroughCWD = projRoot
else else
os.chdir(Aurora.Settings.sAbsRoot) os.chdir(Aurora.Settings.sAbsRoot)
passThroughCWD = Aurora.Settings.sAbsRoot
end end
local root = Aurora.Settings.sAbsRoot
local args = _OPTIONS["additional"] local args = _OPTIONS["additional"]
if (args) then if (args) then
local path = _G.path.join(Aurora.Settings.sAbsCompilerWd, args .. ".args") local path = _G.path.join(Aurora.Settings.sAbsCompilerWd, args .. ".args")
@ -198,15 +203,22 @@ auBuild =
projectTargetName = targetName, projectTargetName = targetName,
projectTargetFileName = fileName, projectTargetFileName = fileName,
args = args, args = args,
root = cwd root = root,
cwd = passThroughCWD
} }
local luaScript = _OPTIONS["luascript"] local luaScript = _OPTIONS["luascript"]
local luaAbsScript = _OPTIONS["luaabsscript"] local luaAbsScript = _OPTIONS["luaabsscript"]
local fn = nil
if (luaScript) then if (luaScript) then
auRequireAbs(path.join(Aurora.Settings.sAbsRepoScripts, luaScript)) fn = auRequireAbs(path.join(Aurora.Settings.sAbsRepoScripts, luaScript))
elseif (luaAbsScript) then 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 end
os.exit() os.exit()

View File

@ -1,49 +1,48 @@
local projectName = auBuild.projectName local function doAction()
local version = auBuild.projectRoot .. "/Version.json" 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 = "" local prjex = ""
if (not manifest.noPrjName) then if (not manifest.noPrjName) then
prjex = projectName prjex = projectName
else
prjex = "Au"
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"
if (manifest.patch and manifest.incrementPatchOnBuild) then
manifest.patch = manifest.patch + 1;
end
local includeGit = manifest.includeGit
local commitString = ""
os.chdir(auBuild.root)
if (includeGit) then
local cmd = nil
if (auBuild.shortGitCommit) then
local result, errorCode = os.outputof("git rev-parse --short HEAD")
commitString = result
else else
local result, errorCode = os.outputof("git rev-parse --verify HEAD") prjex = "Au"
commitString = result
end end
end
io.writefile(version, json.encode_pretty(manifest)) 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) then if (manifest.patch and manifest.incrementPatchOnBuild) then
manifest.patch = manifest.patch - 1; manifest.patch = manifest.patch + 1;
end end
local hheader = manifest.hheader or "" local includeGit = manifest.includeGit
local chTemplate = [[ 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 // Aurora Build Pipeline: Auto-generated Version File
#include "AuroraTypes.h" #include "AuroraTypes.h"
@ -61,25 +60,25 @@ local chTemplate = [[
]] ]]
local vis = nil local vis = nil
if (manifest.visability) then if (manifest.visability) then
vis = manifest.visability .. " " vis = manifest.visability .. " "
else else
vis = "" vis = ""
end
if (includeGit) then
hheader = hheader .. "\n"
if (shortGitCommit) then
hheader = hheader .. "#define VER_" .. string.upper(projectName) .. "_USES_SMALL_HASH 1\n"
end end
hheader = hheader .. "#define VER_" .. string.upper(projectName) .. "_HAS_GIT_VERSION 1\n"
end
local cppTemplate = [[ 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"
end
local cppTemplate = [[
// Aurora Build Pipeline: Auto-generated Version File // Aurora Build Pipeline: Auto-generated Version File
extern "C" extern "C"
@ -88,38 +87,38 @@ extern "C"
} }
]] ]]
local cHeaderGitExt = "" local cHeaderGitExt = ""
if (includeGit) then if (includeGit) then
cHeaderGitExt = [[ cHeaderGitExt = [[
%sconst char *Get%sCommitString();]] %sconst char *Get%sCommitString();]]
cHeaderGitExt = string.format(cHeaderGitExt, vis, projectName) cHeaderGitExt = string.format(cHeaderGitExt, vis, projectName)
end end
local formattedChTemplate = string.format(chTemplate, local formattedChTemplate = string.format(chTemplate,
hheader, hheader,
vis, projectName, vis, projectName,
vis, projectName, vis, projectName,
vis, projectName, vis, projectName,
vis, projectName, vis, projectName,
vis, projectName, vis, projectName,
cHeaderGitExt cHeaderGitExt
) )
if (not os.isfile(versionH)) then if (not os.isfile(versionH)) then
io.writefile(versionH, formattedChTemplate) 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)) 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 // Aurora Build Pipeline: Auto-generated Version File
#define FNV1_MAGIC_VAL32 0x811c9dc5u #define FNV1_MAGIC_VAL32 0x811c9dc5u
@ -169,58 +168,61 @@ local cTemplate = [[
} }
%s]] %s]]
local hashTemplateA = [[ local hashTemplateA = [[
struct dummy struct dummy
{ {
uint16_ct a; uint16_ct a;
uint16_ct b; uint16_ct b;
uint16_ct c; uint16_ct c;
} info; } info;
info.a = Get%sPatchVersion(); info.a = Get%sPatchVersion();
info.b = Get%sMinorVersion(); info.b = Get%sMinorVersion();
info.c = Get%sMajorVersion(); info.c = Get%sMajorVersion();
]] ]]
local hashTemplateB = [[ local hashTemplateB = [[
const char info[sizeof(%s)] = %s; 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) hashTemplate = string.format(hashTemplateA, projectName, projectName, projectName)
else else
hashTemplate = string.format(hashTemplateB, "\"" .. commitString .. "\"", "\"" .. commitString .. "\"") hashTemplate = string.format(hashTemplateB, "\"" .. commitString .. "\"", "\"" .. commitString .. "\"")
end end
local strVerHash = "" local strVerHash = ""
local strPatch = manifest.patch or "0" local strPatch = manifest.patch or "0"
local strMinor = manifest.minor or "0" local strMinor = manifest.minor or "0"
local strMajor = manifest.major or "0" local strMajor = manifest.major or "0"
local gitFooter = "" local gitFooter = ""
if (includeGit) then if (includeGit) then
gitFooter = [[ gitFooter = [[
%sconst char *Get%sCommitString() %sconst char *Get%sCommitString()
{ {
return %s; return %s;
}]] }]]
gitFooter = string.format(gitFooter, vis, projectName, "\"" .. commitString .. "\"") 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,
vis, projectName, manifest.includeGit and "1" or "0", auBuild.shortGitCommit and "1" or "0",
gitFooter
)
io.writefile(versionC, formattedCTemplate)
end end
return doAction
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)