From 64c2f1ef70fdab5a14c3625144a58cddc5fccdee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xenxo=20Espasand=C3=ADn?= Date: Tue, 13 Jun 2023 15:40:54 +0200 Subject: [PATCH] maint(build): new version system (#129) --- .gitignore | 4 +++ deps/zlib.lua | 4 +++ premake5.lua | 65 ++++++++++++++++++++++++++++++++++++++++++++--- src/tool/main.cpp | 8 ++++++ 4 files changed, 78 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 679bdf98..c106cf87 100644 --- a/.gitignore +++ b/.gitignore @@ -149,6 +149,7 @@ user*.bat # VScode .vscode/ +# Output folders renamed/ parsed/ compiled/ @@ -157,3 +158,6 @@ assembled/ disassembled/ data/* + +# Version file +include/xsk/version.hpp diff --git a/deps/zlib.lua b/deps/zlib.lua index c2edca24..9b3c893f 100644 --- a/deps/zlib.lua +++ b/deps/zlib.lua @@ -29,6 +29,10 @@ function zlib:project() "_CRT_NONSTDC_NO_DEPRECATE", "_CRT_SECURE_NO_DEPRECATE", } + + if os.istarget("darwin") then + defines "HAVE_UNISTD_H" + end end table.insert(dependencies, zlib) diff --git a/premake5.lua b/premake5.lua index a7a82c3a..bed1213f 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,3 +1,6 @@ +------------------------------------------------- +-- DEPENDENCIES +------------------------------------------------- dependencies = { base = path.getrelative(os.getcwd(), path.getabsolute("deps")) } function dependencies.load() @@ -11,6 +14,62 @@ function dependencies.load() end dependencies.load() + +------------------------------------------------- +-- VERSIONING +------------------------------------------------- +function version_split(version, revision) + array = {} + + for num in string.gmatch(version or "", "%d+") do + if #array < 3 then + table.insert(array, tonumber(num)) + end + end + + while #array < 3 do + table.insert(array, 0) + end + + table.insert(array, tonumber(revision)) + + return array +end + +function generate_version() + -- get current version + local proc1 = assert(io.popen("git describe --tags --abbrev=0", "r")) + local version = assert(proc1:read('*a')):gsub("%s+", "") + proc1:close() + + -- get current branch + local proc2 = assert(io.popen("git symbolic-ref -q --short HEAD", "r")) + local branch = assert(proc2:read('*a')):gsub("%s+", "") + proc2:close() + + -- get revision number + local proc3 = assert(io.popen("git rev-list --count HEAD", "r")) + local revision = assert(proc3:read("*a")):gsub("%s+", "") + proc3:close() + + local split = version_split(version, revision) + local verstr = split[1] .. "." .. split[2] .. "." .. split[3] .. "." .. split[4] .. "-" .. branch + + local file = assert(io.open("include/xsk/version.hpp", "w")) + file:write("// Generated by premake - do not edit\n\n") + file:write("#define XSK_VERSION_MAJOR " .. split[1] .. "\n") + file:write("#define XSK_VERSION_MINOR " .. split[2] .. "\n") + file:write("#define XSK_VERSION_PATCH " .. split[3] .. "\n") + file:write("#define XSK_VERSION_BUILD " .. split[4] .. "\n") + file:write("#define XSK_VERSION_BRANCH \"" .. branch .. "\"\n") + file:write("#define XSK_VERSION_STR \"" .. verstr .. "\"\n") + file:close() +end + +generate_version() + +------------------------------------------------- +-- PROJECTS ------------------------------------------------- workspace "gsc-tool" startproject "xsk-tool" @@ -40,7 +99,7 @@ workspace "gsc-tool" filter {} filter { "language:C++", "toolset:not msc*" } - buildoptions "-std=c++20" + buildoptions "-std=c++20" filter {} filter "toolset:msc*" @@ -50,11 +109,11 @@ workspace "gsc-tool" filter {} filter { "system:windows" } - systemversion "latest" + systemversion "latest" filter {} filter { "system:macosx" } - systemversion "12.0" + systemversion "12.0" filter {} symbols "On" diff --git a/src/tool/main.cpp b/src/tool/main.cpp index 02c8f37b..a6052e05 100644 --- a/src/tool/main.cpp +++ b/src/tool/main.cpp @@ -30,6 +30,7 @@ #include "xsk/arc/engine/t7.hpp" #include "xsk/arc/engine/t8.hpp" #include "xsk/arc/engine/t9.hpp" +#include "xsk/version.hpp" namespace fs = std::filesystem; @@ -1017,6 +1018,11 @@ auto print_usage() -> void std::cin.get(); } +auto branding() -> void +{ + std::cout << fmt::format("\nGSC Tool {} created by xensik\n\n", XSK_VERSION_STR); +} + auto main(u32 argc, char** argv) -> void { auto path = fs::path{}; @@ -1024,6 +1030,8 @@ auto main(u32 argc, char** argv) -> void auto game = game::_; auto mach = mach::_; + branding(); + if (!parse_flags(argc, argv, mode, game, mach, path)) { return print_usage();