@@ -20,23 +20,25 @@ if(WIN32)
2020 file (TO_NATIVE_PATH "${_XCDSC_LINK} " _XCDSC_LINK_WIN)
2121 file (TO_NATIVE_PATH "${_XCDSC_REAL} " _XCDSC_REAL_WIN)
2222
23- # Ensures %TEMP%\xcdsc is a symlink/junction pointing to XCDSC_TOOLCHAIN_PATH,
24- # creating or replacing it as needed (shell chosen via _CURRENT_SHELL).
23+ # Ensure %TEMP%\xcdsc points to ${_XCDSC_REAL}; recreate only if different.
2524 if (_CURRENT_SHELL STREQUAL "powershell" )
26- message (STATUS "Ensuring junction via PowerShell" )
2725 execute_process (
2826 COMMAND powershell -NoProfile -ExecutionPolicy Bypass -Command
2927 "\$ ErrorActionPreference='Stop'; \$ ConfirmPreference='None';"
3028 "\$ p = Join-Path \$ env:TEMP 'xcdsc';"
3129 "\$ t = '${_XCDSC_REAL} ';"
30+ "function Normalize([string]\$ path){ if(-not \$ path){return \$ null}; [IO.Path]::GetFullPath(\$ path).TrimEnd([IO.Path]::DirectorySeparatorChar,[IO.Path]::AltDirectorySeparatorChar) }"
3231 "if (Test-Path -LiteralPath \$ p) {"
3332 " \$ it = Get-Item -LiteralPath \$ p -Force;"
34- " if (-not (\$ it.Attributes -band [IO.FileAttributes]::ReparsePoint)) {"
35- " if (\$ it.PSIsContainer) {"
36- " Remove-Item -LiteralPath \$ p -Recurse -Force -Confirm:\$ false"
37- " } else {"
38- " Remove-Item -LiteralPath \$ p -Force -Confirm:\$ false"
33+ " if (\$ it.Attributes -band [IO.FileAttributes]::ReparsePoint) {"
34+ " \$ curr = Normalize ((\$ it.Target | Select-Object -First 1));"
35+ " \$ want = Normalize \$ t;"
36+ " if (-not \$ curr -or -not [String]::Equals(\$ curr,\$ want,[StringComparison]::OrdinalIgnoreCase)) {"
37+ " cmd /d /c \" rmdir `\"\$ p`\"\" | Out-Null;" # <-- changed: delete junction via cmd (no prompt)
38+ " New-Item -ItemType Junction -Path \$ p -Target \$ t | Out-Null"
3939 " }"
40+ " } else {"
41+ " if (\$ it.PSIsContainer) { Remove-Item -LiteralPath \$ p -Recurse -Force -Confirm:\$ false } else { Remove-Item -LiteralPath \$ p -Force -Confirm:\$ false }"
4042 " New-Item -ItemType Junction -Path \$ p -Target \$ t | Out-Null"
4143 " }"
4244 "} else {"
@@ -50,34 +52,40 @@ if(WIN32)
5052 message (FATAL_ERROR "Failed to ensure %TEMP%\\ xcdsc junction (PowerShell).\n ${_ps_err} " )
5153 endif ()
5254 else ()
53- message (STATUS "Ensuring junction via Command Prompt" )
54- # Ensures %TEMP%\xcdsc is a symlink/junction to XCDSC_TOOLCHAIN_PATH via cmd,
55- # creating or replacing it as needed.
55+ # Use PowerShell (invoked from cmd) to compare target; recreate only if different.
5656 execute_process (
5757 COMMAND cmd.exe /C
58- "if exist \" ${_XCDSC_LINK_WIN} \" ( "
59- " fsutil reparsepoint query \" ${_XCDSC_LINK_WIN} \" >nul 2>&1 && ( ver >nul ) "
60- " || ( "
61- " if exist \" ${_XCDSC_LINK_WIN} \\ *\" ( "
62- " rmdir /S /Q \" ${_XCDSC_LINK_WIN} \" "
63- " ) else ( "
64- " del /Q /F \" ${_XCDSC_LINK_WIN} \" 2>nul "
65- " ) & "
66- " mklink /J \" ${_XCDSC_LINK_WIN} \" \" ${_XCDSC_REAL_WIN} \" "
67- " ) "
68- ") else ( "
69- " mklink /J \" ${_XCDSC_LINK_WIN} \" \" ${_XCDSC_REAL_WIN} \" "
70- ")"
58+ "powershell -NoProfile -ExecutionPolicy Bypass -Command "
59+ "\"\$ ErrorActionPreference='Stop'; \$ ConfirmPreference='None'; "
60+ "\$ p = Join-Path \$ env:TEMP 'xcdsc'; "
61+ "\$ t = '${_XCDSC_REAL} '; "
62+ "function N([string]\$ x){ if(-not \$ x){return \$ null}; [IO.Path]::GetFullPath(\$ x).TrimEnd([IO.Path]::DirectorySeparatorChar,[IO.Path]::AltDirectorySeparatorChar) } "
63+ "if (Test-Path -LiteralPath \$ p) { "
64+ " \$ it = Get-Item -LiteralPath \$ p -Force; "
65+ " if (\$ it.Attributes -band [IO.FileAttributes]::ReparsePoint) { "
66+ " \$ curr = N ((\$ it.Target | Select-Object -First 1)); "
67+ " \$ want = N \$ t; "
68+ " if (-not \$ curr -or -not [String]::Equals(\$ curr,\$ want,[StringComparison]::OrdinalIgnoreCase)) { "
69+ " cmd /d /c \" rmdir `\"\$ p`\"\" | Out-Null; " # <-- changed: delete junction via cmd (no prompt)
70+ " New-Item -ItemType Junction -Path \$ p -Target \$ t | Out-Null "
71+ " } "
72+ " } else { "
73+ " if (\$ it.PSIsContainer) { Remove-Item -LiteralPath \$ p -Recurse -Force -Confirm:\$ false } else { Remove-Item -LiteralPath \$ p -Force -Confirm:\$ false } "
74+ " New-Item -ItemType Junction -Path \$ p -Target \$ t | Out-Null "
75+ " } "
76+ "} else { "
77+ " New-Item -ItemType Junction -Path \$ p -Target \$ t | Out-Null "
78+ "}\" "
7179 RESULT_VARIABLE _cmd_rv
7280 OUTPUT_VARIABLE _cmd_out
7381 ERROR_VARIABLE _cmd_err
7482 )
7583 if (NOT _cmd_rv EQUAL 0)
76- message (FATAL_ERROR "Failed to ensure %TEMP%\\ xcdsc junction (cmd).\n ${_cmd_err} " )
84+ message (FATAL_ERROR "Failed to ensure %TEMP%\\ xcdsc junction (cmd/PowerShell ).\n ${_cmd_err} " )
7785 endif ()
7886 endif ()
7987
80- # Use the junction for the toolchain
88+ # Use the (possibly newly created) junction for the toolchain
8189 set (XCDSC_TOOLCHAIN_PATH "${_XCDSC_LINK} " )
8290 message (STATUS "XCDSC toolchain (real): ${_XCDSC_REAL} " )
8391 message (STATUS "XCDSC toolchain (via junction): ${XCDSC_TOOLCHAIN_PATH} " )
@@ -99,6 +107,5 @@ else() # Support for picolibc is indicated by the presence of 'picolibc.h' in th
99107 file (GLOB_RECURSE picolibc_header ${XCDSC_TOOLCHAIN_PATH} /include /picolibc/picolibc.h)
100108 if (picolibc_header)
101109 set (TOOLCHAIN_HAS_PICOLIBC ON CACHE BOOL "True if toolchain supports picolibc" )
102- endif ()
110+ endif ()
103111endif ()
104-
0 commit comments