diff mbox series

meson: use test_environment conditionally.

Message ID 310a34bace801d288e369c6a01a8d04ffc4c3c06.1741975367.git.sam@gentoo.org (mailing list archive)
State Superseded
Headers show
Series meson: use test_environment conditionally. | expand

Commit Message

Sam James March 14, 2025, 6:02 p.m. UTC
test_environment is only defined with -Dtests, so use it conditionally
and define a stub environment() instead, to avoid erroring out:

```
$ meson setup -Dtests=false -Dcontrib=subtree build
[...]

contrib/subtree/meson.build:15:27: ERROR: Unknown variable "test_environment".
```

Do the same for 'netrc' in contrib/ as it uses the same pattern.
---
Not sure if we can do better here somehow or not (with a disabler?)

 contrib/credential/netrc/meson.build | 8 ++++++--
 contrib/subtree/meson.build          | 8 ++++++--
 2 files changed, 12 insertions(+), 4 deletions(-)

Comments

Patrick Steinhardt March 19, 2025, 1:39 p.m. UTC | #1
On Fri, Mar 14, 2025 at 06:02:47PM +0000, Sam James wrote:
> test_environment is only defined with -Dtests, so use it conditionally
> and define a stub environment() instead, to avoid erroring out:
> 
> ```
> $ meson setup -Dtests=false -Dcontrib=subtree build
> [...]
> 
> contrib/subtree/meson.build:15:27: ERROR: Unknown variable "test_environment".
> ```
> 
> Do the same for 'netrc' in contrib/ as it uses the same pattern.
> ---
> Not sure if we can do better here somehow or not (with a disabler?)
> 
>  contrib/credential/netrc/meson.build | 8 ++++++--
>  contrib/subtree/meson.build          | 8 ++++++--
>  2 files changed, 12 insertions(+), 4 deletions(-)
> 
> diff --git a/contrib/credential/netrc/meson.build b/contrib/credential/netrc/meson.build
> index a990dbb86d..6d815d01c4 100644
> --- a/contrib/credential/netrc/meson.build
> +++ b/contrib/credential/netrc/meson.build
> @@ -7,8 +7,12 @@ credential_netrc = custom_target(
>    install_dir: get_option('libexecdir') / 'git-core',
>  )
>  
> -credential_netrc_testenv = test_environment
> -credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())
> +if get_option('tests')
> +  credential_netrc_testenv = test_environment
> +  credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())
> +else
> +  credential_netrc_testenv = environment()
> +fi
>  
>  test('t-git-credential-netrc',
>    shell,
> diff --git a/contrib/subtree/meson.build b/contrib/subtree/meson.build
> index 9c72b23625..d18f188216 100644
> --- a/contrib/subtree/meson.build
> +++ b/contrib/subtree/meson.build
> @@ -12,8 +12,12 @@ git_subtree = custom_target(
>    install_dir: get_option('libexecdir') / 'git-core',
>  )
>  
> -subtree_test_environment = test_environment
> -subtree_test_environment.prepend('PATH', meson.current_build_dir())
> +if get_option('tests')
> +  subtree_test_environment = test_environment
> +  subtree_test_environment.prepend('PATH', meson.current_build_dir())
> +else
> +  subtree_test_environment = environment()
> +endif
>  
>  test('t7900-subtree', shell,
>    args: [ 't7900-subtree.sh' ],

Thanks for the fix! I think it doesn't quite go far enough though, does
it? I would have expected us to completely disable tests in case we have
`!get_option("tests")`, e.g. like the below patch.

I see this patch has already been merged to `next` though, so we'd have
to send a follow-up fix that builds on top of it. Do you want to do it
or shall I send this patch?

Thanks!

Patrick

diff --git a/contrib/credential/netrc/meson.build b/contrib/credential/netrc/meson.build
index a990dbb86da..3d74547c8ae 100644
--- a/contrib/credential/netrc/meson.build
+++ b/contrib/credential/netrc/meson.build
@@ -7,14 +7,16 @@ credential_netrc = custom_target(
   install_dir: get_option('libexecdir') / 'git-core',
 )
 
-credential_netrc_testenv = test_environment
-credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())
+if get_option('tests')
+  credential_netrc_testenv = test_environment
+  credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())
 
-test('t-git-credential-netrc',
-  shell,
-  args: [ meson.current_source_dir() / 't-git-credential-netrc.sh' ],
-  workdir: meson.current_source_dir(),
-  env: credential_netrc_testenv,
-  depends: test_dependencies + bin_wrappers + [credential_netrc],
-  timeout: 0,
-)
+  test('t-git-credential-netrc',
+    shell,
+    args: [ meson.current_source_dir() / 't-git-credential-netrc.sh' ],
+    workdir: meson.current_source_dir(),
+    env: credential_netrc_testenv,
+    depends: test_dependencies + bin_wrappers + [credential_netrc],
+    timeout: 0,
+  )
+endif
diff --git a/contrib/subtree/meson.build b/contrib/subtree/meson.build
index 9c72b236259..63714166a61 100644
--- a/contrib/subtree/meson.build
+++ b/contrib/subtree/meson.build
@@ -12,16 +12,18 @@ git_subtree = custom_target(
   install_dir: get_option('libexecdir') / 'git-core',
 )
 
-subtree_test_environment = test_environment
-subtree_test_environment.prepend('PATH', meson.current_build_dir())
+if get_option('tests')
+  subtree_test_environment = test_environment
+  subtree_test_environment.prepend('PATH', meson.current_build_dir())
 
-test('t7900-subtree', shell,
-  args: [ 't7900-subtree.sh' ],
-  env: subtree_test_environment,
-  workdir: meson.current_source_dir() / 't',
-  depends: test_dependencies + bin_wrappers + [ git_subtree ],
-  timeout: 0,
-)
+  test('t7900-subtree', shell,
+    args: [ 't7900-subtree.sh' ],
+    env: subtree_test_environment,
+    workdir: meson.current_source_dir() / 't',
+    depends: test_dependencies + bin_wrappers + [ git_subtree ],
+    timeout: 0,
+  )
+endif
 
 if get_option('docs').contains('man')
   subtree_xml = custom_target(
diff mbox series

Patch

diff --git a/contrib/credential/netrc/meson.build b/contrib/credential/netrc/meson.build
index a990dbb86d..6d815d01c4 100644
--- a/contrib/credential/netrc/meson.build
+++ b/contrib/credential/netrc/meson.build
@@ -7,8 +7,12 @@  credential_netrc = custom_target(
   install_dir: get_option('libexecdir') / 'git-core',
 )
 
-credential_netrc_testenv = test_environment
-credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())
+if get_option('tests')
+  credential_netrc_testenv = test_environment
+  credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())
+else
+  credential_netrc_testenv = environment()
+fi
 
 test('t-git-credential-netrc',
   shell,
diff --git a/contrib/subtree/meson.build b/contrib/subtree/meson.build
index 9c72b23625..d18f188216 100644
--- a/contrib/subtree/meson.build
+++ b/contrib/subtree/meson.build
@@ -12,8 +12,12 @@  git_subtree = custom_target(
   install_dir: get_option('libexecdir') / 'git-core',
 )
 
-subtree_test_environment = test_environment
-subtree_test_environment.prepend('PATH', meson.current_build_dir())
+if get_option('tests')
+  subtree_test_environment = test_environment
+  subtree_test_environment.prepend('PATH', meson.current_build_dir())
+else
+  subtree_test_environment = environment()
+endif
 
 test('t7900-subtree', shell,
   args: [ 't7900-subtree.sh' ],