-
Notifications
You must be signed in to change notification settings - Fork 21
/
setup.py
92 lines (68 loc) · 2.45 KB
/
setup.py
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
# pylint: disable=missing-class-docstring
import glob
import os
import platform
import shutil
import subprocess
import sys
import pathlib
from distutils.command.build import build as st_build
from distutils.util import get_platform
import pkg_resources
from setuptools import Command, setup
from setuptools.command.develop import develop as st_develop
from setuptools.errors import LibError
def _build_support_libraries():
env = os.environ.copy()
env["CMAKE_GENERATOR"] = "Ninja"
curr_dir = pathlib.Path(__file__).parent.absolute()
tcp_udp_dir = os.path.join(curr_dir, "archr", "implants", "udp_tcp_convert")
build_dir = os.path.join(tcp_udp_dir, "build")
if os.path.exists(build_dir):
shutil.rmtree(build_dir)
subprocess.run(["cmake", ".", "-Bbuild"], cwd=tcp_udp_dir, env=env, check=True)
subprocess.run(["ninja"], cwd=build_dir, env=env, check=True)
shutil.copy(os.path.join(build_dir, "lib", "libudp_to_tcp.so"), tcp_udp_dir)
def _clean_support_libraries():
curr_dir = pathlib.Path(__file__).parent.absolute()
build_dir = os.path.join(curr_dir, "archr", "implants", "udp_tcp_convert", "build")
shutil.rmtree(build_dir, ignore_errors=True)
class build(st_build):
def run(self, *args):
self.execute(_build_support_libraries, (), msg="Building Archr support libraries")
super().run(*args)
class clean_native(Command):
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
self.execute(_clean_support_libraries, (), msg="Cleaning up build directories")
class develop(st_develop):
def run(self):
self.run_command("build")
super().run()
cmdclass = {
"build": build,
"clean_native": clean_native,
"develop": develop,
}
try:
from setuptools.command.editable_wheel import editable_wheel as st_editable_wheel
class editable_wheel(st_editable_wheel):
def run(self):
self.run_command("build")
super().run()
cmdclass["editable_wheel"] = editable_wheel
except ModuleNotFoundError:
pass
if "bdist_wheel" in sys.argv and "--plat-name" not in sys.argv:
sys.argv.append("--plat-name")
name = get_platform()
if "linux" in name:
sys.argv.append("manylinux2014_" + platform.machine())
else:
# https://www.python.org/dev/peps/pep-0425/
sys.argv.append(name.replace(".", "_").replace("-", "_"))
setup(cmdclass=cmdclass)