[*] 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,30 +1,29 @@
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 else
prjex = "Au" prjex = "Au"
end end
local versionH = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.h" local versionH = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.h"
local versionHPP = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.hpp" local versionHPP = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.hpp"
local versionC = auBuild.projectRoot .. "/Source/" .. prjex .. "Version.c" 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; 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 local cmd = nil
if (auBuild.shortGitCommit) then if (auBuild.shortGitCommit) then
local result, errorCode = os.outputof("git rev-parse --short HEAD") 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") local result, errorCode = os.outputof("git rev-parse --verify HEAD")
commitString = result commitString = result
end 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; 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 // Aurora Build Pipeline: Auto-generated Version File
#include "AuroraTypes.h" #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 .. " " vis = manifest.visability .. " "
else else
vis = "" vis = ""
end end
if (includeGit) then if (includeGit) then
hheader = hheader .. "\n" hheader = hheader .. "\n"
if (shortGitCommit) then if (shortGitCommit) then
@ -77,9 +76,9 @@ if (includeGit) then
end end
hheader = hheader .. "#define VER_" .. string.upper(projectName) .. "_HAS_GIT_VERSION 1\n" 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 // Aurora Build Pipeline: Auto-generated Version File
extern "C" extern "C"
@ -88,18 +87,18 @@ 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,
@ -107,19 +106,19 @@ local formattedChTemplate = string.format(chTemplate,
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,7 +168,7 @@ local cTemplate = [[
} }
%s]] %s]]
local hashTemplateA = [[ local hashTemplateA = [[
struct dummy struct dummy
{ {
uint16_ct a; uint16_ct a;
@ -182,26 +181,26 @@ local hashTemplateA = [[
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()
@ -210,10 +209,10 @@ if (includeGit) then
}]] }]]
gitFooter = string.format(gitFooter, vis, projectName, "\"" .. commitString .. "\"") gitFooter = string.format(gitFooter, vis, projectName, "\"" .. commitString .. "\"")
end end
local formattedCTemplate = string.format(cTemplate, local formattedCTemplate = string.format(cTemplate,
cheader, cheader,
vis, projectName, strPatch, vis, projectName, strPatch,
vis, projectName, strMinor, vis, projectName, strMinor,
@ -221,6 +220,9 @@ local formattedCTemplate = string.format(cTemplate,
vis, projectName, hashTemplate, vis, projectName, hashTemplate,
vis, projectName, manifest.includeGit and "1" or "0", auBuild.shortGitCommit and "1" or "0", vis, projectName, manifest.includeGit and "1" or "0", auBuild.shortGitCommit and "1" or "0",
gitFooter gitFooter
) )
io.writefile(versionC, formattedCTemplate) io.writefile(versionC, formattedCTemplate)
end
return doAction