From b9bb3535aeda6e604ff2b9dc2f871c8214aab41f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=9A=93?= Date: Sat, 1 Feb 2025 17:28:52 -0500 Subject: [PATCH] Use `vcs_tag` to get Git version instead of `run_command` This way Meson will automatically keep the Git hash updated as you make new Git commits, rather than forcing you to reconfigure the build again every time you make a new commit to keep the commit hash updated. --- binding/binding-mri.cpp | 4 ++++ meson.build | 7 +++---- src/core.cpp | 1 + src/git-hash.h.in | 3 +++ 4 files changed, 11 insertions(+), 4 deletions(-) create mode 100644 src/git-hash.h.in diff --git a/binding/binding-mri.cpp b/binding/binding-mri.cpp index 5c888bac..cb3b2d49 100644 --- a/binding/binding-mri.cpp +++ b/binding/binding-mri.cpp @@ -64,6 +64,10 @@ extern "C" { #include #include +#ifndef MKXPZ_BUILD_XCODE +# include "git-hash.h" +#endif // MKXPZ_BUILD_XCODE + extern const char module_rpg1[]; extern const char module_rpg2[]; extern const char module_rpg3[]; diff --git a/meson.build b/meson.build index 4e6e437d..40effc17 100644 --- a/meson.build +++ b/meson.build @@ -7,8 +7,6 @@ if get_option('retro') == false and host_system == 'darwin' error('\nThis Meson project no longer supports macOS. Please use the Xcode project instead.') endif -git_hash = run_command('git', 'rev-parse', '--short', 'HEAD', check: true).stdout().strip() - compilers = {'cpp': meson.get_compiler('cpp')} global_sources = [] @@ -24,7 +22,6 @@ win64 = (sizeof['void*'] != sizeof['long']) global_args += '-DMKXPZ_BUILD_MESON' global_args += '-DMKXPZ_VERSION="@0@"'.format(meson.project_version()) -global_args += '-DMKXPZ_GIT_HASH="@0@"'.format(git_hash) global_args += '-DHAVE_NANOSLEEP' # ==================== # Ext libs @@ -149,7 +146,6 @@ if get_option('retro') == true retro_defines = [ '-DMKXPZ_VERSION="@0@"'.format(meson.project_version()), - '-DMKXPZ_GIT_HASH="@0@"'.format(git_hash), '-DWASM_RT_SKIP_SIGNAL_RECOVERY', '-DWASM_RT_TRAP_HANDLER=mkxp_sandbox_trap_handler', '-DMKXPZ_RETRO', @@ -247,6 +243,7 @@ if get_option('retro') == true include_directories(join_paths(retro_phase1, 'sdl/include')), ], sources: [ + vcs_tag(command: ['git', 'rev-parse', '--short', 'HEAD'], input: 'src/git-hash.h.in', output: 'git-hash.h', replace_string: '@MKXPZ_GIT_HASH@'), 'src/core.cpp', 'src/sharedstate.cpp', 'src/audio/alstream.cpp', @@ -286,6 +283,8 @@ if get_option('retro') == true ) else +global_sources += vcs_tag(command: ['git', 'rev-parse', '--short', 'HEAD'], input: 'src/git-hash.h.in', output: 'git-hash.h', replace_string: '@MKXPZ_GIT_HASH@') + xxd = find_program('xxd', native: true) # STEAMWORKS diff --git a/src/core.cpp b/src/core.cpp index 7b033b0e..cce26a10 100644 --- a/src/core.cpp +++ b/src/core.cpp @@ -29,6 +29,7 @@ #include #include #include +#include "git-hash.h" #include "../binding-sandbox/sandbox.h" #include "../binding-sandbox/binding-sandbox.h" #include "../binding-sandbox/core.h" diff --git a/src/git-hash.h.in b/src/git-hash.h.in new file mode 100644 index 00000000..700b8017 --- /dev/null +++ b/src/git-hash.h.in @@ -0,0 +1,3 @@ +#ifndef MKXPZ_GIT_HASH +#define MKXPZ_GIT_HASH "@MKXPZ_GIT_HASH@" +#endif /* MKXPZ_GIT_HASH */