From 0f919391c2ad24f64d8aed6a87d58eab63b6c584 Mon Sep 17 00:00:00 2001 From: Jarod42 Date: Tue, 31 Dec 2024 10:33:36 +0100 Subject: [PATCH] Use git to retrieve version instead of manually change `PREMAKE_VERSION`. --- .gitattributes | 1 + git-tags.txt | 1 + premake5.lua | 25 +++++++++++++++++++++++++ src/host/premake.h | 5 ++++- 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 git-tags.txt diff --git a/.gitattributes b/.gitattributes index b04e452d7..746e24715 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1,2 @@ Bootstrap.bat text eol=crlf +git-tags.txt export-subst diff --git a/git-tags.txt b/git-tags.txt new file mode 100644 index 000000000..d01155d63 --- /dev/null +++ b/git-tags.txt @@ -0,0 +1 @@ +$Format:%(describe:tags=true)$ \ No newline at end of file diff --git a/premake5.lua b/premake5.lua index b70f9b0b7..041c97865 100644 --- a/premake5.lua +++ b/premake5.lua @@ -192,6 +192,27 @@ -- symbols "On" -- + local function retrieve_git_tag() + local git_tag, errorCode = os.outputof("git describe --tag --exact-match") + if errorCode == 0 then + return git_tag + else + return nil + end + end + + if premake.action.isConfigurable() then + local git_tag = retrieve_git_tag() or io.readfile("git-tags.txt") + + if git_tag == "$Format:%(describe:tags=true)$" then + git_tag = nil + end + if git_tag and git_tag:startswith('v') then -- tags use v5.x.x-xxx format whereas premake uses 5.x.x-xxx + git_tag = git_tag:strsub(2) + end + print("Current git tag: ", git_tag) + end + solution "Premake5" configurations { "Release", "Debug" } location ( _OPTIONS["to"] ) @@ -278,6 +299,10 @@ "binmodules/**.*" } + if git_tag then + defines { 'PREMAKE_VERSION="' .. git_tag .. '"'} + end + filter { "options:lua-src=contrib" } includedirs { "contrib/lua/src", "contrib/luashim" } links { "lua-lib" } diff --git a/src/host/premake.h b/src/host/premake.h index 62a9fbfa8..21170331f 100644 --- a/src/host/premake.h +++ b/src/host/premake.h @@ -18,7 +18,10 @@ #include #include -#define PREMAKE_VERSION "5.0.0-dev" +#ifndef PREMAKE_VERSION +# define PREMAKE_VERSION "5.0.0-dev" +#endif + #define PREMAKE_COPYRIGHT "Copyright (C) 2002-2024 Jess Perkins and the Premake Project" #define PREMAKE_PROJECT_URL "https://github.com/premake/premake-core/wiki"