Introducing git revision in source code

Git revision is generating on build time (not on configure time). In case of uncommited changes this revision will be marked as "dirty". If cmake cannot retrieve revision from git history (i.e. from packaged source code), cmake will attempt to read "git-hash.txt" from `PROJECT_SOURCE_DIR` (it will be generated on build time; after implementing packaging workflow it can be reworked).
Reworked main screen and console output to display proper version.
Version project now is 1.5.0 as previous PATCH value (500) was intended to be D3_RELEASE_BUILD_NO, autogenerated on compile time. As we switched to GIT_HASH, D3_RELEASE_BUILD_NO now useless.
This commit is contained in:
Azamat H. Hackimov 2024-04-28 21:42:02 +03:00
parent f001d82b80
commit 1926a77f19
11 changed files with 93 additions and 59 deletions

6
.gitignore vendored
View File

@ -404,5 +404,7 @@ FodyWeavers.xsd
cmake-build-* cmake-build-*
# Linux stuff # Linux stuff
build build[s]
builds
# Ignore autogenerated git-hash.txt file, generated for packaging purposes
git-hash.txt

View File

@ -7,7 +7,7 @@ endif()
project(Descent3 project(Descent3
LANGUAGES C CXX LANGUAGES C CXX
VERSION 1.5.500 VERSION 1.5.0
) )
option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF) option(FORCE_COLORED_OUTPUT "Always produce ANSI-colored compiler warnings/errors (GCC/Clang only; esp. useful with ninja)." OFF)
@ -42,6 +42,23 @@ if(BUILD_TESTING)
add_subdirectory(tests) add_subdirectory(tests)
endif() endif()
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/Descent3/d3_version.h ALL
COMMAND ${CMAKE_COMMAND}
-D SOURCE_DIR=${PROJECT_SOURCE_DIR}
-D TARGET_DIR=${PROJECT_BINARY_DIR}
-D PROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR}
-D PROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR}
-D PROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH}
-P ${PROJECT_SOURCE_DIR}/cmake/CheckGit.cmake
WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
)
# rebuild version.hpp every time
add_custom_target(get_git_hash ALL
DEPENDS ${PROJECT_BINARY_DIR}/Descent3/d3_version.h
)
if(UNIX) if(UNIX)
set(D3_GAMEDIR "~/Descent3/") set(D3_GAMEDIR "~/Descent3/")

View File

@ -16,7 +16,6 @@ set(HEADERS
BriefingParse.h BriefingParse.h
bsp.h bsp.h
buddymenu.h buddymenu.h
buildno.h
cinematics.h cinematics.h
cockpit.h cockpit.h
config.h config.h
@ -301,6 +300,8 @@ target_link_libraries(Descent3
fix grtext manage mem misc model module movie stream_audio fix grtext manage mem misc model module movie stream_audio
music networking physics renderer rtperformance sndlib ui unzip vecmat md5 music networking physics renderer rtperformance sndlib ui unzip vecmat md5
${PLATFORM_LIBS}) ${PLATFORM_LIBS})
target_include_directories(Descent3 PRIVATE ${PROJECT_BINARY_DIR}/lib)
add_dependencies(Descent3 get_git_hash)
if(UNIX) if(UNIX)
add_dependencies(Descent3 HogLinuxFull) add_dependencies(Descent3 HogLinuxFull)

View File

@ -1,21 +0,0 @@
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Descent 3 release build number definition. This file is generated by code, so don't edit it!!!!
#define D3_RELEASE_BUILD_NO 604

View File

@ -539,14 +539,14 @@ int main(int argc, char *argv[]) {
GatherArgs(argv); GatherArgs(argv);
snprintf(game_version_buffer, sizeof(game_version_buffer), "%d.%d.%d%s%s", D3_MAJORVER, D3_MINORVER, D3_BUILD, snprintf(game_version_buffer, sizeof(game_version_buffer), "%d.%d.%d%s %s", D3_MAJORVER, D3_MINORVER, D3_BUILD,
LOKI_VERSION, GAME_VERS_EXT); D3_GIT_HASH, GAME_VERS_EXT);
loki_setgamename("descent3" GAME_NAME_EXT, game_version_buffer, "Descent 3"); loki_setgamename("descent3" GAME_NAME_EXT, game_version_buffer, "Descent 3");
snprintf(game_version_buffer, sizeof(game_version_buffer), snprintf(game_version_buffer, sizeof(game_version_buffer),
"\n\n" "\n\n"
"Descent 3 %s %s v%d.%d.%d%s\n" "Descent 3 %s %s v%d.%d.%d %s\n"
"Copyright (C) 1999 Outrage Entertainment, Inc.\n", "Copyright (C) 1999 Outrage Entertainment, Inc.\n",
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
@ -562,7 +562,7 @@ int main(int argc, char *argv[]) {
#else #else
"Client", "Client",
#endif #endif
D3_MAJORVER, D3_MINORVER, D3_BUILD, LOKI_VERSION); D3_MAJORVER, D3_MINORVER, D3_BUILD, D3_GIT_HASH);
game_version += 2; // skip those first newlines for loki_initialize. game_version += 2; // skip those first newlines for loki_initialize.

View File

@ -438,31 +438,19 @@ void mmInterface::CopyrightText() {
} else if (Program_version.version_type == RELEASE_VERSION) { } else if (Program_version.version_type == RELEASE_VERSION) {
strcat(type, "Ver"); strcat(type, "Ver");
} }
#ifndef RELEASE
int x = Max_window_w - 128, y = Max_window_h - 29; // was -128 and -16
#else
int x = Max_window_w - 164, y = Max_window_h - 29; // was -128 and -16 int x = Max_window_w - 164, y = Max_window_h - 29; // was -128 and -16
#endif
// attempt to print text nicely. // attempt to print text nicely.
grtext_SetFont(BRIEFING_FONT); grtext_SetFont(BRIEFING_FONT);
grtext_SetAlpha(192); grtext_SetAlpha(192);
grtext_SetColor(GR_RGB(255, 32, 32)); grtext_SetColor(GR_RGB(255, 32, 32));
#if ((!defined(RELEASE)) || defined(DEMO))
grtext_Printf(x, y, Program_version.build ? "%s %d.%d.%d" : "%s v%d.%d", type, Program_version.major,
Program_version.minor, Program_version.build);
#else
grtext_Printf(x, y, Program_version.build ? "%s %d.%d.%d Build %d" : "%s v%d.%d", type, Program_version.major,
Program_version.minor, Program_version.build, D3_RELEASE_BUILD_NO);
#endif
// grtext_CenteredPrintf(0, Max_window_h-16, "(c) 1998 Outrage Entertainment, Inc.");
grtext_SetFlags(GRTEXTFLAG_SATURATE); grtext_Printf(x, y, "%s %d.%d.%d %s", type, Program_version.major,
Program_version.minor, Program_version.build, D3_GIT_HASH);
for (i = 0; i < 1; i++) { grtext_SetFlags(GRTEXTFLAG_SHADOW);
grtext_Printf(x, y, Program_version.build ? "%s %d.%d.%d" : "%s v%d.%d", type, Program_version.major, grtext_Printf(x, y, "%s %d.%d.%d %s", type, Program_version.major,
Program_version.minor, Program_version.build); Program_version.minor, Program_version.build, D3_GIT_HASH);
// grtext_CenteredPrintf(0, Max_window_h-16, "(c) 1998 Outrage Entertainment, Inc.");
}
grtext_Flush(); grtext_Flush();
} }

View File

@ -156,14 +156,9 @@
#ifndef PROGRAM_H #ifndef PROGRAM_H
#define PROGRAM_H #define PROGRAM_H
#include "d3_version.h"
#include "pstypes.h" #include "pstypes.h"
#include "buildno.h"
#define D3_MAJORVER 0x1 // DESCENT 3 VERSION NUMBER
#define D3_MINORVER 0x5
#define D3_BUILD 0x0
#define DEVELOPMENT_VERSION 0x1 // without editor: with debug, no beta #define DEVELOPMENT_VERSION 0x1 // without editor: with debug, no beta
#define RELEASE_VERSION 0x2 // final release candidate: no debug, beta, editor #define RELEASE_VERSION 0x2 // final release candidate: no debug, beta, editor

26
cmake/CheckGit.cmake Normal file
View File

@ -0,0 +1,26 @@
# In case Git is not available, default is empty string
set(GIT_HASH "")
find_package(Git QUIET)
if(GIT_FOUND)
execute_process(
COMMAND ${GIT_EXECUTABLE} describe --always --dirty
OUTPUT_VARIABLE D3_GIT_HASH
OUTPUT_STRIP_TRAILING_WHITESPACE
ERROR_QUIET
)
file(WRITE ${SOURCE_DIR}/git-hash.txt ${D3_GIT_HASH})
else()
# Try to read pregenerated file with commit hash on it (archive version of repository)
if(EXISTS ${SOURCE_DIR}/git-hash.txt)
file(READ ${SOURCE_DIR}/git-hash.txt D3_GIT_HASH)
endif()
endif()
message(STATUS "Git hash is ${D3_GIT_HASH}")
configure_file(
${SOURCE_DIR}/lib/d3_version.h.in
${TARGET_DIR}/lib/d3_version.h
@ONLY
)

27
lib/d3_version.h.in Normal file
View File

@ -0,0 +1,27 @@
/*
* Descent 3
* Copyright (C) 2024 Descent Developers
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
/* This file is autogenerated from lib/d3_version.h.in */
#define D3_MAJORVER @PROJECT_VERSION_MAJOR@
#define D3_MINORVER @PROJECT_VERSION_MINOR@
#define D3_BUILD @PROJECT_VERSION_PATCH@
#define D3_GIT_HASH "@D3_GIT_HASH@"

View File

@ -9,3 +9,5 @@ set(CPPS
wintask.cpp) wintask.cpp)
add_library(win32 STATIC ${HEADERS} ${CPPS}) add_library(win32 STATIC ${HEADERS} ${CPPS})
add_dependencies(win32 get_git_hash)
target_include_directories(win32 PRIVATE ${PROJECT_BINARY_DIR}/lib)

View File

@ -188,6 +188,7 @@
* $NoKeywords: $ * $NoKeywords: $
*/ */
#include "d3_version.h"
#include "Debug.h" #include "Debug.h"
#include "mono.h" #include "mono.h"
@ -1183,10 +1184,6 @@ const int NumCodeBytes = 16; // Number of code bytes to record.
const int MaxStackDump = 2048; // Maximum number of DWORDS in stack dumps. const int MaxStackDump = 2048; // Maximum number of DWORDS in stack dumps.
const int StackColumns = 8; // Number of columns in stack dump. const int StackColumns = 8; // Number of columns in stack dump.
#if (defined(RELEASE) && (!defined(DEMO)) && (!defined(GAMEGAUGE)))
#include "buildno.h"
#endif
extern int no_debug_dialog; extern int no_debug_dialog;
int __cdecl RecordExceptionInfo(PEXCEPTION_POINTERS data, const char *Message) { int __cdecl RecordExceptionInfo(PEXCEPTION_POINTERS data, const char *Message) {
@ -1239,7 +1236,7 @@ int __cdecl RecordExceptionInfo(PEXCEPTION_POINTERS data, const char *Message) {
WriteFile(LogFile, callstack, lstrlen(callstack), &NumBytes, 0); WriteFile(LogFile, callstack, lstrlen(callstack), &NumBytes, 0);
#if (defined(RELEASE) && (!defined(DEMO)) && (!defined(GAMEGAUGE))) #if (defined(RELEASE) && (!defined(DEMO)) && (!defined(GAMEGAUGE)))
wsprintf(callstack, "Descent 3 Release build %d\r\n", D3_RELEASE_BUILD_NO); wsprintf(callstack, "Descent 3 Release build %s\r\n", D3_GIT_HASH);
WriteFile(LogFile, callstack, lstrlen(callstack), &NumBytes, 0); WriteFile(LogFile, callstack, lstrlen(callstack), &NumBytes, 0);
#endif #endif
RecordSystemInformation(LogFile); RecordSystemInformation(LogFile);