forked from mahaloz/decomp2dbg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
73 lines (59 loc) · 2.27 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
# pylint: disable=missing-class-docstring
import os
import platform
import shutil
from pathlib import Path
import sys
from distutils.util import get_platform
from distutils.command.build import build as st_build
from setuptools import setup
from setuptools.command.develop import develop as st_develop
def _copy_decomp_plugins():
local_plugins = Path("decompilers").absolute()
decomp2dbg_loc = Path("decomp2dbg").absolute()
pip_e_plugins = decomp2dbg_loc.joinpath("decompilers").absolute()
local_d2d = Path("d2d.py").absolute()
# clean the install location of symlink or folder
try:
shutil.rmtree(pip_e_plugins, ignore_errors=True)
except Exception as e:
print(f"Exception occurred while removing {pip_e_plugins}: {e}")
try:
os.unlink(pip_e_plugins)
os.unlink(decomp2dbg_loc.joinpath(local_d2d.name))
except Exception as e:
print(f"Exception occurred during cleaning of install location: {e}")
# first attempt a symlink, if it works, exit early
try:
os.symlink(local_plugins, pip_e_plugins, target_is_directory=True)
os.symlink(local_d2d, decomp2dbg_loc.joinpath(local_d2d.name))
return
except Exception as e:
print(f"Exception occured during symlinking process: {e}")
# copy if symlinking is not available on target system
try:
shutil.copytree("decompilers", "decomp2dbg/decompilers")
shutil.copy("d2d.py", "decomp2dbg/d2d.py")
except Exception as e:
print(f"Exception occurred during copying process: {e}")
class build(st_build):
def run(self, *args):
self.execute(_copy_decomp_plugins, (), msg="Copying plugins")
super().run(*args)
class develop(st_develop):
def run(self, *args):
self.execute(_copy_decomp_plugins, (), msg="Linking or copying local plugins folder")
super().run(*args)
cmdclass = {
"build": build,
"develop": develop,
}
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)