From 0b95cd3029747da1ed89fc79317bfa0165c5e3a8 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 bd5e2feda4b..79dd985e579 100755 --- a/configure.py +++ b/configure.py @@ -3209,6 +3209,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(str(sVal)); + def write(self, sKey, oVal = None): """ Writes an environment variable appropriate for the platform. @@ -3220,12 +3228,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): """