Merge branch 'master' of https://git.do.srb2.org/KartKrew/Kart into rulesify

This commit is contained in:
toaster 2022-12-27 11:36:03 +00:00
commit 63f75fcba1
7 changed files with 95 additions and 58 deletions

View file

@ -172,22 +172,25 @@ add_subdirectory(src)
add_subdirectory(assets) add_subdirectory(assets)
## config.h generation
set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary") set(GIT_EXECUTABLE "git" CACHE FILEPATH "Path to git binary")
include(GitUtilities) include(GitUtilities)
git_latest_commit(SRB2_COMP_COMMIT "${CMAKE_SOURCE_DIR}")
git_current_branch(SRB2_GIT_BRANCH "${CMAKE_SOURCE_DIR}")
git_working_tree_dirty(SRB2_COMP_UNCOMMITTED "${CMAKE_SOURCE_DIR}")
set(SRB2_COMP_BRANCH "${SRB2_GIT_BRANCH}")
set(SRB2_COMP_REVISION "${SRB2_COMP_COMMIT}")
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/src/config.h)
if("${SRB2_SDL2_EXE_NAME}" STREQUAL "") if("${SRB2_SDL2_EXE_NAME}" STREQUAL "")
# cause a reconfigure if the branch changes
get_git_dir(SRB2_GIT_DIR)
configure_file("${SRB2_GIT_DIR}/HEAD" HEAD COPYONLY)
git_current_branch(SRB2_GIT_REVISION)
if("${SRB2_GIT_REVISION}" STREQUAL "")
# use abbreviated commit hash if on detached HEAD
git_latest_commit(SRB2_GIT_REVISION)
endif()
list(APPEND EXE_NAME_PARTS "ringracers") list(APPEND EXE_NAME_PARTS "ringracers")
if(NOT "${SRB2_GIT_BRANCH}" STREQUAL "master") if(NOT "${SRB2_GIT_REVISION}" STREQUAL "master")
list(APPEND EXE_NAME_PARTS ${SRB2_GIT_BRANCH}) list(APPEND EXE_NAME_PARTS ${SRB2_GIT_REVISION})
endif() endif()
else() else()
list(APPEND EXE_NAME_PARTS ${SRB2_SDL2_EXE_NAME}) list(APPEND EXE_NAME_PARTS ${SRB2_SDL2_EXE_NAME})

13
cmake/Comptime.cmake Normal file
View file

@ -0,0 +1,13 @@
set(CMAKE_BINARY_DIR "${BINARY_DIR}")
set(CMAKE_CURRENT_BINARY_DIR "${BINARY_DIR}")
# Set up CMAKE path
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules/")
include(GitUtilities)
git_current_branch(SRB2_COMP_BRANCH)
git_summary(SRB2_COMP_REVISION)
git_working_tree_dirty(SRB2_COMP_UNCOMMITTED)
configure_file(src/config.h.in src/config.h)

View file

@ -6,50 +6,42 @@ endif()
set(__GitUtilities ON) set(__GitUtilities ON)
function(git_describe variable path) macro(_git_command)
execute_process(COMMAND "${GIT_EXECUTABLE}" "describe" execute_process(
WORKING_DIRECTORY "${path}" COMMAND "${GIT_EXECUTABLE}" ${ARGN}
RESULT_VARIABLE result WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
OUTPUT_VARIABLE output OUTPUT_VARIABLE output
ERROR_QUIET ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE OUTPUT_STRIP_TRAILING_WHITESPACE
) )
endmacro()
macro(_git_easy_command)
_git_command(${ARGN})
set(${variable} "${output}" PARENT_SCOPE)
endmacro()
function(git_current_branch variable)
_git_command(symbolic-ref -q --short HEAD)
# If a detached head, a ref could still be resolved.
if("${output}" STREQUAL "")
_git_command(describe --all --exact-match)
# Get the ref, in the form heads/master or
# remotes/origin/master so isolate the final part.
string(REGEX REPLACE ".*/" "" output "${output}")
endif()
set(${variable} "${output}" PARENT_SCOPE) set(${variable} "${output}" PARENT_SCOPE)
endfunction() endfunction()
function(git_current_branch variable path) function(git_latest_commit variable)
execute_process(COMMAND ${GIT_EXECUTABLE} "symbolic-ref" "--short" "HEAD" _git_easy_command(rev-parse --short HEAD)
WORKING_DIRECTORY "${path}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${variable} "${output}" PARENT_SCOPE)
endfunction() endfunction()
function(git_latest_commit variable path) function(git_working_tree_dirty variable)
execute_process(COMMAND ${GIT_EXECUTABLE} "rev-parse" "--short" "HEAD" _git_command(status --porcelain -uno)
WORKING_DIRECTORY "${path}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
set(${variable} "${output}" PARENT_SCOPE)
endfunction()
function(git_working_tree_dirty variable path)
execute_process(COMMAND ${GIT_EXECUTABLE} "status" "--porcelain" "-uno"
WORKING_DIRECTORY "${path}"
RESULT_VARIABLE result
OUTPUT_VARIABLE output
ERROR_QUIET
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if(output STREQUAL "") if(output STREQUAL "")
set(${variable} FALSE PARENT_SCOPE) set(${variable} FALSE PARENT_SCOPE)
@ -57,3 +49,11 @@ function(git_working_tree_dirty variable path)
set(${variable} TRUE PARENT_SCOPE) set(${variable} TRUE PARENT_SCOPE)
endif() endif()
endfunction() endfunction()
function(git_summary variable)
_git_easy_command(log -1 "--format=%h %s")
endfunction()
function(get_git_dir variable)
_git_easy_command(rev-parse --git-dir)
endfunction()

View file

@ -132,6 +132,32 @@ add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32
k_roulette.c k_roulette.c
) )
# This updates the modification time for comptime.c at the
# end of building so when the build system is ran next time,
# that file gets flagged. comptime.c will always be rebuilt.
#
# This begs the question, why always rebuild comptime.c?
# Some things like the git commit must be checked each time
# the program is built. But the build system determines which
# files should be rebuilt before anything else. So
# comptime.c, which only needs to be rebuilt based on
# information known at build time, must be told to rebuild
# before that information can be ascertained.
add_custom_command(
TARGET SRB2SDL2
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E touch_nocreate ${CMAKE_CURRENT_BINARY_DIR}/comptime.c
)
# config.h is generated by this command. It should be done at
# build time for accurate git information and before anything
# that needs it, obviously.
add_custom_target(_SRB2_reconf ALL
COMMAND ${CMAKE_COMMAND} -DGIT_EXECUTABLE=${GIT_EXECUTABLE} -DBINARY_DIR=${CMAKE_CURRENT_BINARY_DIR}/.. -P ${CMAKE_CURRENT_SOURCE_DIR}/../cmake/Comptime.cmake
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.."
)
add_dependencies(SRB2SDL2 _SRB2_reconf)
if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows") if("${CMAKE_COMPILER_IS_GNUCC}" AND "${CMAKE_SYSTEM_NAME}" MATCHES "Windows")
target_link_options(SRB2SDL2 PRIVATE "-Wl,--disable-dynamicbase") target_link_options(SRB2SDL2 PRIVATE "-Wl,--disable-dynamicbase")
if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}") if(NOT "${SRB2_CONFIG_SYSTEM_LIBRARIES}" AND NOT "${SRB2_CONFIG_SHARED_INTERNAL_LIBRARIES}")

View file

@ -76,12 +76,6 @@
#include "m_random.h" // P_ClearRandom #include "m_random.h" // P_ClearRandom
#include "k_specialstage.h" #include "k_specialstage.h"
#ifdef CMAKECONFIG
#include "config.h"
#else
#include "config.h.in"
#endif
#ifdef HWRENDER #ifdef HWRENDER
#include "hardware/hw_main.h" // 3D View Rendering #include "hardware/hw_main.h" // 3D View Rendering
#endif #endif
@ -1211,6 +1205,12 @@ void D_SRB2Main(void)
/* break the version string into version numbers, for netplay */ /* break the version string into version numbers, for netplay */
D_ConvertVersionNumbers(); D_ConvertVersionNumbers();
if (!strcmp(compbranch, ""))
{
// \x8b = aqua highlight
compbranch = "\x8b" "detached HEAD" "\x80";
}
#ifdef DEVELOP #ifdef DEVELOP
D_AbbrevCommit(); D_AbbrevCommit();
#endif #endif
@ -1440,6 +1440,7 @@ void D_SRB2Main(void)
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_PK3); // maps.pk3 -- 4 - If you touch this, make sure to touch up the majormods stuff below. mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_MAPS_PK3); // maps.pk3 -- 4 - If you touch this, make sure to touch up the majormods stuff below.
mainwads++; W_VerifyFileMd5(mainwads, ASSET_HASH_FOLLOWERS_PK3); // followers.pk3 mainwads++; W_VerifyFileMd5(mainwads, ASSET_HASH_FOLLOWERS_PK3); // followers.pk3
#ifdef USE_PATCH_FILE #ifdef USE_PATCH_FILE
mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_PK3); // patch.pk3 mainwads++; W_VerifyFileMD5(mainwads, ASSET_HASH_PATCH_PK3); // patch.pk3
#endif #endif
#else #else

View file

@ -4714,7 +4714,7 @@ static void Command_ListDoomednums_f(void)
static void Command_Version_f(void) static void Command_Version_f(void)
{ {
#ifdef DEVELOP #ifdef DEVELOP
CONS_Printf("Ring Racers %s-%s (%s %s)\n", compbranch, comprevision, compdate, comptime); CONS_Printf("Ring Racers %s %s (%s %s)\n", compbranch, comprevision, compdate, comptime);
#else #else
CONS_Printf("Ring Racers %s (%s %s %s %s) ", VERSIONSTRING, compdate, comptime, comprevision, compbranch); CONS_Printf("Ring Racers %s (%s %s %s %s) ", VERSIONSTRING, compdate, comptime, comprevision, compbranch);
#endif #endif

View file

@ -23,12 +23,6 @@
/// \file /// \file
/// \brief SRB2 system stuff for SDL /// \brief SRB2 system stuff for SDL
#ifdef CMAKECONFIG
#include "config.h"
#else
#include "../config.h.in"
#endif
#include <signal.h> #include <signal.h>
#ifdef _WIN32 #ifdef _WIN32