Skip to content

Commit 0e0dc53

Browse files
committed
install: use reg add to avoid setx truncating Windows PATH
INSTALL.bat and UNINSTALL.bat persist the system-wide PATH with 'setx /M', which silently truncates the value it writes to 1024 characters. When installing from a shell with an already long inherited PATH, such as a Visual Studio Developer Prompt, this drops the tail of the persisted PATH, which can remove entries required to even start cmd.exe or powershell.exe in a later session. Use 'reg add' on the same registry key instead, which has no such limit and requires the same administrator privilege setx already needed. Mark these Windows batch scripts, which intentionally carry carriage-return line endings, with the cr-at-eol whitespace attribute so the pre-commit hook stops flagging their line endings as trailing whitespace. Extend the native-cmd CI job to replace the inherited PATH with a controlled value past the legacy 1024-character limit before installing, then check the persisted registry PATH afterward, so a regression here gets caught automatically. The replacement keeps the length controlled and safely under the 8191-character command line length limit of cmd.exe, rather than extending the runner's own already large inherited PATH and risking hitting that separate limit. Fixes #654 Assisted-by: Claude:claude-sonnet-5 Signed-off-by: Xavier Delaruelle <xavier.delaruelle@cea.fr>
1 parent 4a96a66 commit 0e0dc53

7 files changed

Lines changed: 46 additions & 4 deletions

File tree

.gitattributes

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ script/pre-commit export-ignore
2323
# Scorecard entirely
2424
# no export of website-specific content
2525
doc/talk export-ignore
26+
# these Windows batch scripts intentionally use CRLF line endings, do not
27+
# flag the CR as a trailing whitespace error
28+
script/INSTALL.bat whitespace=cr-at-eol
29+
script/UNINSTALL.bat whitespace=cr-at-eol

.github/workflows/windows_tests.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,31 @@ jobs:
4848
run: |
4949
jar xvf %DIST_WIN%.zip
5050
cd %DIST_WIN%
51-
INSTALL.bat
51+
:: replace (rather than extend) the inherited PATH with a
52+
:: controlled value that is still past the legacy 1024-character
53+
:: limit of the 'setx' tool previously used here, to simulate a
54+
:: large pre-existing PATH such as found in a Visual Studio
55+
:: Developer Prompt (see GH-654), while staying safely under the
56+
:: 8191-character command line length limit of cmd.exe
57+
setlocal enabledelayedexpansion
58+
set "PATH=%SYSTEMROOT%\system32;%SYSTEMROOT%"
59+
for /L %%i in (1,1,50) do set "PATH=!PATH!;C:\dummy-path-segment-%%i"
60+
set "PATH=!PATH!;C:\marker-end-of-long-path"
61+
call INSTALL.bat
62+
- name: Check persisted PATH is not truncated
63+
shell: cmd
64+
run: |
65+
reg query "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH > persisted-path.txt
66+
%SYSTEMROOT%\system32\find /i "marker-end-of-long-path" persisted-path.txt >nul
67+
if errorlevel 1 (
68+
echo "persisted system PATH truncated: marker entry not found"
69+
exit /b 1
70+
)
71+
%SYSTEMROOT%\system32\find /i "%MODULE_DIR%" persisted-path.txt >nul
72+
if errorlevel 1 (
73+
echo "installation 'bin' directory not found in persisted system PATH"
74+
exit /b 1
75+
)
5276
- name: Test Modules installation
5377
shell: cmd
5478
run: |

.hunspell.en.dic

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,7 @@ setState
736736
setenv
737737
setgid
738738
setq
739+
setx
739740
severities
740741
sexualized
741742
sgr

NEWS.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ Modules 5.7.0 (not yet released)
173173
white matte color instead of black.
174174
* Doc: document Windows Terminal profile setup as an alternative way to
175175
initialize Modules on Windows without an install script. (fix issue #634)
176+
* Install: use ``reg add`` instead of ``setx /M`` to persist the system-wide
177+
``PATH`` environment variable in :file:`INSTALL.bat` and
178+
:file:`UNINSTALL.bat`, as ``setx`` silently truncates the value it writes
179+
to 1024 characters, which could corrupt the system ``PATH`` when installing
180+
from a shell with an already long inherited ``PATH`` (e.g. a Visual Studio
181+
Developer Prompt). (fix issue #654)
176182

177183

178184
.. _5.6 release notes:

doc/source/devel/ci.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,10 @@ on Windows:
107107
<https://www.bawt.tcl3d.org/>`_), built via ``make dist-win`` and
108108
installed/tested/uninstalled through the generated
109109
:file:`INSTALL.bat`/:file:`TESTINSTALL.bat`/:file:`UNINSTALL.bat`
110-
scripts, driven from a ``cmd`` shell.
110+
scripts, driven from a ``cmd`` shell. Before installing, the inherited
111+
``PATH`` is padded past the legacy 1024-character limit of the
112+
``setx`` tool (mimicking a Visual Studio Developer Prompt) to guard
113+
against the persisted system ``PATH`` getting silently truncated.
111114
``native-pwsh``
112115
Same native Windows install, but through the PowerShell variant
113116
(:file:`INSTALL_PWSH.bat`/:file:`TESTINSTALL_PWSH.ps1`).

script/INSTALL.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ set FIND=%SYSTEMROOT%\system32\find
2323
echo %PATH% | %FIND% /i "%binpath:"=%">nul || set "NEWPATH=%binpath%;%PATH%"
2424
if not "%NEWPATH%" == "" (
2525
set "PATH=%NEWPATH%"
26-
setx /M PATH "%NEWPATH%"
26+
:: 'reg add' is used instead of 'setx /M' as the latter silently
27+
:: truncates the value it persists to 1024 characters
28+
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH /t REG_EXPAND_SZ /d "%NEWPATH%" /f
2729
)
2830
if errorlevel 1 ( exit /b 3 )
2931

script/UNINSTALL.bat

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ setlocal enableextensions enabledelayedexpansion
1313
set "NEWPATH=!PATH:%binpath%;=!"
1414
if not "%NEWPATH%" == "%PATH%" (
1515
set "PATH=%NEWPATH%"
16-
setx /M PATH "%NEWPATH%"
16+
:: 'reg add' is used instead of 'setx /M' as the latter silently
17+
:: truncates the value it persists to 1024 characters
18+
reg add "HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment" /v PATH /t REG_EXPAND_SZ /d "%NEWPATH%" /f
1719
)
1820
if errorlevel 1 ( exit /b 1 )
1921

0 commit comments

Comments
 (0)