1
0
Fork 0
mirror of https://github.com/TerryCavanagh/VVVVVV.git synced 2024-12-22 09:39:43 +01:00

Optimize recompilation from changing commit hash

This reworks how the commit hash and date are compiled so that if
they're changed (and they're changed often), only one source file needs
to be recompiled in order to update it everywhere in the game, no matter
how many source files use the hash or date.

The commit hash and date are now declared in InterimVersion.h (and they
need `extern "C"` guards because otherwise it results in a link fail on
MSVC because MSVC is stupid).

To do this, what now happens is that upon every rebuild,
InterimVersion.in.c is processed to create InterimVersion.out.c, then
InterimVersion.out.c is compiled into its own static library that is
then linked with VVVVVV.

(Why didn't I just simply add it to the list of VVVVVV source files?
Well, doing it _now_ does nothing because at that point the horse is
already out of the barn, and the VVVVVV executable has already been
declared, so I can't modify its sources. And I can't do it before
either, because we depend on the VVVVVV executable existing to do the
interim version logic. I could probably work around this by cleverly
moving around lines, but that'd separate related logic from each other.)

And yes, the naming convention has changed. Not only did I rename
Version to InterimVersion (to clearly differentiate it from
ReleaseVersion, which I'll be adding later), I also named the files
InterimVersion.in.c and InterimVersion.out.c instead of
InterimVersion.c.in and InterimVersion.c.out. I needed to put the file
extension on the end because otherwise CMake wouldn't recognize what
kind of language it is, and I mean like yeah duh of course it doesn't,
my text editor doesn't recognize it either.
This commit is contained in:
Misa 2022-08-22 21:21:23 -07:00
parent b4226631b9
commit 4bf5e5e6a0
8 changed files with 39 additions and 26 deletions

View file

@ -10,6 +10,7 @@ VVVVVV
*.a *.a
*.gch *.gch
src/Version.h.out src/Version.h.out
src/InterimVersion.out.c
# Game data # Game data
data.zip data.zip

View file

@ -201,8 +201,8 @@ if(NOT OFFICIAL_BUILD)
if(GIT_FOUND) if(GIT_FOUND)
# These filenames have to be qualified, because when we run # These filenames have to be qualified, because when we run
# the CMake script, its work dir gets set to the build folder # the CMake script, its work dir gets set to the build folder
set(VERSION_INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h.in) set(VERSION_INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.in.c)
set(VERSION_OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h.out) set(VERSION_OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.out.c)
add_custom_target( add_custom_target(
GenerateVersion ALL GenerateVersion ALL
@ -219,8 +219,10 @@ if(NOT OFFICIAL_BUILD)
add_dependencies(VVVVVV GenerateVersion) add_dependencies(VVVVVV GenerateVersion)
# This lets Version.h know that Version.h.out exists target_compile_definitions(VVVVVV PRIVATE -DINTERIM_VERSION_EXISTS)
target_compile_definitions(VVVVVV PRIVATE -DVERSION_H_OUT_EXISTS)
add_library(InterimVersion STATIC src/InterimVersion.out.c)
list(APPEND STATIC_LIBRARIES InterimVersion)
endif() endif()
endif() endif()
@ -299,9 +301,9 @@ target_compile_definitions(lodepng-static PRIVATE
) )
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)
set(STATIC_LIBRARIES physfs-static tinyxml2-static lodepng-static faudio-static) list(APPEND STATIC_LIBRARIES physfs-static tinyxml2-static lodepng-static faudio-static)
else() else()
set(STATIC_LIBRARIES lodepng-static) list(APPEND STATIC_LIBRARIES lodepng-static)
endif() endif()
if(BUNDLE_DEPENDENCIES) if(BUNDLE_DEPENDENCIES)

View file

@ -0,0 +1,22 @@
#ifndef INTERIMVERSION_H
#define INTERIMVERSION_H
#ifdef INTERIM_VERSION_EXISTS
#ifdef __cplusplus
extern "C"
{
#endif
extern const char* INTERIM_COMMIT;
extern const int LEN_INTERIM_COMMIT;
extern const char* COMMIT_DATE;
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* INTERIM_VERSION_EXISTS */
#endif /* INTERIMVERSION_H */

View file

@ -0,0 +1,4 @@
const char* INTERIM_COMMIT = "@INTERIM_COMMIT@";
const int LEN_INTERIM_COMMIT = sizeof("@INTERIM_COMMIT@") - 1;
const char* COMMIT_DATE = "@COMMIT_DATE@";

View file

@ -9,6 +9,7 @@
#include "GlitchrunnerMode.h" #include "GlitchrunnerMode.h"
#include "Graphics.h" #include "Graphics.h"
#include "GraphicsUtil.h" #include "GraphicsUtil.h"
#include "InterimVersion.h"
#include "KeyPoll.h" #include "KeyPoll.h"
#include "MakeAndPlay.h" #include "MakeAndPlay.h"
#include "Map.h" #include "Map.h"
@ -17,7 +18,6 @@
#include "Screen.h" #include "Screen.h"
#include "Script.h" #include "Script.h"
#include "UtilityClass.h" #include "UtilityClass.h"
#include "Version.h"
static int tr; static int tr;
static int tg; static int tg;
@ -144,11 +144,9 @@ static void menurender(void)
#if defined(MAKEANDPLAY) #if defined(MAKEANDPLAY)
graphics.Print(-1,temp+35," MAKE AND PLAY EDITION",tr, tg, tb, true); graphics.Print(-1,temp+35," MAKE AND PLAY EDITION",tr, tg, tb, true);
#endif #endif
#ifdef COMMIT_DATE #ifdef INTERIM_VERSION_EXISTS
graphics.Print( 310 - (10*8), 210, COMMIT_DATE, tr/2, tg/2, tb/2); graphics.Print( 310 - (10*8), 210, COMMIT_DATE, tr/2, tg/2, tb/2);
#endif graphics.Print( 310 - LEN_INTERIM_COMMIT * 8, 220, INTERIM_COMMIT, tr/2, tg/2, tb/2);
#ifdef INTERIM_COMMIT
graphics.Print( 310 - (SDL_arraysize(INTERIM_COMMIT) - 1) * 8, 220, INTERIM_COMMIT, tr/2, tg/2, tb/2);
#endif #endif
graphics.Print( 310 - (4*8), 230, "v2.4", tr/2, tg/2, tb/2); graphics.Print( 310 - (4*8), 230, "v2.4", tr/2, tg/2, tb/2);

View file

@ -1,8 +0,0 @@
#ifndef VERSION_H
#define VERSION_H
#ifdef VERSION_H_OUT_EXISTS
#include "Version.h.out"
#endif
#endif /* VERSION_H */

View file

@ -1,7 +0,0 @@
#ifndef VERSION_H_OUT
#define VERSION_H_OUT
#define INTERIM_COMMIT "@INTERIM_COMMIT@"
#define COMMIT_DATE "@COMMIT_DATE@"
#endif /* VERSION_H_OUT */

View file

@ -14,6 +14,7 @@
#include "Game.h" #include "Game.h"
#include "Graphics.h" #include "Graphics.h"
#include "Input.h" #include "Input.h"
#include "InterimVersion.h"
#include "KeyPoll.h" #include "KeyPoll.h"
#include "Logic.h" #include "Logic.h"
#include "Map.h" #include "Map.h"