Skip to content

Commit e7a9394

Browse files
committed
Use git to retrieve version instead of manually change PREMAKE_VERSION.
1 parent 8cd7ef9 commit e7a9394

File tree

4 files changed

+31
-1
lines changed

4 files changed

+31
-1
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
Bootstrap.bat text eol=crlf
2+
git-tags.txt export-subst

git-tags.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$Format:%(describe:tags=true)$

premake5.lua

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,27 @@
192192
-- symbols "On"
193193
--
194194

195+
local function retrieve_git_tag()
196+
local git_tag, errorCode = os.outputof("git describe --tag --exact-match")
197+
if errorCode == 0 then
198+
return git_tag
199+
else
200+
return nil
201+
end
202+
end
203+
204+
if premake.action.isConfigurable() then
205+
local git_tag = retrieve_git_tag() or io.readfile("git-tags.txt")
206+
207+
if git_tag == "$Format:%(describe:tags=true)$" then
208+
git_tag = nil
209+
end
210+
if git_tag and git_tag:startswith('v') then -- tags use v5.x.x-xxx format whereas premake uses 5.x.x-xxx
211+
git_tag = git_tag:sub(2)
212+
end
213+
print("Current git tag: ", git_tag)
214+
end
215+
195216
solution "Premake5"
196217
configurations { "Release", "Debug" }
197218
location ( _OPTIONS["to"] )
@@ -278,6 +299,10 @@
278299
"binmodules/**.*"
279300
}
280301

302+
if git_tag then
303+
defines { 'PREMAKE_VERSION="' .. git_tag .. '"'}
304+
end
305+
281306
filter { "options:lua-src=contrib" }
282307
includedirs { "contrib/lua/src", "contrib/luashim" }
283308
links { "lua-lib" }

src/host/premake.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
#include <stdint.h>
1919
#include <stdlib.h>
2020

21-
#define PREMAKE_VERSION "5.0.0-dev"
21+
#ifndef PREMAKE_VERSION
22+
# define PREMAKE_VERSION "5.0.0-dev"
23+
#endif
24+
2225
#define PREMAKE_COPYRIGHT "Copyright (C) 2002-2025 Jess Perkins and the Premake Project"
2326
#define PREMAKE_PROJECT_URL "https://github.com/premake/premake-core/wiki"
2427

0 commit comments

Comments
 (0)