find_program: use Meson's Python3 for non-executable Python scripts

Whenever a non-executable Python script is found by find_program, currently
Haiku and Windows replace a python3 from the shebang line with the one that
was used by Meson.  Extend this behavior to POSIX systems so that it is
easy to test a program with multiple Python versions.

Currently this is particularly important for generators, because
they don't allow files in the arguments and thus you cannot do
something like

   g = generator(pymod.find_installation(), ...,
                 arguments: [files('myscript.py'), ...])

With this patch, instead, you can just do

   g = generator(find_program('myscript.py'), ...)
pull/5131/head
Paolo Bonzini 6 years ago committed by Jussi Pakkanen
parent f46b485fc2
commit 0078d808a2
  1. 6
      mesonbuild/dependencies/base.py

@ -1993,6 +1993,12 @@ class ExternalProgram:
# We know what python3 is, we're running on it
if len(commands) > 0 and commands[0] == 'python3':
commands = mesonlib.python_command + commands[1:]
else:
# 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:]
return commands + [script]
except Exception as e:
mlog.debug(e)

Loading…
Cancel
Save