From b25c5cddd109ff44aa2f020a1e996cbe1c0d1015 Mon Sep 17 00:00:00 2001 From: Roberto Nibali Date: Wed, 8 Jul 2026 13:13:09 +0200 Subject: [PATCH] configure: quote generated shell environment values Quote non-Windows env.sh values when writing generated build environment files. This keeps source ./env.sh working when inherited environment values such as PATH contain spaces. Windows env.bat output is left unchanged. Signed-off-by: Roberto Nibali --- configure.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/configure.py b/configure.py index da9479cef962..52a3563d52e7 100755 --- a/configure.py +++ b/configure.py @@ -3205,6 +3205,14 @@ def __init__(self, asFilename, enmBuildTarget = None, oEnvMgr = None, cchKeyAlig super().__init__(asFilename, enmBuildTarget, oEnvMgr, cchKeyAlign); self.sKeyword = 'set' if enmBuildTarget == BuildTarget.WINDOWS else 'export'; + def formatValue(self, sVal): + """ + Formats an environment variable value for the target shell. + """ + if self.enmBuildTarget == BuildTarget.WINDOWS: + return sVal; + return shlex.quote(sVal); + def write(self, sKey, oVal = None): """ Writes an environment variable appropriate for the platform. @@ -3216,12 +3224,12 @@ def write(self, sKey, oVal = None): sValStr = ' '.join(map(str, oVal)); else: sValStr = str(oVal); - super().write_raw(f"{self.sKeyword} {sKey}={sValStr}"); + super().write_raw(f"{self.sKeyword} {sKey}={self.formatValue(sValStr)}"); return; if sKey in self.oEnvMgr.env \ and sKey is not None: - super().write_raw(f"{self.sKeyword} {sKey}={oVal if oVal else self.oEnvMgr[sKey]}"); + super().write_raw(f"{self.sKeyword} {sKey}={self.formatValue(oVal if oVal else self.oEnvMgr[sKey])}"); def write_all(self, asPrefixInclude = None, asPrefixExclude = None): """