Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / lldb / test / API / get_darwin_real_python.py
blob63bd08bcff89e1105daebba8e1d79b280f7fd8cc
1 # On macOS, system python binaries like /usr/bin/python and $(xcrun -f python3)
2 # are shims. They do some light validation work and then spawn the "real" python
3 # binary. Find the "real" python by asking dyld -- sys.executable reports the
4 # wrong thing more often than not. This is also useful when we're running under
5 # a Homebrew python3 binary, which also appears to be some kind of shim.
6 def getDarwinRealPythonExecutable():
7 import ctypes
9 dyld = ctypes.cdll.LoadLibrary("/usr/lib/system/libdyld.dylib")
10 namelen = ctypes.c_ulong(1024)
11 name = ctypes.create_string_buffer(b"\000", namelen.value)
12 dyld._NSGetExecutablePath(ctypes.byref(name), ctypes.byref(namelen))
13 return name.value.decode("utf-8").strip()
16 print(getDarwinRealPythonExecutable())