Skip to content

Commit

Permalink
maint(build): new version system (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
xensik committed Jun 13, 2023
1 parent 34a67d9 commit 64c2f1e
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ user*.bat
# VScode
.vscode/

# Output folders
renamed/
parsed/
compiled/
Expand All @@ -157,3 +158,6 @@ assembled/
disassembled/

data/*

# Version file
include/xsk/version.hpp
4 changes: 4 additions & 0 deletions deps/zlib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
65 changes: 62 additions & 3 deletions premake5.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
-------------------------------------------------
-- DEPENDENCIES
-------------------------------------------------
dependencies = { base = path.getrelative(os.getcwd(), path.getabsolute("deps")) }

function dependencies.load()
Expand All @@ -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"
Expand Down Expand Up @@ -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*"
Expand All @@ -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"
Expand Down
8 changes: 8 additions & 0 deletions src/tool/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -1017,13 +1018,20 @@ 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{};
auto mode = mode::_;
auto game = game::_;
auto mach = mach::_;

branding();

if (!parse_flags(argc, argv, mode, game, mach, path))
{
return print_usage();
Expand Down

0 comments on commit 64c2f1e

Please sign in to comment.