aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Claessens <xavier.claessens@collabora.com>2022-11-05 10:30:10 -0400
committerXavier Claessens <xavier.claessens@collabora.com>2022-12-07 11:58:35 -0500
commitb926374205bd761085031755c87152d08bc10e9d (patch)
tree6e3f230ffc1540514c9aa9534a855badd705b21c
parentbc2f1fb2f3e4e3601a262facc16313e1852926f0 (diff)
downloadmeson-b926374205bd761085031755c87152d08bc10e9d.zip
meson-b926374205bd761085031755c87152d08bc10e9d.tar.gz
meson-b926374205bd761085031755c87152d08bc10e9d.tar.bz2
devenv: Do not include system values in --dump
This makes --dump print variables like `FOO=/path:$FOO:/another/path`.
-rw-r--r--mesonbuild/mdevenv.py12
-rw-r--r--mesonbuild/utils/core.py15
2 files changed, 14 insertions, 13 deletions
diff --git a/mesonbuild/mdevenv.py b/mesonbuild/mdevenv.py
index 7f9b04e..57972ce 100644
--- a/mesonbuild/mdevenv.py
+++ b/mesonbuild/mdevenv.py
@@ -6,7 +6,7 @@ import itertools
from pathlib import Path
from . import build, minstall, dependencies
-from .mesonlib import MesonException, is_windows, setup_vsenv, OptionKey, quote_arg, get_wine_shortpath
+from .mesonlib import MesonException, is_windows, setup_vsenv, OptionKey, get_wine_shortpath
from . import mlog
import typing as T
@@ -47,15 +47,15 @@ def reduce_winepath(env: T.Dict[str, str]) -> None:
env['WINEPATH'] = get_wine_shortpath([winecmd], winepath.split(';'))
mlog.log('Meson detected wine and has set WINEPATH accordingly')
-def get_env(b: build.Build) -> T.Tuple[T.Dict[str, str], T.Set[str]]:
+def get_env(b: build.Build, dump: bool) -> T.Tuple[T.Dict[str, str], T.Set[str]]:
extra_env = build.EnvironmentVariables()
extra_env.set('MESON_DEVENV', ['1'])
extra_env.set('MESON_PROJECT_NAME', [b.project_name])
- env = os.environ.copy()
+ env = {} if dump else os.environ.copy()
varnames = set()
for i in itertools.chain(b.devenv, {extra_env}):
- env = i.get_env(env)
+ env = i.get_env(env, dump)
varnames |= i.get_names()
reduce_winepath(env)
@@ -141,12 +141,12 @@ def run(options: argparse.Namespace) -> int:
b = build.load(options.builddir)
workdir = options.workdir or options.builddir
- devenv, varnames = get_env(b)
+ devenv, varnames = get_env(b, options.dump)
if options.dump:
if options.devcmd:
raise MesonException('--dump option does not allow running other command.')
for name in varnames:
- print(f'{name}={quote_arg(devenv[name])}')
+ print(f'{name}="{devenv[name]}"')
print(f'export {name}')
return 0
diff --git a/mesonbuild/utils/core.py b/mesonbuild/utils/core.py
index ed413ca..5450cdc 100644
--- a/mesonbuild/utils/core.py
+++ b/mesonbuild/utils/core.py
@@ -119,23 +119,24 @@ class EnvironmentVariables(HoldableObject):
self.envvars.append((self._prepend, name, values, separator))
@staticmethod
- def _set(env: T.Dict[str, str], name: str, values: T.List[str], separator: str) -> str:
+ def _set(env: T.Dict[str, str], name: str, values: T.List[str], separator: str, default_value: T.Optional[str]) -> str:
return separator.join(values)
@staticmethod
- def _append(env: T.Dict[str, str], name: str, values: T.List[str], separator: str) -> str:
- curr = env.get(name)
+ def _append(env: T.Dict[str, str], name: str, values: T.List[str], separator: str, default_value: T.Optional[str]) -> str:
+ curr = env.get(name, default_value)
return separator.join(values if curr is None else [curr] + values)
@staticmethod
- def _prepend(env: T.Dict[str, str], name: str, values: T.List[str], separator: str) -> str:
- curr = env.get(name)
+ def _prepend(env: T.Dict[str, str], name: str, values: T.List[str], separator: str, default_value: T.Optional[str]) -> str:
+ curr = env.get(name, default_value)
return separator.join(values if curr is None else values + [curr])
- def get_env(self, full_env: T.MutableMapping[str, str]) -> T.Dict[str, str]:
+ def get_env(self, full_env: T.MutableMapping[str, str], dump: bool = False) -> T.Dict[str, str]:
env = full_env.copy()
for method, name, values, separator in self.envvars:
- env[name] = method(env, name, values, separator)
+ default_value = f'${name}' if dump else None
+ env[name] = method(env, name, values, separator, default_value)
return env