Skip to content

Commit 3b9ca00

Browse files
authored
Merge pull request #27785 from drodriguez/windows-update-checkout-symlink
[windows] Provide a symlink alternative for Windows.
2 parents 781b1b1 + ce1382c commit 3b9ca00

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

utils/update_checkout/update_checkout/update_checkout.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,28 @@ def skip_list_for_platform(config):
400400
return skip_list
401401

402402

403+
# Python 2.7 in Windows doesn't support os.symlink
404+
os_symlink = getattr(os, "symlink", None)
405+
if callable(os_symlink):
406+
pass
407+
else:
408+
def symlink_ms(source, link_name):
409+
source = os.path.normpath(source)
410+
link_name = os.path.normpath(link_name)
411+
if os.path.isdir(link_name):
412+
os.rmdir(link_name)
413+
elif os.exists(link_name):
414+
os.remove(link_name)
415+
import ctypes
416+
csl = ctypes.windll.kernel32.CreateSymbolicLinkW
417+
csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
418+
csl.restype = ctypes.c_ubyte
419+
flags = 1 if os.path.isdir(source) else 0
420+
if csl(link_name, source, flags) == 0:
421+
raise ctypes.WinError()
422+
os.symlink = symlink_ms
423+
424+
403425
def symlink_llvm_monorepo(args):
404426
print("Create symlink for LLVM Project")
405427
llvm_projects = ['clang',

0 commit comments

Comments
 (0)