Created
July 8, 2020 01:51
-
-
Save nico/65ab5319c4e699464590ebff62d0f3f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Works with py2 and py3 | |
import ctypes | |
import os | |
import sys | |
libSystem = ctypes.CDLL('libSystem.dylib') | |
spawn = libSystem.posix_spawnp | |
spawn.restype = ctypes.c_int | |
spawn.argtypes = ( | |
ctypes.POINTER(ctypes.c_int), | |
ctypes.c_char_p, ctypes.c_void_p, ctypes.c_void_p, | |
ctypes.POINTER(ctypes.c_char_p), | |
ctypes.POINTER(ctypes.c_char_p) | |
) | |
def charpp(a): return (ctypes.c_char_p * len(a))(*a) | |
argv = list(map(ctypes.c_char_p, b'git -c core.deltaBaseCacheLimit=2g clone --no-checkout --progress https://chromium.googlesource.com/chromium/src.git _gclient_src_mmdd8v1w'.split())) + [None] | |
envp = [ctypes.c_char_p(('%s=%s' % (k, os.environ[k])).encode('utf-8')) for k in os.environ] + [None] | |
pid = ctypes.c_int() | |
e = spawn(ctypes.byref(pid), ctypes.c_char_p(b"git"), None, None, charpp(argv), charpp(envp)) | |
if e != 0: | |
print('spawn failed') | |
sys.exit(1) | |
os.waitpid(pid.value, 0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment