xtd
xtd copied to clipboard
[BUG] Path not updated with xtd on Windows
Describe the bug
I installed Visual Studio Community 2022 and cmake. I then cloned the xtd repository and attempted to build it. The build ran for a long time, then produced the following output;
--snip--
-- Up-to-date: C:/Program Files (x86)/xtd/share/xtd/themes/xtd_light/system-colors.css
-- Up-to-date: C:/Program Files (x86)/xtd/share/xtd/themes/xtd_light/theme.css
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
Microsoft (R) Windows Script Host Version 5.812
Copyright (C) Microsoft Corporation. All rights reserved.
1024 was unexpected at this time.
C:\Users\jimor\Projects\xtd>
I tried to build a simple app using;
xtdc build
but I get;
'xtdc' is not recognized as an internal or external command,
operable program or batch file.
To Reproduce
As described above.
Expected behaviour
xtd install to complete without errors and simple xtd based app to build.
Screenshots
N/A
Desktop (please complete the following information)
- OS: Windows
- Version: 10
- xtd version: latest from master
Additional context
none
Workaround
None known
Defect
This error is related to the calculation of the size of the path (added rexement) which returns an empty string instead of the size. So there is an error during the test. So the path is never updated. I still have to investigate. If there is no satisfactory solution, always ask the user to add the path manually as when the path exceeds 1024 characters.
Workaround
Add c:\Program Files\xtd\bin
or c:\Program Files (x86)\xtd\bin
(depends on where xtd is installed by your cmake version) to the user path manually.
Here is the problematic piece of code in install.cmd :
::______________________________________________________________________________
:: Add xtdc-gui path
echo.%path%|findstr /C:"xtd\bin" >nul 2>&1
if not errorlevel 1 (
echo The environment variable path already contains xtd.
) else (
set new_path="%cmake_install_prefix%\xtd\bin;%path%"
call :strlen new_path path_length
if %path_length% LSS 1024 (
setx path %new_path%
) else (
echo.
echo ---------------------------------------------------------------
echo.
echo WARNING : The path is greater than 1024.
echo.
echo setx will not work correctly with a path greater than 1024.
echo Manually add "%cmake_install_prefix%\xtd\bin" in your path.
echo.
echo ---------------------------------------------------------------
echo.
pause
)
)
::______________________________________________________________________________
:: launch xtdc-gui
echo Launching xtdc-gui...
start "xtdc-gui" "%cmake_install_prefix%\xtd\bin\xtdc-gui.exe"
goto :eof
::______________________________________________________________________________
:: Gets the length of specified string.
:: param string_var The string to compute length.
:: param result_var That will cantains the length of the specified string.
:strlen string_var [result_var]
setlocal EnableDelayedExpansion
set "s=#!%~1!"
set "len=0"
for %%N in (4096 2048 1024 512 256 128 64 32 16 8 4 2 1) do (
if "!s:~%%N,1!" neq "" (
set /a "len+=%%N"
set "s=!s:~%%N!"
)
)
endlocal&if "%~2" neq "" (set %~2=%len%) else echo %len%
exit /b
Error
Line 6 : get the length of new_path Line 7 : Test if new_length is less than 1024 -> error in the script because new_length is empty !
Remarks
The strlen "function" was found here : https://ss64.com/nt/syntax-strlen.html
I'm going to try to do it myself, finally.
I create a new tool set_path to add the xtd installation path to the user path.