maint(build): new version system (#129)

This commit is contained in:
Xenxo Espasandín 2023-06-13 15:40:54 +02:00 committed by GitHub
parent 34a67d97c6
commit 64c2f1ef70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 78 additions and 3 deletions

4
.gitignore vendored
View File

@ -149,6 +149,7 @@ user*.bat
# VScode # VScode
.vscode/ .vscode/
# Output folders
renamed/ renamed/
parsed/ parsed/
compiled/ compiled/
@ -157,3 +158,6 @@ assembled/
disassembled/ disassembled/
data/* data/*
# Version file
include/xsk/version.hpp

4
deps/zlib.lua vendored
View File

@ -29,6 +29,10 @@ function zlib:project()
"_CRT_NONSTDC_NO_DEPRECATE", "_CRT_NONSTDC_NO_DEPRECATE",
"_CRT_SECURE_NO_DEPRECATE", "_CRT_SECURE_NO_DEPRECATE",
} }
if os.istarget("darwin") then
defines "HAVE_UNISTD_H"
end
end end
table.insert(dependencies, zlib) table.insert(dependencies, zlib)

View File

@ -1,3 +1,6 @@
-------------------------------------------------
-- DEPENDENCIES
-------------------------------------------------
dependencies = { base = path.getrelative(os.getcwd(), path.getabsolute("deps")) } dependencies = { base = path.getrelative(os.getcwd(), path.getabsolute("deps")) }
function dependencies.load() function dependencies.load()
@ -11,6 +14,62 @@ function dependencies.load()
end end
dependencies.load() 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" workspace "gsc-tool"
startproject "xsk-tool" startproject "xsk-tool"
@ -40,7 +99,7 @@ workspace "gsc-tool"
filter {} filter {}
filter { "language:C++", "toolset:not msc*" } filter { "language:C++", "toolset:not msc*" }
buildoptions "-std=c++20" buildoptions "-std=c++20"
filter {} filter {}
filter "toolset:msc*" filter "toolset:msc*"
@ -50,11 +109,11 @@ workspace "gsc-tool"
filter {} filter {}
filter { "system:windows" } filter { "system:windows" }
systemversion "latest" systemversion "latest"
filter {} filter {}
filter { "system:macosx" } filter { "system:macosx" }
systemversion "12.0" systemversion "12.0"
filter {} filter {}
symbols "On" symbols "On"

View File

@ -30,6 +30,7 @@
#include "xsk/arc/engine/t7.hpp" #include "xsk/arc/engine/t7.hpp"
#include "xsk/arc/engine/t8.hpp" #include "xsk/arc/engine/t8.hpp"
#include "xsk/arc/engine/t9.hpp" #include "xsk/arc/engine/t9.hpp"
#include "xsk/version.hpp"
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -1017,6 +1018,11 @@ auto print_usage() -> void
std::cin.get(); 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 main(u32 argc, char** argv) -> void
{ {
auto path = fs::path{}; auto path = fs::path{};
@ -1024,6 +1030,8 @@ auto main(u32 argc, char** argv) -> void
auto game = game::_; auto game = game::_;
auto mach = mach::_; auto mach = mach::_;
branding();
if (!parse_flags(argc, argv, mode, game, mach, path)) if (!parse_flags(argc, argv, mode, game, mach, path))
{ {
return print_usage(); return print_usage();