git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] meson: disable coccinelle configuration when building from a tarball
@ 2025-03-25 20:05 Eli Schwartz
  2025-03-25 20:08 ` [PATCH v2] " Eli Schwartz
  0 siblings, 1 reply; 5+ messages in thread
From: Eli Schwartz @ 2025-03-25 20:05 UTC (permalink / raw)
  To: git; +Cc: Patrick Steinhardt, Sam James

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

Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
---
 contrib/coccinelle/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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

base-commit: c1d6628c9433c09ff62f916f2b933ee12995e9d8
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH v2] meson: disable coccinelle configuration when building from a tarball
  2025-03-25 20:05 [PATCH] meson: disable coccinelle configuration when building from a tarball Eli Schwartz
@ 2025-03-25 20:08 ` Eli Schwartz
  2025-03-25 23:21   ` Junio C Hamano
  2025-03-26  8:28   ` Patrick Steinhardt
  0 siblings, 2 replies; 5+ messages in thread
From: Eli Schwartz @ 2025-03-25 20:08 UTC (permalink / raw)
  To: git; +Cc: Patrick Steinhardt, Sam James

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

v2: accidentally chopped off part of the commit message, sorry...

 contrib/coccinelle/meson.build | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

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

base-commit: c1d6628c9433c09ff62f916f2b933ee12995e9d8
-- 
2.48.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] meson: disable coccinelle configuration when building from a tarball
  2025-03-25 20:08 ` [PATCH v2] " Eli Schwartz
@ 2025-03-25 23:21   ` Junio C Hamano
  2025-03-25 23:29     ` Eli Schwartz
  2025-03-26  8:28   ` Patrick Steinhardt
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2025-03-25 23:21 UTC (permalink / raw)
  To: Eli Schwartz; +Cc: git, Patrick Steinhardt, Sam James

Eli Schwartz <eschwartz@gentoo.org> writes:

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

Good thinking.  I very much appreciate that you allowed .git to be a
regular file, as well as a directory.

Will queue.  Thanks.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] meson: disable coccinelle configuration when building from a tarball
  2025-03-25 23:21   ` Junio C Hamano
@ 2025-03-25 23:29     ` Eli Schwartz
  0 siblings, 0 replies; 5+ messages in thread
From: Eli Schwartz @ 2025-03-25 23:29 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, Patrick Steinhardt, Sam James


[-- Attachment #1.1: Type: text/plain, Size: 506 bytes --]

On 3/25/25 7:21 PM, Junio C Hamano wrote:
> Eli Schwartz <eschwartz@gentoo.org> writes:
> 
>> 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.
> 
> Good thinking.  I very much appreciate that you allowed .git to be a
> regular file, as well as a directory.
> 
> Will queue.  Thanks.


As a heavy user of worktrees this topic is certainly on my mind. :D


-- 
Eli Schwartz

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 236 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] meson: disable coccinelle configuration when building from a tarball
  2025-03-25 20:08 ` [PATCH v2] " Eli Schwartz
  2025-03-25 23:21   ` Junio C Hamano
@ 2025-03-26  8:28   ` Patrick Steinhardt
  1 sibling, 0 replies; 5+ messages in thread
From: Patrick Steinhardt @ 2025-03-26  8:28 UTC (permalink / raw)
  To: Eli Schwartz; +Cc: git, Sam James

On Tue, Mar 25, 2025 at 04:08:48PM -0400, Eli Schwartz wrote:
> 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
>   ```

Makes sense.

> Signed-off-by: Eli Schwartz <eschwartz@gentoo.org>
> ---
> 
> v2: accidentally chopped off part of the commit message, sorry...
> 
>  contrib/coccinelle/meson.build | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> 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
> 
> base-commit: c1d6628c9433c09ff62f916f2b933ee12995e9d8

Yup, makes sense, as well.

Thank you for the patch, looks good!

Patrick

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-03-26  8:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-03-25 20:05 [PATCH] meson: disable coccinelle configuration when building from a tarball Eli Schwartz
2025-03-25 20:08 ` [PATCH v2] " Eli Schwartz
2025-03-25 23:21   ` Junio C Hamano
2025-03-25 23:29     ` Eli Schwartz
2025-03-26  8:28   ` Patrick Steinhardt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).