Skip to content

Commit aab2533

Browse files
committed
limit wrapped-due-to-env special case for env to only apply for env.set
In commit 2cb7350 we added a special case for environment() objects to allow skipping `meson --internal exe` overhead when /usr/bin/env exists and can be used to set environment variables instead of using a pickled wrapper. This special case assumed that environment is used for setting variables, but it is also possible, albeit less common, to append/prepend to them, in which case `meson --internal exe` will compute the final value as an offset from whatever the current environment variables inherited from ninja are. It is not possible to precompute this when generating command lines for ninja, so using arguments to /usr/bin/env is not possible. All it can do is set (override) an environment variable. In this case, we have to use the python wrapper and cannot optimize it away. Add a tracking bit to the env object and propagate it to the backend.
1 parent 1570289 commit aab2533

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mesonbuild/backend/backends.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ def as_meson_exe_cmdline(self, exe: T.Union[str, mesonlib.File, build.BuildTarge
627627
# It's also overridden for a few conditions that can't be handled
628628
# inside a command line
629629

630-
can_use_env = not force_serialize
630+
can_use_env = env.can_use_env and not force_serialize
631631
force_serialize = force_serialize or bool(reasons)
632632

633633
if capture:

mesonbuild/utils/core.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def __init__(self, values: T.Optional[EnvInitValueType] = None,
6464
# The set of all env vars we have operations for. Only used for self.has_name()
6565
self.varnames: T.Set[str] = set()
6666
self.unset_vars: T.Set[str] = set()
67+
self.can_use_env = True
6768

6869
if values:
6970
init_func = getattr(self, init_method)
@@ -95,7 +96,9 @@ def merge(self, other: EnvironmentVariables) -> None:
9596
self.envvars.append((method, name, values, separator))
9697
if name in self.unset_vars:
9798
self.unset_vars.remove(name)
98-
self.unset_vars.update(other.unset_vars)
99+
if other.unset_vars:
100+
self.can_use_env = False
101+
self.unset_vars.update(other.unset_vars)
99102

100103
def set(self, name: str, values: T.List[str], separator: str = os.pathsep) -> None:
101104
if name in self.unset_vars:
@@ -104,17 +107,20 @@ def set(self, name: str, values: T.List[str], separator: str = os.pathsep) -> No
104107
self.envvars.append((self._set, name, values, separator))
105108

106109
def unset(self, name: str) -> None:
110+
self.can_use_env = False
107111
if name in self.varnames:
108112
raise MesonException(f'You cannot unset the {name!r} variable because it is already set')
109113
self.unset_vars.add(name)
110114

111115
def append(self, name: str, values: T.List[str], separator: str = os.pathsep) -> None:
116+
self.can_use_env = False
112117
if name in self.unset_vars:
113118
raise MesonException(f'You cannot append to unset variable {name!r}')
114119
self.varnames.add(name)
115120
self.envvars.append((self._append, name, values, separator))
116121

117122
def prepend(self, name: str, values: T.List[str], separator: str = os.pathsep) -> None:
123+
self.can_use_env = False
118124
if name in self.unset_vars:
119125
raise MesonException(f'You cannot prepend to unset variable {name!r}')
120126
self.varnames.add(name)

0 commit comments

Comments
 (0)