Skip to content

test() dependencies not added to PATH #4668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lazka opened this issue Dec 20, 2018 · 7 comments · May be fixed by #14649
Open

test() dependencies not added to PATH #4668

lazka opened this issue Dec 20, 2018 · 7 comments · May be fixed by #14649
Labels
enhancement OS:windows Winodows OS specific issues test targets

Comments

@lazka
Copy link
Contributor

lazka commented Dec 20, 2018

Hey, support question:

(context: https://gitlab.gnome.org/GNOME/gobject-introspection/blob/master/tests/scanner/annotationparser/meson.build)

We have a test() which calls Python, which uses some Python module and we set PYTHONPATH there so it can find it. The Python module in turn links against various DLLs when the dependencies are build in subprojects they are obviously not in PATH and things fail.

I tried adding the Python module target as a test depends, but that doesn't add anything to PATH. I can add everything manually to PATH, but well...

Is this something which needs fixing in meson or am I missing something?

@dcbaker
Copy link
Member

dcbaker commented Dec 20, 2018

The problem is you having a layout like:
dir/mod.py
subproject/foo/foo.dll

and mod.py needs foo.dll?

@lazka
Copy link
Contributor Author

lazka commented Dec 20, 2018

yes

test() -> foo.py -> bar.pyd -> subproject/baz/baz.dll

@dcbaker dcbaker added enhancement OS:windows Winodows OS specific issues test targets labels Dec 20, 2018
@dcbaker
Copy link
Member

dcbaker commented Dec 20, 2018

I don't believe there is a robust solution for this ATM. if you only need dll's out of one directory you can probably use the workdir parameter. This really needs to be resolved though, as I have some use cases for this as well.

@lazka
Copy link
Contributor Author

lazka commented Dec 20, 2018

@dcbaker
Copy link
Member

dcbaker commented Dec 20, 2018

I wonder if we could use an environment object for this?

@nirbheek
Copy link
Member

We already have the machinery to do this when you pass a build target or a custom target as an argument to a test; we should just do the same when you pass one of those to depends:. See: self.determine_windows_extra_paths() in write_test_serialisation() in backends.py.

@pwithnall
Copy link
Contributor

We’re hitting this in GLib too, where we have some tests written in Python, which then spawn a native binary in the builddir when they’re run. The native built binary is correctly listed in depends on the test(). On Linux this works fine as the write_test_serialisation() code adds the binary’s dependency paths to LD_LIBRARY_PATH. On mingw/Windows it fails, as the same is not done for PATH.

For the moment I’ve copied Christoph’s workaround, as fixing and testing Meson issues on Windows is not something I’m set up to do (sorry). Mentioning it here so the use case of running a native built binary from a Python unit test is recorded somewhere, as it’s slightly different from Christoph’s original case of a built Python module.

@lb90 lb90 linked a pull request May 27, 2025 that will close this issue
lb90 added a commit to lb90/meson that referenced this issue May 27, 2025
Rather than iterating over t.cmd_args, iterate over the
function-local depends variable. This set is constructed
from all of t.depends and t.cmd_args that are Targets or
CustomTargetIndex.

Fixes mesonbuild#4668
lb90 added a commit to lb90/meson that referenced this issue May 27, 2025
gnomesysadmins pushed a commit to GNOME/glib that referenced this issue May 29, 2025
This works around a Meson bug
(mesonbuild/meson#4668).

If we have a Python test which spawns a built native binary, that binary is
listed in the `depends` argument of the `test()`. On Linux, this results in
the directories containing the built libraries which the binary depends on
being added to the `LD_LIBRARY_PATH` of the test invocation. On Windows,
however, Meson currently doesn’t add those directories to `PATH` (which is
the equivalent of `LD_LIBRARY_PATH`), so we have to do it manually.

This takes the same approach as Christoph Reiter did in
gobject-introspection
(https://gitlab.gnome.org/GNOME/gobject-introspection/blob/13e8c7ff80f9ff2dc77e9d0da4b7396182c63612/tests/meson.build#L2).

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement OS:windows Winodows OS specific issues test targets
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants