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'
pull/8176/head
Eli Schwartz 4 years ago committed by Xavier Claessens
parent a590cfde0c
commit 2cb7350d16
  1. 19
      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, ''

Loading…
Cancel
Save