meson: fix exec path with enabled runtime prefix

When the runtime prefix option is enabled, Git is built such that it knows to locate its binaries relative to the directory a binary is being executed from. This requires us to figure out relative paths, which is handled in `system_prefix()` by trying to strip a couple of well-known paths. One of these paths, GIT_EXEC_PATH, is expected to be absolute when runtime prefixes are enabled, but relative otherwise. And while our Makefile gets this correctly, in Meson we always wire up the absolute path, which may result in us not being able to find binaries. Fix this by conditionally injecting the paths depending on whether or not the `runtime_prefix` option is enabled. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Patrick Steinhardt committed Feb 26, 2025 at 09:22 UTC bd262d07b65af894b1014cd8cc2d02aaee65800b
1 file changed +3 -1
meson.build
+3 -1
@@ -691,7 +691,6 @@ libgit_c_args = [
691 '-DETC_GITATTRIBUTES="' + get_option('gitattributes') + '"',
692 '-DETC_GITCONFIG="' + get_option('gitconfig') + '"',
693 '-DFALLBACK_RUNTIME_PREFIX="' + get_option('prefix') + '"',
694 - '-DGIT_EXEC_PATH="' + get_option('prefix') / get_option('libexecdir') / 'git-core"',
694 '-DGIT_HOST_CPU="' + host_machine.cpu_family() + '"',
695 '-DGIT_HTML_PATH="' + get_option('datadir') / 'doc/git-doc"',
696 '-DGIT_INFO_PATH="' + get_option('infodir') + '"',
@@ -1466,6 +1465,7 @@ endif
1465 if get_option('runtime_prefix')
1466 libgit_c_args += '-DRUNTIME_PREFIX'
1467 build_options_config.set('RUNTIME_PREFIX', 'true')
1468 + git_exec_path = get_option('libexecdir') / 'git-core'
1469
1470 if compiler.has_header('mach-o/dyld.h')
1471 libgit_c_args += '-DHAVE_NS_GET_EXECUTABLE_PATH'
@@ -1502,7 +1502,9 @@ if get_option('runtime_prefix')
1502 endif
1503 else
1504 build_options_config.set('RUNTIME_PREFIX', 'false')
1505 + git_exec_path = get_option('prefix') / get_option('libexecdir') / 'git-core'
1506 endif
1507 +libgit_c_args += '-DGIT_EXEC_PATH="' + git_exec_path + '"'
1508
1509 git_version_file = custom_target(
1510 command: [