On Fri, Sep 5, 2025 at 5:01 PM Peter Foley <pefo...@google.com> wrote:
> Interesting, that's not what I'm seeing in practice.
> For example, locally reverting the change to block/meson.build results in:
> FAILED: block/module_block.h
> /build/work/046b6fd7014012220d3de53b1bd62f6eb1e9/google3/third_party/qemu/block/../scripts/modules/module_block.py
>  block/module_block.h
> /usr/bin/env: 'python3': No such file or directory
>
> Where module_block.py is *not* executable:
> -rw-rw-r-- 1 pefoley primarygroup 2751 Feb 10  2021 
> third_party/qemu/scripts/modules/module_block.py

What is the version of meson, and the actual command line? In my case
it's  "/home/.../+build/pyvenv/bin/python3
/home/pbonzini/work/upstream/qemu/block/../scripts/modules/module_block.py
block/module_block.h"..

In case you would like to debug it, here are some pointers. The Meson
code that handles it is, starting from the constructor:

    if search_dirs is None:
        # For compat with old behaviour
        search_dirs = [None]
    self.command = self._search(name, search_dirs, exclude_paths)

The search_dirs list is simply
[os.path.join(self.environment.get_source_dir(), self.subdir)]; see
program_for_siystem in mesonbuild/interpreter/interpreter.py. _search
simply walks the list:

    for search_dir in search_dirs:
        commands = self._search_dir(name, search_dir)
        if commands:
            return commands

and here is when the non-executable case is handled:

    def _search_dir(self, name: str, search_dir: T.Optional[str]) ->
T.Optional[list]:
        if os.path.exists(trial):
            if self._is_executable(trial):
                return [trial]
            # Now getting desperate. Maybe it is a script file that is
            # a) not chmodded executable, or
            # b) we are on windows so they can't be directly executed.
            return self._shebang_to_cmd(trial)

from which you go to

   # Replace python3 with the actual python3 that we are using
   if commands[0] == '/usr/bin/env' and commands[1] == 'python3':
       commands = mesonlib.python_command + commands[2:]
   elif commands[0].split('/')[-1] == 'python3':
       commands = mesonlib.python_command + commands[1:]

and mesonlib.python_command should be the pyvenv Python interpreter.

Paolo


Reply via email to