aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@gentoo.org>2025-03-25 16:08:48 -0400
committerJunio C Hamano <gitster@pobox.com>2025-03-25 16:20:15 -0700
commitd2827dc31e6769ddd552a34593d28cecd5f3392d (patch)
tree2d67c6c9d0b45b1d427d9263f0bbb6fb3d30c6ea
parent683c54c999c301c2cd6f715c411407c413b1d84e (diff)
downloadgit-d2827dc31e6769ddd552a34593d28cecd5f3392d.tar.gz
meson: disable coccinelle configuration when building from a tarball
Wiring up coccinelle in the build, depends on running git commands to get the list of files to operate on. Reasonable, for a feature mainly used by people developing on git. If building git itself from a tarball distribution of git's own source code, one likely does not need to run coccinelle. But running those git commands failed, and caused the build to error out, if `spatch` was installed -- because the build assumed that its presence indicated a desire to use it on this source tree. Instead, we can expand the conditional to check for both `spatch` and the `.git` file or directory. Meson's `opt.require()` method allows us to add a prerequisite for the feature option. If the prerequisite fails, then the option either: - converts autodetection to disabled - emits an informative error if the feature was set to enabled: ``` ERROR: Feature coccinelle cannot be enabled: coccinelle can only be run from a git checkout ``` Signed-off-by: Eli Schwartz <eschwartz@gentoo.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--contrib/coccinelle/meson.build7
1 files changed, 6 insertions, 1 deletions
diff --git a/contrib/coccinelle/meson.build b/contrib/coccinelle/meson.build
index 5d76a7fee6..ea054c924f 100644
--- a/contrib/coccinelle/meson.build
+++ b/contrib/coccinelle/meson.build
@@ -1,4 +1,9 @@
-spatch = find_program('spatch', required: get_option('coccinelle'))
+coccinelle_opt = get_option('coccinelle').require(
+ fs.exists(meson.project_source_root() / '.git'),
+ error_message: 'coccinelle can only be run from a git checkout',
+)
+
+spatch = find_program('spatch', required: coccinelle_opt)
if not spatch.found()
subdir_done()
endif