Skip to content

Commit 224cf12

Browse files
committed
Better versioning
1 parent 9714275 commit 224cf12

8 files changed

+129
-26
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ package/*
1717
vs2022/*
1818
vsxmake*/
1919
*.pyc
20+
src/config/*

src/CETVersion.h.in

-4
This file was deleted.

src/Options.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <stdafx.h>
22

3+
#include "config/CETVersion.h"
34
#include "Paths.h"
45
#include "Utils.h"
56
#include "RED4ext/Api/Runtime.hpp"
@@ -177,7 +178,7 @@ Options::Options(Paths& aPaths)
177178

178179
if (GameImage.FileVersion.major != 0)
179180
{
180-
Log::Info("CET version {} [{}]", CET_BUILD_COMMIT, CET_BUILD_BRANCH);
181+
Log::Info("CET version {}", CET_VERSION_FULL);
181182
Log::Info("Game version {}.{}.{}.{}", GameImage.FileVersion.major, GameImage.FileVersion.minor, GameImage.FileVersion.build, GameImage.FileVersion.revision);
182183
Log::Info("Root path: \"{}\"", UTF16ToUTF8(aPaths.GameRoot().native()));
183184
Log::Info("Cyber Engine Tweaks path: \"{}\"", UTF16ToUTF8(aPaths.CETRoot().native()));

src/scripting/Scripting.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
#include "Scripting.h"
44

5+
#include "config/CETVersion.h"
6+
57
#include "FunctionOverride.h"
68
#include "GameOptions.h"
79
#include "Texture.h"
@@ -125,7 +127,7 @@ void Scripting::Initialize()
125127

126128
globals["GetVersion"] = []() -> std::string
127129
{
128-
return CET_BUILD_COMMIT;
130+
return CET_GIT_TAG;
129131
};
130132

131133
globals["GetDisplayResolution"] = [this]() -> std::tuple<float, float>

src/stdafx.h

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@
6767
#include <unordered_map>
6868
#include <vector>
6969

70-
#include "CETVersion.h"
7170
#include "common/Logging.h"
7271
#include "common/FontMaterialDesignIcons.h"
7372
#include "common/ImGuiNotify.h"

src/xmake/CETVersion.h.in

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#pragma once
2+
3+
${define CET_DEBUG_BUILD}
4+
${define CET_GIT_TAG}
5+
${define CET_GIT_TAG_LONG}
6+
${define CET_GIT_BRANCH}
7+
${define CET_GIT_COMMIT}
8+
${define CET_GIT_COMMIT_LONG}
9+
${define CET_GIT_COMMIT_DATE}
10+
11+
${define CET_VERSION_MAJOR}
12+
${define CET_VERSION_MINOR}
13+
${define CET_VERSION_PATCH}
14+
${define CET_VERSION_SIMPLE}
15+
${define CET_VERSION_FULL}
16+
${define CET_VERSION}
17+
18+
${define CET_CURRENT_YEAR}
19+
${define CET_PRODUCT_NAME}
20+
${define CET_GROUP_NAME}
21+
${define CET_FILE_NAME}

src/xmake/Resource.rc.in

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include "Windows.h"
2+
3+
LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL
4+
5+
VS_VERSION_INFO VERSIONINFO
6+
FILEVERSION ${CET_VERSION_MAJOR},${CET_VERSION_MINOR},${CET_VERSION_PATCH},0
7+
PRODUCTVERSION ${CET_VERSION_MAJOR},${CET_VERSION_MINOR},${CET_VERSION_PATCH},0
8+
FILEFLAGSMASK 0x3fL
9+
FILEFLAGS 0x${CET_DEBUG_BUILD}L
10+
FILEOS 0x40004L
11+
FILETYPE 0x2L
12+
FILESUBTYPE 0x0L
13+
BEGIN
14+
BLOCK "StringFileInfo"
15+
BEGIN
16+
BLOCK "040904b0"
17+
BEGIN
18+
VALUE "CompanyName", "${CET_GROUP_NAME}"
19+
VALUE "FileDescription", "${CET_PRODUCT_NAME}"
20+
VALUE "FileVersion", "${CET_VERSION_SIMPLE}"
21+
VALUE "LegalCopyright", "� 2020-${CET_CURRENT_YEAR} ${CET_GROUP_NAME}. All Rights Reserved"
22+
VALUE "OriginalFilename", "${CET_FILE_NAME}"
23+
VALUE "ProductName", "${CET_PRODUCT_NAME}"
24+
VALUE "ProductVersion", "${CET_VERSION_FULL}"
25+
END
26+
END
27+
BLOCK "VarFileInfo"
28+
BEGIN
29+
VALUE "Translation", 0x0409 0x04E2
30+
END
31+
END

xmake.lua

+71-19
Original file line numberDiff line numberDiff line change
@@ -9,37 +9,29 @@ add_rules("c.unity_build")
99
add_cxflags("/bigobj", "/MP", "/EHsc")
1010
add_defines("UNICODE", "_UNICODE", "_CRT_SECURE_NO_WARNINGS")
1111

12-
local vsRuntime = "MD"
13-
1412
if is_mode("debug") then
15-
add_defines("CET_DEBUG")
16-
set_symbols("debug")
1713
set_optimize("none")
1814
set_warnings("all")
1915
set_policy("build.optimization.lto", false)
20-
21-
vsRuntime = vsRuntime.."d"
2216
elseif is_mode("releasedbg") then
23-
add_defines("CET_DEBUG")
24-
set_symbols("debug")
2517
set_optimize("fastest")
2618
set_warnings("all")
2719
set_policy("build.optimization.lto", true)
28-
29-
vsRuntime = vsRuntime.."d"
3020
elseif is_mode("release") then
31-
add_defines("NDEBUG")
32-
set_symbols("debug")
3321
set_strip("all")
3422
set_optimize("fastest")
35-
set_runtimes("MD")
3623
set_warnings("all", "error")
3724
set_policy("build.optimization.lto", true)
3825
end
3926

40-
set_runtimes(vsRuntime);
27+
set_symbols("debug")
28+
set_runtimes(is_mode("release") and "MD" or "MDd");
4129

42-
add_requireconfs("**", { configs = { debug = is_mode("debug"), lto = not is_mode("debug"), shared = false, vs_runtime = vsRuntime } })
30+
add_requireconfs("**", { configs = {
31+
--debug = is_mode("debug"), -- This seems to cause compilation issues recently and probably has little benefit anyway
32+
lto = not is_mode("debug"),
33+
shared = false,
34+
vs_runtime = is_mode("release") and "MD" or "MDd" } })
4335

4436
add_requires("spdlog 1.11.0")
4537
add_requires("nlohmann_json")
@@ -67,14 +59,74 @@ target("cyber_engine_tweaks")
6759
add_defines("WIN32_LEAN_AND_MEAN", "NOMINMAX", "WINVER=0x0601", "SOL_ALL_SAFETIES_ON", "SOL_LUAJIT=1", "SOL_EXCEPTIONS_SAFE_PROPAGATION", "SPDLOG_WCHAR_TO_UTF8_SUPPORT", "SPDLOG_WCHAR_FILENAMES", "SPDLOG_WCHAR_SUPPORT", "IMGUI_USER_CONFIG=\""..imguiUserConfig.."\"") -- WINVER=0x0601 == Windows 7xmake
6860
set_pcxxheader("src/stdafx.h")
6961
set_kind("shared")
70-
set_filename("cyber_engine_tweaks.asi")
71-
add_files("src/**.cpp")
72-
add_headerfiles("src/**.h", "build/CETVersion.h")
62+
63+
set_configdir(path.join("src", "config"))
64+
add_configfiles("src/xmake/**.in")
65+
66+
add_files("src/**.cpp", "src/**.rc")
67+
add_headerfiles("src/**.h")
7368
add_includedirs("src/", "build/")
7469
add_syslinks("User32", "Version", "d3d11", "dxgi")
7570
add_packages("spdlog", "nlohmann_json", "minhook", "hopscotch-map", "imgui", "mem", "sol2", "tiltedcore", "sqlite3", "openrestry-luajit", "xbyak", "stb")
7671
add_deps("RED4ext.SDK")
77-
add_configfiles("src/CETVersion.h.in")
72+
73+
-- Set up basic config variables.
74+
-- Required for us to set up something here first to be able to access and modify "configvars"
75+
-- in `on_load`, there seems to be no way to do this otherwise at the moment.
76+
set_configvar("CET_PRODUCT_NAME", "Cyber Engine Tweaks")
77+
78+
on_load(function(target)
79+
-- Set filename based on project name
80+
target:set("basename", target:name())
81+
target:set("extension", ".asi")
82+
83+
-- Get a list of existing target config variables.
84+
local configVars = target:get("configvar")
85+
86+
-- Set up other basic config variables.
87+
configVars.CET_CURRENT_YEAR = tonumber(os.date("%Y"))
88+
configVars.CET_GROUP_NAME = configVars.CET_PRODUCT_NAME .. " Team"
89+
configVars.CET_FILE_NAME = target:filename();
90+
91+
-- Set up build type.
92+
if is_mode("release") then
93+
configVars.CET_DEBUG_BUILD = 0
94+
else
95+
configVars.CET_DEBUG_BUILD = 1
96+
target:add("defines", "CET_DEBUG")
97+
end
98+
99+
-- Emulate GIT_<XXX> XMake Git builtins so we can parse them ourselves.
100+
-- Unable to use and access builtins unfortunately. This is taken directly from XMake source.
101+
configVars.CET_GIT_TAG = os.iorun("git describe --tags"):gsub("%s", "")
102+
configVars.CET_GIT_TAG_LONG = os.iorun("git describe --tags --long"):gsub("%s", "")
103+
configVars.CET_GIT_BRANCH = os.iorun("git rev-parse --abbrev-ref HEAD"):gsub("%s", "")
104+
configVars.CET_GIT_COMMIT = os.iorun("git rev-parse --short HEAD"):gsub("%s", "")
105+
configVars.CET_GIT_COMMIT_LONG = os.iorun("git rev-parse HEAD"):gsub("%s", "")
106+
configVars.CET_GIT_COMMIT_DATE = os.iorun("git log -1 --date=format:%Y%m%d%H%M%S --format=%ad"):gsub("%s", "")
107+
108+
-- Split tag so we can easily extract version from it.
109+
local splitGitTag = configVars.CET_GIT_TAG:split("%.")
110+
assert(#splitGitTag == 3)
111+
112+
-- Setup version variables.
113+
configVars.CET_VERSION_MAJOR = tonumber(splitGitTag[1]:match("%d+"))
114+
configVars.CET_VERSION_MINOR = tonumber(splitGitTag[2]:match("%d+"))
115+
configVars.CET_VERSION_PATCH = tonumber(splitGitTag[3]:match("%d+"))
116+
configVars.CET_VERSION_SIMPLE = format(
117+
"%d.%d.%d",
118+
configVars.CET_VERSION_MAJOR,
119+
configVars.CET_VERSION_MINOR,
120+
configVars.CET_VERSION_PATCH)
121+
configVars.CET_VERSION_FULL = format(
122+
"%s [%s]",
123+
configVars.CET_GIT_TAG,
124+
configVars.CET_GIT_BRANCH)
125+
configVars.CET_VERSION = configVars.CET_VERSION_FULL
126+
127+
-- Push new list to target.
128+
target:add("configvar", configVars)
129+
end)
78130

79131
on_package(function(target)
80132
import("net.http")

0 commit comments

Comments
 (0)