On 4/23/23 3:08 PM, Richard Hughes wrote:
> I'm currently using:
>
> cmdpy = find_program(join_paths(meson.project_source_root(), 'cmd.py'))
> cmd = generator(cmdpy,
> output : ['@BASENAME@-struct.c', '@BASENAME@-struct.h'],
> arguments : ['@INPUT@', '@OUTPUT0@', '@OUTPUT1@'],
> )
>
> ...but this is being run by the system python, rather than the
> configured python install (e.g. what
> import('python').find_installation('python3')) would detect. Using the
> system python version doesn't work on macos and freebsd like it does
> on Linux.
When using find_program on the script:
- join_paths is unnecessary here, probably, because it will be found
relative to the current meson.build file first
- if the cmd.py is an executable file, it will be run as-is, regardless
of the shebang and what programming language it is written in
- if the cmd.py is not an executable file, meson will parse the shebang,
and specially handle "python3" to run it with the same version of
python that meson itself uses, to guarantee that python scripts always
work (even on Windows, where python may not be installed)
When using find_installation with the "python3" argument, meson will
find a literal "python3" executable on PATH and use that as the command.
This is effectively the same as the `#!/usr/bin/env python3` approach.
But the latter also respects machine file overrides.
Does this script need non-stdlib modules?
--
Eli Schwartz