Repository navigation
Expand file tree
/
Copy pathbuild_attach_binaries.py
More file actions
97 lines (88 loc) · 3.02 KB
/
Copy pathbuild_attach_binaries.py
File metadata and controls
97 lines (88 loc) · 3.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# This script is used for building the pydevd binaries
import argparse
import os
import platform
import re
import subprocess
import sysconfig
def build_pydevd_binaries(force: bool):
os.environ["PYDEVD_USE_CYTHON"] = "yes"
# Attempt to find where Visual Studio is installed if we're running on Windows.
if os.name == "nt":
try:
import vswhere
install_path = vswhere.get_latest_path(prerelease=True)
if install_path is not None:
os.environ["FORCE_PYDEVD_VC_VARS"] = os.path.join(
install_path, "VC", "Auxiliary", "Build", "vcvars64.bat"
)
except ImportError:
pass
# Run the pydevd build command.
pydevd_root = os.path.join(
os.path.dirname(__file__), "src", "debugpy", "_vendored", "pydevd"
)
# Run the appropriate batch script to build the binaries if necessary.
pydevd_attach_to_process_root = os.path.join(
pydevd_root, "pydevd_attach_to_process"
)
if platform.system() == "Windows":
arm64 = sysconfig.get_platform() == "win-arm64"
suffix = "arm64" if arm64 else "amd64"
required = (
f"attach_{suffix}.dll",
f"run_code_on_dllmain_{suffix}.dll",
f"inject_dll_{suffix}.exe",
)
if (
not all(
os.path.exists(os.path.join(pydevd_attach_to_process_root, name))
for name in required
)
or force
):
command = [
os.path.join(
pydevd_attach_to_process_root, "windows", "compile_windows.bat"
)
]
if arm64:
command.append("arm64")
subprocess.check_call(command)
elif platform.system() == "Linux":
arch = platform.machine()
if re.match(r"^i.*86$", arch):
arch = "x86"
if arch == "x86_64":
arch = "amd64"
if (
not os.path.exists(
os.path.join(pydevd_attach_to_process_root, f"attach_linux_{arch}.so")
)
or force
):
os.system(
os.path.join(
pydevd_attach_to_process_root, "linux_and_mac", "compile_linux.sh"
)
)
elif platform.system() == "Darwin":
if (
not os.path.exists(
os.path.join(pydevd_attach_to_process_root, "attach.dylib")
)
or force
):
os.system(
os.path.join(
pydevd_attach_to_process_root, "linux_and_mac", "compile_mac.sh"
)
)
else:
print("unsupported platform.system(): {}".format(platform.system()))
exit(1)
if __name__ == "__main__":
arg_parser = argparse.ArgumentParser(description="Build the pydevd binaries.")
arg_parser.add_argument("--force", action="store_true", help="Force a rebuild")
args = arg_parser.parse_args()
build_pydevd_binaries(args.force)