git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 09/13] meson: improve handling of `sane_tool_path` option

From
Patrick Steinhardt <ps@pks.im>
Date
Feb 26, 2025, 08:22 UTC
Message-ID
<20250226-b4-pks-meson-improvements-v3-9-60c77cf673ae@pks.im>
In-Reply-To
<20250226-b4-pks-meson-improvements-v3-0-60c77cf673ae@pks.im>

The `sane_tool_path` option can be used to override the PATH variable from which the build process, tests and ultimately Git will end up picking programs from. It is currently lacking though because we only use it to populate the PATH environment variable for executed scripts and for the `BROKEN_PATH_FIX` mechanism, but we don't use it to find programs used in the build process itself.

Fix this issue by treating it similar to the Windows-specific paths, which will make us use it both to find programs and to populate the PATH environment variable.

To help with this fix, change the type of the option to be an array of paths, which makes the handling a bit easier for us. It's also the correct thing to do as the input indeed is a list of paths.

Furthermore, the option now overrides the default behaviour on Windows, which si to pick up tools from Git for Windows. This is done so that it becomes easier to override that default behaviour in case it's not desired.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 meson.build       | 17 ++++++++---------
 meson_options.txt |  4 ++--
 2 files changed, 10 insertions(+), 11 deletions(-)
diff --git a/meson.build b/meson.build
index acd6074b32d..ed857aaa4ab 100644
--- a/meson.build
+++ b/meson.build
@@ -191,9 +191,11 @@ project('git', 'c',
 fs = import('fs')
 
 program_path = []
-# Git for Windows provides all the tools we need to build Git.
-if host_machine.system() == 'windows'
-  program_path += [ 'C:/Program Files/Git/bin', 'C:/Program Files/Git/usr/bin' ]
+if get_option('sane_tool_path').length() != 0
+  program_path = get_option('sane_tool_path')
+elif host_machine.system() == 'windows'
+  # Git for Windows provides all the tools we need to build Git.
+  program_path = [ 'C:/Program Files/Git/bin', 'C:/Program Files/Git/usr/bin' ]
 endif
 
 cygpath = find_program('cygpath', dirs: program_path, required: false)
@@ -212,10 +214,6 @@ foreach path : program_path
   script_environment.prepend('PATH', path)
 endforeach
 
-if get_option('sane_tool_path') != ''
-  script_environment.prepend('PATH', get_option('sane_tool_path'))
-endif
-
 # The environment used by GIT-VERSION-GEN. Note that we explicitly override
 # environment variables that might be set by the user. This is by design so
 # that we always use whatever Meson has configured instead of what is present
@@ -671,8 +669,9 @@ build_options_config.set('GIT_TEST_UTF8_LOCALE', '')
 build_options_config.set_quoted('LOCALEDIR', fs.as_posix(get_option('prefix') / get_option('localedir')))
 build_options_config.set('GITWEBDIR', fs.as_posix(get_option('prefix') / get_option('datadir') / 'gitweb'))
 
-if get_option('sane_tool_path') != ''
-  build_options_config.set_quoted('BROKEN_PATH_FIX', 's|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + get_option('sane_tool_path') + '"|')
+if get_option('sane_tool_path').length() != 0
+  sane_tool_path = (host_machine.system() == 'windows' ? ';' : ':').join(get_option('sane_tool_path'))
+  build_options_config.set_quoted('BROKEN_PATH_FIX', 's|^\# @BROKEN_PATH_FIX@$|git_broken_path_fix "' + sane_tool_path + '"|')
 else
   build_options_config.set_quoted('BROKEN_PATH_FIX', '/^\# @BROKEN_PATH_FIX@$/d')
 endif
diff --git a/meson_options.txt b/meson_options.txt
index c102185ed5e..e0e8089891b 100644
--- a/meson_options.txt
+++ b/meson_options.txt
@@ -13,8 +13,8 @@ option('perl_cpan_fallback', type: 'boolean', value: true,
   description: 'Install bundled copies of CPAN modules that serve as a fallback in case the modules are not available on the system.')
 option('runtime_prefix', type: 'boolean', value: false,
   description: 'Resolve ancillary tooling and support files relative to the location of the runtime binary instead of hard-coding them into the binary.')
-option('sane_tool_path', type: 'string', value: '',
-  description: 'A colon-separated list of paths to prepend to PATH if your tools in /usr/bin are broken.')
+option('sane_tool_path', type: 'array', value: [],
+  description: 'An array of paths to pick up tools from in case the normal tools are broken or lacking.')
 
 # Build information compiled into Git and other parts like documentation.
 option('build_date', type: 'string', value: '',
-- 
2.48.1.741.g8a9f3a5cdc.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 10 of 14 in “meson: cleanups, improvements, smallish fixes”
  1. 00/13 meson: cleanups, improvements, smallish fixesPatrick Steinhardt, Feb 26, 2025
  2. 01/13 meson: fix exec path with enabled runtime prefixPatrick Steinhardt, Feb 26, 2025
  3. 03/13 meson: inline the static 'git' libraryPatrick Steinhardt, Feb 26, 2025
  4. 02/13 meson: fix OpenSSL fallback when not explicitly requiredPatrick Steinhardt, Feb 26, 2025
  5. 04/13 meson: simplify use of the common-main libraryPatrick Steinhardt, Feb 26, 2025
  6. 05/13 meson: introduce `libgit_curl` dependencyPatrick Steinhardt, Feb 26, 2025
  7. 06/13 meson: stop linking libcurl into all executablesPatrick Steinhardt, Feb 26, 2025
  8. 07/13 meson: drop separate version libraryPatrick Steinhardt, Feb 26, 2025
  9. 08/13 meson: improve PATH handlingPatrick Steinhardt, Feb 26, 2025
  10. 09/13 meson: improve handling of `sane_tool_path` optionPatrick Steinhardt, Feb 26, 2025
  11. 10/13 meson: prevent finding sed(1) in a loopPatrick Steinhardt, Feb 26, 2025
  12. 12/13 meson: consistently use custom program paths to resolve programsPatrick Steinhardt, Feb 26, 2025
  13. 11/13 meson: fix overwritten `git` variablePatrick Steinhardt, Feb 26, 2025
  14. 13/13 gitlab-ci: restrict maximum number of link jobs on WindowsPatrick Steinhardt, Feb 26, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.