diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2021-03-18 23:54:59 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2022-10-09 08:03:58 -0400 |
commit | 2cb7350d1679fb61826bf4aebfb0f75a9b9103e3 (patch) | |
tree | 0a84ac22b37164a51a4ddb95d20f014999375656 | |
parent | a590cfde0cf719c637b75e4784be0c0ae60e3b1f (diff) | |
download | meson-2cb7350d1679fb61826bf4aebfb0f75a9b9103e3.zip meson-2cb7350d1679fb61826bf4aebfb0f75a9b9103e3.tar.gz meson-2cb7350d1679fb61826bf4aebfb0f75a9b9103e3.tar.bz2 |
run wrapped-due-to-env commands on unix via the env program
First, check if the env program exists. If it does, it is faster than
doing it via a python script `basically-env.py` that maybe imports all
of mesonbuild.* as a side effect of project structure.
We do not, however, use env for setting up PATH additions, since env can
override an environment variable but not extend it. So in that case we
still need to wrap the command via python.
By default, all run_targets (at least) are wrapped and now wrap via the
`env` program as they export e.g.
MESONINTROSPECT='/usr/bin/meson introspect'
-rw-r--r-- | mesonbuild/backend/backends.py | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py index 2520f0a..8943464 100644 --- a/mesonbuild/backend/backends.py +++ b/mesonbuild/backend/backends.py @@ -23,6 +23,7 @@ import json import os import pickle import re +import shutil import typing as T import hashlib @@ -584,9 +585,19 @@ class Backend: if any('\n' in c for c in es.cmd_args): reasons.append('because command contains newlines') - if es.env and es.env.varnames: + if env and env.varnames: reasons.append('to set env') + # force_serialize passed to this function means that the VS backend has + # decided it absolutely cannot use real commands. This is "always", + # because it's not clear what will work (other than compilers) and so + # we don't bother to handle a variety of common cases that probably do + # work. + # + # It's also overridden for a few conditions that can't be handled + # inside a command line + + can_use_env = not force_serialize force_serialize = force_serialize or bool(reasons) if capture: @@ -594,6 +605,12 @@ class Backend: if feed: reasons.append('to feed input') + if can_use_env and reasons == ['to set env'] and shutil.which('env'): + envlist = [] + for k, v in env.get_env({}).items(): + envlist.append(f'{k}={v}') + return ['env'] + envlist + es.cmd_args, ', '.join(reasons) + if not force_serialize: if not capture and not feed: return es.cmd_args, '' |