From 4bf5e5e6a063de113e1e661275f09ad7ea546844 Mon Sep 17 00:00:00 2001 From: Misa Date: Mon, 22 Aug 2022 21:21:23 -0700 Subject: [PATCH] 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. --- desktop_version/.gitignore | 1 + desktop_version/CMakeLists.txt | 14 ++++++++------ desktop_version/src/InterimVersion.h | 22 ++++++++++++++++++++++ desktop_version/src/InterimVersion.in.c | 4 ++++ desktop_version/src/Render.cpp | 8 +++----- desktop_version/src/Version.h | 8 -------- desktop_version/src/Version.h.in | 7 ------- desktop_version/src/main.cpp | 1 + 8 files changed, 39 insertions(+), 26 deletions(-) create mode 100644 desktop_version/src/InterimVersion.h create mode 100644 desktop_version/src/InterimVersion.in.c delete mode 100644 desktop_version/src/Version.h delete mode 100644 desktop_version/src/Version.h.in diff --git a/desktop_version/.gitignore b/desktop_version/.gitignore index 241f712d..04039b60 100644 --- a/desktop_version/.gitignore +++ b/desktop_version/.gitignore @@ -10,6 +10,7 @@ VVVVVV *.a *.gch src/Version.h.out +src/InterimVersion.out.c # Game data data.zip diff --git a/desktop_version/CMakeLists.txt b/desktop_version/CMakeLists.txt index 29211a75..b9f0b627 100644 --- a/desktop_version/CMakeLists.txt +++ b/desktop_version/CMakeLists.txt @@ -201,8 +201,8 @@ if(NOT OFFICIAL_BUILD) if(GIT_FOUND) # These filenames have to be qualified, because when we run # 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_OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/Version.h.out) + set(VERSION_INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.in.c) + set(VERSION_OUTPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/src/InterimVersion.out.c) add_custom_target( GenerateVersion ALL @@ -219,8 +219,10 @@ if(NOT OFFICIAL_BUILD) add_dependencies(VVVVVV GenerateVersion) - # This lets Version.h know that Version.h.out exists - target_compile_definitions(VVVVVV PRIVATE -DVERSION_H_OUT_EXISTS) + target_compile_definitions(VVVVVV PRIVATE -DINTERIM_VERSION_EXISTS) + + add_library(InterimVersion STATIC src/InterimVersion.out.c) + list(APPEND STATIC_LIBRARIES InterimVersion) endif() endif() @@ -299,9 +301,9 @@ target_compile_definitions(lodepng-static PRIVATE ) 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() - set(STATIC_LIBRARIES lodepng-static) + list(APPEND STATIC_LIBRARIES lodepng-static) endif() if(BUNDLE_DEPENDENCIES) diff --git a/desktop_version/src/InterimVersion.h b/desktop_version/src/InterimVersion.h new file mode 100644 index 00000000..109c8014 --- /dev/null +++ b/desktop_version/src/InterimVersion.h @@ -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 */ diff --git a/desktop_version/src/InterimVersion.in.c b/desktop_version/src/InterimVersion.in.c new file mode 100644 index 00000000..24f72d00 --- /dev/null +++ b/desktop_version/src/InterimVersion.in.c @@ -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@"; diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index 54e56426..bce5901b 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -9,6 +9,7 @@ #include "GlitchrunnerMode.h" #include "Graphics.h" #include "GraphicsUtil.h" +#include "InterimVersion.h" #include "KeyPoll.h" #include "MakeAndPlay.h" #include "Map.h" @@ -17,7 +18,6 @@ #include "Screen.h" #include "Script.h" #include "UtilityClass.h" -#include "Version.h" static int tr; static int tg; @@ -144,11 +144,9 @@ static void menurender(void) #if defined(MAKEANDPLAY) graphics.Print(-1,temp+35," MAKE AND PLAY EDITION",tr, tg, tb, true); #endif -#ifdef COMMIT_DATE +#ifdef INTERIM_VERSION_EXISTS graphics.Print( 310 - (10*8), 210, COMMIT_DATE, tr/2, tg/2, tb/2); -#endif -#ifdef INTERIM_COMMIT - graphics.Print( 310 - (SDL_arraysize(INTERIM_COMMIT) - 1) * 8, 220, INTERIM_COMMIT, tr/2, tg/2, tb/2); + graphics.Print( 310 - LEN_INTERIM_COMMIT * 8, 220, INTERIM_COMMIT, tr/2, tg/2, tb/2); #endif graphics.Print( 310 - (4*8), 230, "v2.4", tr/2, tg/2, tb/2); diff --git a/desktop_version/src/Version.h b/desktop_version/src/Version.h deleted file mode 100644 index e1bf0cbc..00000000 --- a/desktop_version/src/Version.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef VERSION_H -#define VERSION_H - -#ifdef VERSION_H_OUT_EXISTS -#include "Version.h.out" -#endif - -#endif /* VERSION_H */ diff --git a/desktop_version/src/Version.h.in b/desktop_version/src/Version.h.in deleted file mode 100644 index 0837b9cb..00000000 --- a/desktop_version/src/Version.h.in +++ /dev/null @@ -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 */ diff --git a/desktop_version/src/main.cpp b/desktop_version/src/main.cpp index c9dea47b..33988be3 100644 --- a/desktop_version/src/main.cpp +++ b/desktop_version/src/main.cpp @@ -14,6 +14,7 @@ #include "Game.h" #include "Graphics.h" #include "Input.h" +#include "InterimVersion.h" #include "KeyPoll.h" #include "Logic.h" #include "Map.h"