meson: respect 'tests' build option in contrib

Both the "netrc" credential helper and git-subtree(1) from "contrib/"
carry a couple of tests with them. These tests get wired up in Meson
unconditionally even in the case where `-Dtests=false`. As those tests
depend on the `test_enviroment` variable, which only gets defined in
case `-Dtests=true`, the result is an error:

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

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

Fix the issue by not defining these tests at all in case the "tests"
option is set to `false`.

Reported-by: Sam James <sam@gentoo.org>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
maint
Patrick Steinhardt 2025-03-31 10:33:09 +02:00 committed by Junio C Hamano
parent c0d3f90ef5
commit bdd04b91c3
2 changed files with 23 additions and 19 deletions

View File

@ -7,6 +7,7 @@ credential_netrc = custom_target(
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )


if get_option('tests')
credential_netrc_testenv = test_environment credential_netrc_testenv = test_environment
credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path()) credential_netrc_testenv.set('CREDENTIAL_NETRC_PATH', credential_netrc.full_path())


@ -18,3 +19,4 @@ test('t-git-credential-netrc',
depends: test_dependencies + bin_wrappers + [credential_netrc], depends: test_dependencies + bin_wrappers + [credential_netrc],
timeout: 0, timeout: 0,
) )
endif

View File

@ -12,6 +12,7 @@ git_subtree = custom_target(
install_dir: get_option('libexecdir') / 'git-core', install_dir: get_option('libexecdir') / 'git-core',
) )


if get_option('tests')
subtree_test_environment = test_environment subtree_test_environment = test_environment
subtree_test_environment.prepend('PATH', meson.current_build_dir()) subtree_test_environment.prepend('PATH', meson.current_build_dir())


@ -22,6 +23,7 @@ test('t7900-subtree', shell,
depends: test_dependencies + bin_wrappers + [ git_subtree ], depends: test_dependencies + bin_wrappers + [ git_subtree ],
timeout: 0, timeout: 0,
) )
endif


if get_option('docs').contains('man') if get_option('docs').contains('man')
subtree_xml = custom_target( subtree_xml = custom_target(