Skip to content

Commit ce1382c

Browse files
committed
[windows] Provide a symlink alternative for Windows.
Python 2.7 in Windows do not have os.symlink. Provide one by using Win32 API, and try to match the behaviour that seems to be implied by the Unix implementation (meaning, the destination is removed before the symlink is created).
1 parent 7b5dfd6 commit ce1382c

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
@@ -399,6 +399,28 @@ def skip_list_for_platform(config):
399399
return skip_list
400400

401401

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

0 commit comments

Comments
 (0)