Idiomatic way to use python scripts in custom_target and similar. #10978
-
https://mesonbuild.com/Use-of-Python.html#cross-platform-tooling suggests that for portability, additional build tooling should be written in Python, since it is (for the time being) a hard dependency of meson. However, I'm not sure what the 'idiomatic' way to use said scripts is. A shebang line ( There's the In my case, the script(s) also need to be run through pymod = import('python')
py3 = pymod.find_installation('python3', required: true)
script = configure_file(...)
custom_target(
# ...
command: [py3, script, ...]) to be a little boilerplate-heavy for more anything more complex than this heavily reduced example. Particularly the (apparent) need to specify the How does meson deal with shebangs on Windows? Are they portable, somehow? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
On Windows, script files are by definition non-executable. On Linux, they are non-executable if they don't have the executable bit. In both cases, Meson will open up the file and scan it for a shebang on the first line, and run the script using the interpreter specified in the shebang. If that interpreter ends in "python3", (including if the shebang uses /usr/bin/env) it will use Meson's own On Linux, if the file has the executable bit, it is simply run as is, which works in most cases, probably even NixOS, as long as you use ... tl;dr Use shebangs, and if you wish to be extra extra extra extra sure, remove the executable bit. |
Beta Was this translation helpful? Give feedback.
On Windows, script files are by definition non-executable. On Linux, they are non-executable if they don't have the executable bit.
In both cases, Meson will open up the file and scan it for a shebang on the first line, and run the script using the interpreter specified in the shebang. If that interpreter ends in "python3", (including if the shebang uses /usr/bin/env) it will use Meson's own
sys.executable
as the interpreter.On Linux, if the file has the executable bit, it is simply run as is, which works in most cases, probably even NixOS, as long as you use
env
to cope with the BSDs where python is in /usr/local/bin, and NixOS where it is presumably inside a store path somewhere and ma…