Skip to content

Commit 78f113f

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

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-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+
src/host/premake_archive_version.h export-subst

.github/workflows/ci-workflow.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
steps:
1616
- name: Checkout
1717
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
1820
- name: Install booststrap's dependencies
1921
run: |
2022
sudo apt-get update
@@ -46,6 +48,8 @@ jobs:
4648
steps:
4749
- name: Checkout
4850
uses: actions/checkout@v4
51+
with:
52+
fetch-depth: 0
4953
- name: Build
5054
run: PLATFORM=${{ matrix.platform }} CONFIG=${{ matrix.config }} ./Bootstrap.sh
5155
- name: Test
@@ -69,6 +73,8 @@ jobs:
6973
steps:
7074
- name: Checkout
7175
uses: actions/checkout@v4
76+
with:
77+
fetch-depth: 0
7278
- name: Build
7379
shell: cmd
7480
env:
@@ -107,6 +113,8 @@ jobs:
107113
steps:
108114
- name: Checkout
109115
uses: actions/checkout@v4
116+
with:
117+
fetch-depth: 0
110118
- name: 'Setup MSYS2'
111119
uses: msys2/setup-msys2@v2
112120
with:
@@ -146,6 +154,8 @@ jobs:
146154
steps:
147155
- name: Checkout
148156
uses: actions/checkout@v4
157+
with:
158+
fetch-depth: 0
149159
- uses: tritao/[email protected]
150160
with:
151161
version: '3.9.2'
@@ -175,6 +185,8 @@ jobs:
175185
steps:
176186
- name: Checkout
177187
uses: actions/checkout@v4
188+
with:
189+
fetch-depth: 0
178190
- name: Start FreeBSD VM
179191
uses: vmactions/freebsd-vm@v1
180192
with:
@@ -214,6 +226,8 @@ jobs:
214226
steps:
215227
- name: Checkout
216228
uses: actions/checkout@v4
229+
with:
230+
fetch-depth: 0
217231
- name: Start OpenBSD VM
218232
uses: vmactions/openbsd-vm@v1
219233
with:
@@ -253,6 +267,8 @@ jobs:
253267
steps:
254268
- name: Checkout
255269
uses: actions/checkout@v4
270+
with:
271+
fetch-depth: 0
256272
- name: Start NetBSD VM
257273
uses: vmactions/netbsd-vm@v1
258274
with:
@@ -284,6 +300,8 @@ jobs:
284300
steps:
285301
- name: Checkout
286302
uses: actions/checkout@v4
303+
with:
304+
fetch-depth: 0
287305
- name: Start DragonflyBSD VM
288306
uses: vmactions/dragonflybsd-vm@v1
289307
with:
@@ -315,6 +333,8 @@ jobs:
315333
steps:
316334
- name: Checkout
317335
uses: actions/checkout@v4
336+
with:
337+
fetch-depth: 0
318338
- name: Start Solaris VM
319339
uses: vmactions/solaris-vm@v1
320340
with:

premake5.lua

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

195+
local function autoversion_h()
196+
local git_tag, errorCode = os.outputof("git describe --tag --always")
197+
if errorCode == 0 then
198+
print("git description: ", git_tag)
199+
local content = io.readfile("src/host/premake_git_version.h.in")
200+
content = content:gsub("${GIT_DESC}", git_tag)
201+
202+
local locationDir = _OPTIONS["to"]
203+
os.mkdir(locationDir)
204+
local f, err = os.writefile_ifnotequal(content, path.join(locationDir, "premake_git_version.h"))
205+
206+
if (f == 0) then -- file not modified
207+
elseif (f < 0) then
208+
error(err, 0)
209+
return false
210+
elseif (f > 0) then
211+
print("Generated premake_git_version.h...")
212+
end
213+
214+
return true
215+
else
216+
print("`git describe --tag` failed with error code", errorCode, git_tag)
217+
return false
218+
end
219+
end
220+
221+
if premake.action.isConfigurable() then
222+
autoversion_h()
223+
end
224+
225+
gitintegration "Always"
226+
195227
solution "Premake5"
196228
configurations { "Release", "Debug" }
197229
location ( _OPTIONS["to"] )
@@ -269,6 +301,7 @@
269301
{
270302
"*.txt", "**.lua",
271303
"src/**.h", "src/**.c",
304+
"src/**.in",
272305
"modules/**"
273306
}
274307

@@ -278,6 +311,8 @@
278311
"binmodules/**.*"
279312
}
280313

314+
includedirs { _OPTIONS["to"] } -- for generated file premake_git_version.h
315+
281316
filter { "options:lua-src=contrib" }
282317
includedirs { "contrib/lua/src", "contrib/luashim" }
283318
links { "lua-lib" }

src/host/premake.h

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

21-
#define PREMAKE_VERSION "5.0.0-dev"
21+
// #define PREMAKE_VERSION "5.x.x-xxxx"
22+
#ifdef __has_include
23+
# if __has_include("premake_git_version.h")
24+
# include "premake_git_version.h"
25+
# else
26+
# include "premake_archive_version.h"
27+
# endif
28+
#else
29+
# define PREMAKE_VERSION "Unknown"
30+
#endif
31+
2232
#define PREMAKE_COPYRIGHT "Copyright (C) 2002-2025 Jess Perkins and the Premake Project"
2333
#define PREMAKE_PROJECT_URL "https://github.com/premake/premake-core/wiki"
2434

src/host/premake_archive_version.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// File changed by git archive
2+
3+
#define PREMAKE_VERSION "$Format:%(describe)$"

src/host/premake_git_version.h.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// premake_git_version.h auto-generated by git hook thanks to gitintegration
2+
// Don't modify manually premake_git_version.h, but premake_git_version.h.in instead
3+
4+
#define PREMAKE_VERSION "${GIT_DESC}"

0 commit comments

Comments
 (0)