Skip to content
This repository was archived by the owner on Jun 27, 2025. It is now read-only.

Commit 146806f

Browse files
committed
add version information to DLL
1 parent 27c44b8 commit 146806f

File tree

5 files changed

+281
-3
lines changed

5 files changed

+281
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ jobs:
3838
vs-prerelease: true
3939

4040
- name: Generate project files (premake)
41-
run: premake/premake5 vs2022
41+
run: premake/premake5 vs2022 --ci-build
4242

4343
- name: Compile
4444
id: compile

premake/loader.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ pchheader "pch.hpp"
1010
pchsource "./src/loader/pch.cpp"
1111
forceincludes {"pch.hpp"}
1212

13-
files {"./src/loader/**.hpp", "./src/loader/**.cpp", "./src/loader/**.asm", "./src/loader/**.def"}
14-
includedirs {"./src/loader"}
13+
files {"./src/loader/**.hpp", "./src/loader/**.cpp", "./src/loader/**.asm", "./src/loader/**.def", "./src/loader/resource/**.*"}
14+
includedirs {"./src/loader", "%{prj.location}/src"}
15+
16+
prebuildcommands {"pushd %{_MAIN_SCRIPT_DIR}", "premake\\premake5 generate-buildinfo", "popd"}
1517

1618
links {"main"}

premake/premake5.lua

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,131 @@ end
3636

3737
dependencies.load()
3838

39+
newoption {
40+
trigger = "ci-build",
41+
description = "Enable CI builds."
42+
}
43+
44+
newaction {
45+
trigger = "generate-buildinfo",
46+
description = "Sets up build information file like version.h.",
47+
onWorkspace = function(wks)
48+
-- get old version number from version.hpp if any
49+
local oldVersion = "(none)"
50+
local oldVersionHeader = io.open(wks.location .. "/src/version.h", "r")
51+
if oldVersionHeader ~= nil then
52+
local oldVersionHeaderContent = assert(oldVersionHeader:read('*l'))
53+
while oldVersionHeaderContent do
54+
m = string.match(oldVersionHeaderContent, "#define GIT_DESCRIBE (.+)%s*$")
55+
if m ~= nil then
56+
oldVersion = m
57+
end
58+
59+
oldVersionHeaderContent = oldVersionHeader:read('*l')
60+
end
61+
end
62+
63+
-- get current version via git
64+
local proc = assert(io.popen(gitVersioningCommand, "r"))
65+
local gitDescribeOutput = assert(proc:read('*a')):gsub("%s+", "")
66+
proc:close()
67+
68+
-- generate version.hpp with a revision number if not equal
69+
gitDescribeOutputQuoted = cstrquote(gitDescribeOutput)
70+
if oldVersion ~= gitDescribeOutputQuoted then
71+
-- get current git hash and write to version.txt (used by the preliminary updater)
72+
local proc = assert(io.popen("git rev-parse HEAD", "r"))
73+
local gitCommitHash = assert(proc:read('*a')):gsub("%s+", "")
74+
proc:close()
75+
76+
-- get whether this is a clean revision (no uncommitted changes)
77+
proc = assert(io.popen("git status --porcelain", "r"))
78+
local revDirty = (assert(proc:read('*a')) ~= "")
79+
if revDirty then revDirty = 1 else revDirty = 0 end
80+
proc:close()
81+
82+
-- get current tag name
83+
proc = assert(io.popen("git describe --tags --abbrev=0"))
84+
local tagName = proc:read('*l')
85+
86+
-- patch tag name to be the next one
87+
if tagName ~= nil and tagName ~= '' and tagName:find("^v%d+$") then
88+
tagName = string.format("v%u", tagName:sub(tagName:find("%d+$")) + 1)
89+
print(tagName)
90+
end
91+
92+
-- get current branch name
93+
proc = assert(io.popen("git branch --show-current"))
94+
local branchName = proc:read('*l')
95+
96+
-- branch for ci
97+
if branchName == nil or branchName == '' then
98+
proc = assert(io.popen("git show -s --pretty=%d HEAD"))
99+
local branchInfo = proc:read('*l')
100+
m = branchInfo:match(".+,.+, ([^)]+)")
101+
if m ~= nil then
102+
branchName = m
103+
end
104+
end
105+
106+
if branchName == nil then
107+
branchName = "master"
108+
end
109+
110+
print("Detected branch: " .. branchName)
111+
112+
-- get revision number via git
113+
local proc = assert(io.popen("git rev-list --count HEAD", "r"))
114+
local revNumber = assert(proc:read('*a')):gsub("%s+", "")
115+
116+
print ("Update " .. oldVersion .. " -> " .. gitDescribeOutputQuoted)
117+
118+
-- write to version.txt for preliminary updater
119+
-- NOTE - remove this once we have a proper updater and proper release versioning
120+
local versionFile = assert(io.open(wks.location .. "/version.txt", "w"))
121+
versionFile:write(gitCommitHash)
122+
versionFile:close()
123+
124+
-- write version header
125+
local versionHeader = assert(io.open(wks.location .. "/src/version.h", "w"))
126+
versionHeader:write("/*\n")
127+
versionHeader:write(" * Automatically generated by premake5.\n")
128+
versionHeader:write(" * Do not touch!\n")
129+
versionHeader:write(" */\n")
130+
versionHeader:write("\n")
131+
versionHeader:write("#define GIT_DESCRIBE " .. gitDescribeOutputQuoted .. "\n")
132+
versionHeader:write("#define GIT_DIRTY " .. revDirty .. "\n")
133+
versionHeader:write("#define GIT_HASH " .. cstrquote(gitCommitHash) .. "\n")
134+
versionHeader:write("#define GIT_TAG " .. cstrquote(tagName) .. "\n")
135+
versionHeader:write("#define GIT_BRANCH " .. cstrquote(branchName) .. "\n")
136+
versionHeader:write("\n")
137+
versionHeader:write("// Version transformed for RC files\n")
138+
versionHeader:write("#define VERSION_PRODUCT_RC " .. table.concat(vertonumarr(tagName, revNumber, 3), ",") .. "\n")
139+
versionHeader:write("#define VERSION_PRODUCT " .. cstrquote(table.concat(vertonumarr(tagName, revNumber, 3), ".")) .. "\n")
140+
versionHeader:write("#define VERSION_FILE_RC " .. table.concat(vertonumarr(tagName, revNumber, 4), ",") .. "\n")
141+
versionHeader:write("#define VERSION_FILE " .. cstrquote(table.concat(vertonumarr(tagName, revNumber, 4), ".")) .. "\n")
142+
versionHeader:write("\n")
143+
versionHeader:write("// Alias definitions\n")
144+
versionHeader:write("#define VERSION GIT_DESCRIBE\n")
145+
versionHeader:write("#define SHORTVERSION VERSION_PRODUCT\n")
146+
versionHeader:close()
147+
local versionHeader = assert(io.open(wks.location .. "/src/version.hpp", "w"))
148+
versionHeader:write("/*\n")
149+
versionHeader:write(" * Automatically generated by premake5.\n")
150+
versionHeader:write(" * Do not touch!\n")
151+
versionHeader:write(" *\n")
152+
versionHeader:write(" * This file exists for reasons of complying with our coding standards.\n")
153+
versionHeader:write(" *\n")
154+
versionHeader:write(" * The Resource Compiler will ignore any content from C++ header files if they're not from STDInclude.hpp.\n")
155+
versionHeader:write(" * That's the reason why we now place all version info in version.h instead.\n")
156+
versionHeader:write(" */\n")
157+
versionHeader:write("\n")
158+
versionHeader:write("#include \"version.h\"\n")
159+
versionHeader:close()
160+
end
161+
end
162+
}
163+
39164
workspace "Fuck_off_EA_App"
40165
startproject "Fuck_off_EA_App"
41166
location "./build"
@@ -76,6 +201,10 @@ defines {"_WINDOWS", "WIN32", "NOMINMAX"}
76201
buildoptions {"/utf-8"}
77202
linkoptions {}
78203

204+
if _OPTIONS["ci-build"] then
205+
defines {"CI_BUILD"}
206+
end
207+
79208
filter "configurations:Release"
80209
optimize "Speed"
81210
buildoptions {}

premake/utils.lua

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
os.chdir(_MAIN_SCRIPT_DIR)
22

3+
gitVersioningCommand = "git describe --tags --dirty --always"
4+
gitCurrentBranchCommand = "git symbolic-ref -q --short HEAD"
5+
36
require("vstudio")
47
premake.api.register {
58
name = "solutionitems",
@@ -108,3 +111,52 @@ end)
108111
-- end
109112
-- return base(cfg)
110113
--end)
114+
115+
-- Quote the given string input as a C string
116+
function cstrquote(value)
117+
if value == nil then
118+
return "\"\""
119+
end
120+
result = value:gsub("\\", "\\\\")
121+
result = result:gsub("\"", "\\\"")
122+
result = result:gsub("\n", "\\n")
123+
result = result:gsub("\t", "\\t")
124+
result = result:gsub("\r", "\\r")
125+
result = result:gsub("\a", "\\a")
126+
result = result:gsub("\b", "\\b")
127+
result = "\"" .. result .. "\""
128+
return result
129+
end
130+
131+
-- Converts tags in "vX.X.X" format and given revision number Y to an array of numbers {X,X,X,Y}.
132+
-- In the case where the format does not work fall back to padding with zeroes and just ending with the revision number.
133+
-- partscount can be either 3 or 4.
134+
function vertonumarr(value, vernumber, partscount)
135+
vernum = {}
136+
for num in string.gmatch(value or "", "%d+") do
137+
if #vernum < 3 then
138+
table.insert(vernum, tonumber(num))
139+
end
140+
end
141+
while #vernum < 3 do
142+
table.insert(vernum, 0)
143+
end
144+
if #vernum < partscount then
145+
table.insert(vernum, tonumber(vernumber))
146+
end
147+
return vernum
148+
end
149+
150+
function io.writefile(filename, content)
151+
-- do not write if contents haven't changed
152+
if content == io.readfile(filename) then
153+
return true
154+
end
155+
156+
local file = io.open(filename, "w+b")
157+
if file then
158+
file:write(content)
159+
file:close()
160+
return true
161+
end
162+
end

src/loader/resource/resource.rc

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
// Microsoft Visual C++ generated resource script.
2+
//
3+
#pragma code_page(65001)
4+
5+
#include "version.hpp"
6+
7+
#define APSTUDIO_READONLY_SYMBOLS
8+
/////////////////////////////////////////////////////////////////////////////
9+
//
10+
// Generated from the TEXTINCLUDE 2 resource.
11+
//
12+
#include "windows.h"
13+
14+
/////////////////////////////////////////////////////////////////////////////
15+
#undef APSTUDIO_READONLY_SYMBOLS
16+
17+
/////////////////////////////////////////////////////////////////////////////
18+
// English (United States) resources
19+
20+
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
21+
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
22+
23+
#ifdef APSTUDIO_INVOKED
24+
/////////////////////////////////////////////////////////////////////////////
25+
//
26+
// TEXTINCLUDE
27+
//
28+
29+
1 TEXTINCLUDE
30+
BEGIN
31+
"#include ""windows.h""\r\n"
32+
"\0"
33+
END
34+
35+
2 TEXTINCLUDE
36+
BEGIN
37+
"\r\n"
38+
"\0"
39+
END
40+
41+
#endif // APSTUDIO_INVOKED
42+
43+
/////////////////////////////////////////////////////////////////////////////
44+
//
45+
// Version
46+
//
47+
48+
VS_VERSION_INFO VERSIONINFO
49+
FILEVERSION VERSION_FILE_RC
50+
PRODUCTVERSION VERSION_PRODUCT_RC
51+
FILEFLAGSMASK 0x3fL
52+
#ifdef _DEBUG
53+
FILEFLAGS 0x1L
54+
#else
55+
FILEFLAGS 0x0L
56+
#endif
57+
FILEOS 0x40004L
58+
FILETYPE VFT_DLL
59+
FILESUBTYPE 0x0L
60+
BEGIN
61+
BLOCK "StringFileInfo"
62+
BEGIN
63+
BLOCK "040904b0"
64+
BEGIN
65+
VALUE "CompanyName", "p0358"
66+
#if defined(_DEBUG)
67+
VALUE "FileDescription", """Fuck off EA App"" patch (DEBUG)"
68+
#elif !defined(CI_BUILD)
69+
VALUE "FileDescription", """Fuck off EA App"" patch [DEV] (" GIT_DESCRIBE ")"
70+
#else
71+
VALUE "FileDescription", """Fuck off EA App"" patch"
72+
#endif
73+
74+
#if defined(CI_BUILD)
75+
VALUE "FileVersion", VERSION_FILE
76+
#else
77+
VALUE "FileVersion", GIT_DESCRIBE
78+
#endif
79+
VALUE "InternalName", """Fuck off EA App"" patch"
80+
VALUE "LegalCopyright", "https://github.com/p0358/Fuck_off_EA_App/blob/master/LICENSE"
81+
VALUE "Licence", "LGPLv3"
82+
VALUE "Info", "https://github.com/p0358/Fuck_off_EA_App"
83+
VALUE "OriginalFilename", "version.dll"
84+
VALUE "ProductName", """Fuck off EA App"" patch"
85+
VALUE "ProductVersion", VERSION_PRODUCT
86+
END
87+
END
88+
BLOCK "VarFileInfo"
89+
BEGIN
90+
VALUE "Translation", 0x409, 1200
91+
END
92+
END
93+
94+
#endif // English (United States) resources
95+
/////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)