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.
This commit is contained in:
刘皓 2025-02-01 17:28:52 -05:00
parent 37a7559e38
commit b9bb3535ae
No known key found for this signature in database
GPG key ID: 7901753DB465B711
4 changed files with 11 additions and 4 deletions

View file

@ -64,6 +64,10 @@ extern "C" {
#include <SDL_loadso.h>
#include <SDL_power.h>
#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[];

View file

@ -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

View file

@ -29,6 +29,7 @@
#include <AL/alext.h>
#include <fluidlite.h>
#include <fluidsynth_priv.h>
#include "git-hash.h"
#include "../binding-sandbox/sandbox.h"
#include "../binding-sandbox/binding-sandbox.h"
#include "../binding-sandbox/core.h"

3
src/git-hash.h.in Normal file
View file

@ -0,0 +1,3 @@
#ifndef MKXPZ_GIT_HASH
#define MKXPZ_GIT_HASH "@MKXPZ_GIT_HASH@"
#endif /* MKXPZ_GIT_HASH */