Repository: mesonbuild/meson

Issue:
regression: meson 1.2.3 fails to build gtk3, gtk4, glib-networking and gvfs
**Describe the bug**
After updating meson to version 1.2.3 (from 1.2.2) the 4 GNOME packages gtk3, gtk4,glib-networking and gvfs fail to build on openSUSE Tumbleweed (the update is initially tested against the GNOME stack, as the maintainers overlap between meson and the GNOME packages for openSUSE)

Those 4 builds all fail with something like:

```
[   24s] meson.build:889:8: ERROR: Unhandled python exception
[   24s] 
[   24s]     This is a Meson bug and should be reported!
```

This is part of this block in meson.build:

```
if host_machine.system() != 'windows'
  # Install Valgrind suppression files (except on Windows,
  # as Valgrind is currently not supported on Windows)
  install_data('gtk.supp',
    install_dir : join_paths(gtk_datadir, 'gtk-4.0', 'valgrind'))
endif
```

** Traceback **
```
[   10s] Traceback (most recent call last):
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/mesonmain.py", line 194, in run
[   10s]     return options.run_func(options)
[   10s]            ^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/msetup.py", line 358, in run
[   10s]     app.generate()
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/msetup.py", line 183, in generate
[   10s]     return self._generate(env, capture, vslite_ctx)
[   10s]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/msetup.py", line 228, in _generate
[   10s]     intr.run()
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreter.py", line 3002, in run
[   10s]     super().run()
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 164, in run
[   10s]     self.evaluate_codeblock(self.ast, start=1)
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 190, in evaluate_codeblock
[   10s]     raise e
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 182, in evaluate_codeblock
[   10s]     self.evaluate_statement(cur)
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 200, in evaluate_statement
[   10s]     return self.method_call(cur)
[   10s]            ^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/interpreterbase.py", line 550, in method_call
[   10s]     res = obj.method_call(method_name, args, kwargs)
[   10s]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreter/interpreterobjects.py", line 811, in method_call
[   10s]     ret = method(state, args, kwargs)
[   10s]           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 596, in wrapper
[   10s]     return f(*wrapped_args, **wrapped_kwargs)
[   10s]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 64, in wrapped
[   10s]     return f(*wrapped_args, **wrapped_kwargs)
[   10s]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/interpreterbase/decorators.py", line 690, in wrapped
[   10s]     return f(*wrapped_args, **wrapped_kwargs)
[   10s]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/modules/gnome.py", line 363, in post_install
[   10s]     script = state.backend.get_executable_serialisation([prog, moduledir])
[   10s]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[   10s]   File "/usr/lib/python3.11/site-packages/mesonbuild/backend/backends.py", line 570, in get_executable_serialisation
[   10s]     if exe_cmd[0].endswith('.jar'):
[   10s]        ^^^^^^^^^^^^^^^^^^^
[   10s] AttributeError: 'NoneType' object has no attribute 'endswith'
[   10s] The Meson build system
[   10s] Version: 1.2.3
```

**To Reproduce**

* Update meson from 1.2.2 to 1.2.3
* Rebuild glib-networking, gtk3, gtk4 or gvfs and see the builds fail

**system parameters**
* Is this a [cross build](https://mesonbuild.com/Cross-compilation.html) or just a plain native build (for the same computer)? *Native build*
* what operating system (e.g. MacOS Catalina, Windows 10, CentOS 8.0, Ubuntu 18.04, etc.) *openSUSE Tumbleweed*
* what Python version are you using e.g. 3.8.0: *3.11.5*
* what `meson --version`: *1.2.3*
* what `ninja --version` if it's a Ninja build: *1.11.1*



Discussion:
I'm going to need more data on this because those packages build fine for me.

Of course, we could be testing completely different things -- I'm not even sure which versions you had issues with. ;)

I tried with:
- glib-networking 2.76.1
- gtk4 4.10.5
- gtk3 3.24.38
- gvfs 1.50.6
I'm also fairly well baffled at what on the list of commits for 1.2.3 could have affected this for better or worse. Have you tested that setting up the identical environment but without the 1.2.3 update causes things to pass?
> I'm going to need more data on this because those packages build fine for me.
> 
> Of course, we could be testing completely different things -- I'm not even sure which versions you had issues with. ;)

Maybe... 
> 
> I tried with:
> 
>     * glib-networking 2.76.1
>     * gtk4 4.10.5
>     * gtk3 3.24.38
>     * gvfs 1.50.6


In my case it is GNOME 45 stack, so:
* gtk4: 4.12.3
* gtk3: 3.24.38
* glib-networking: 2.78.0
* gvfs: 1.52.0

I am using open build service, based on the project GNOME:Next (currently holding the GNOME Stable branch)

If I build those for packages with meson 1.2.3, they fail, if I build them using meson 1.2.2, they pass. The rest of the buildroot is being setup with the same package versions/build artefacts.

I'll see if I can bisect this; the commits between 1.2.2…1.2.3 really do  not look strange




git bisect brought me to https://github.com/mesonbuild/meson/commit/ab3d02066c91974922948f8b8b0fc944875d1a90

Indeed,I can take the 1.2.3 tarball and revert that commit, and then gtk4 (the one I just used for the git bisect testing) passes the `meson setup` again.
This  seems not to be a regression of meson itself - there is indeed a binary it cannot find (added some debug prints); 

so instead of the backtrace, maybe meson should try to catch what binary it was trying to look for and not finding (in case of openSUSE it was /usr/bin/gio-querymodules - which is renamed to /usr/bin/gio-querymodules-64, but apparently not corrected in the .pc file)



Resolving patch:
diff --git a/mesonbuild/modules/__init__.py b/mesonbuild/modules/__init__.py
--- a/mesonbuild/modules/__init__.py
+++ b/mesonbuild/modules/__init__.py
@@ -112,7 +112,12 @@ def find_tool(self, name: str, depname: str, varname: str, required: bool = True
         if dep.found() and dep.type_name == 'pkgconfig':
             value = dep.get_variable(pkgconfig=varname)
             if value:
-                return ExternalProgram(value)
+                progobj = ExternalProgram(value)
+                if not progobj.found():
+                    msg = (f'Dependency {depname!r} tool variable {varname!r} contains erroneous value: {value!r}\n\n'
+                           'This is a distributor issue -- please report it to your {depname} provider.')
+                    raise mesonlib.MesonException(msg)
+                return progobj
 
         # Normal program lookup
         return self.find_program(name, required=required, wanted=wanted)


Test patch: