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

[PATCH v2] meson: Tolerate errors from git ls-files --deduplicate

From
Martin Storsjö <martin@martin.st>
Date
Aug 1, 2025, 07:56 UTC
Message-ID
<20250801075649.1796238-1-martin@martin.st>
In-Reply-To
<69faab5-43d4-812c-90f-c518ff7f618@martin.st>

When using the Meson build system with an old-enough Git version that does not yet know the `git ls-files --deduplicate` option one can observe the following error:

    ../meson.build:697:19: ERROR: Command `/usr/bin/git -C /home/martin/code/git ls-files --deduplicate '*.h' ':!contrib' ':!compat/inet_ntop.c' ':!compat/inet_pton.c' ':!compat/nedmalloc' ':!compat/obstack.*' ':!compat/poll' ':!compat/regex' ':!sha1collisiondetection' ':!sha1dc' ':!t/unit-tests/clar' ':!t/t[0-9][0-9][0-9][0-9]*' ':!xdiff'` failed with status 129.

The failing command is used to find all header files in our code base, which is required for static analysis.

Static analysis is an entirely optional feature that distributors typically don't care about, and we already know to skip running the command when we are not in a Git repository. But we do not handle the above failure gracefully, even though we could.

Fix this by passing `check: false` to `run_command`, which makes it tolerate failures. Then check `returncode()` manually to decide whether to inspect the output.

Signed-off-by: Martin Storsjö <martin@martin.st>
---
 meson.build | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/meson.build b/meson.build
index 9bc1826cb6..9b519e6eed 100644
--- a/meson.build
+++ b/meson.build
@@ -694,9 +694,12 @@ third_party_excludes = [
 
 headers_to_check = []
 if git.found() and fs.exists(meson.project_source_root() / '.git')
-  foreach header : run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_excludes, check: true).stdout().split()
-    headers_to_check += header
-  endforeach
+  ls_headers = run_command(git, '-C', meson.project_source_root(), 'ls-files', '--deduplicate', '*.h', third_party_excludes, check: false)
+  if ls_headers.returncode() == 0
+    foreach header : ls_headers.stdout().split()
+      headers_to_check += header
+    endforeach
+  endif
 endif
 
 if not get_option('breaking_changes')
-- 
2.43.0
Previous: Martin StorsjöNext: Patrick Steinhardt
Message 4 of 13 in “meson: Check whether git is new enough to support ls-files --deduplicate”
  1. meson: Check whether git is new enough to support ls-files --deduplicateMartin Storsjö, Jul 31, 2025
  2. Patrick SteinhardtAug 1, 2025
  3. Martin StorsjöAug 1, 2025
  4. meson: Tolerate errors from git ls-files --deduplicateMartin Storsjö, Aug 1, 2025
  5. Patrick SteinhardtAug 1, 2025
  6. Martin StorsjöAug 1, 2025
  7. Patrick SteinhardtAug 1, 2025
  8. Martin StorsjöAug 1, 2025
  9. meson: Tolerate errors from git ls-files --deduplicateMartin Storsjö, Aug 1, 2025
  10. Patrick SteinhardtAug 1, 2025
  11. Junio C HamanoAug 1, 2025
  12. Martin StorsjöAug 1, 2025
  13. meson: Tolerate errors from git ls-files --deduplicateMartin Storsjö, Aug 1, 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.