-
Notifications
You must be signed in to change notification settings - Fork 10
/
setup.py
84 lines (71 loc) · 2.61 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
import os
import pathlib
import shutil
from setuptools import setup, Extension
from setuptools.command.build_ext import build_ext as build_ext_orig
from setuptools.command.build_py import build_py as build_py_orig
from setuptools.command.egg_info import egg_info as egg_info_orig
from pprint import pprint
from sys import platform
class CMakeExtension(Extension):
def __init__(self, name):
# don't invoke the original build_ext for this special extension
super().__init__(name, sources=[])
class build_py(build_py_orig):
def run(self):
self.run_command("build_ext")
return super().run()
class egg_info(egg_info_orig):
def run(self):
cwd = pathlib.Path().absolute()
package_dir = pathlib.Path('Infinispan')
package_dir.mkdir(parents=True, exist_ok=True)
super().run()
class build_ext(build_ext_orig):
def run(self):
for ext in self.extensions:
self.build_cmake(ext)
super().run()
def build_cmake(self, ext):
cwd = pathlib.Path().absolute()
# these dirs will be created in build_py, so if you don't have
# any python sources to bundle, the dirs will be missing
package_dir = pathlib.Path('Infinispan')
package_dir.mkdir(parents=True, exist_ok=True)
build_temp = pathlib.Path(self.build_temp)
build_temp.mkdir(parents=True, exist_ok=True)
extdir = pathlib.Path(self.get_ext_fullpath(ext.name))
extdir.mkdir(parents=True, exist_ok=True)
# example of cmake args
cmake_args = [
'-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=' + str(extdir.parent.absolute()),
]
os.chdir(str(build_temp))
self.spawn(['cmake', str(cwd)] + cmake_args)
if not self.dry_run:
self.spawn(['cmake', '--build', '.'] )
print(os.getcwd())
dirlist=os.listdir('..')
pprint(dirlist)
os.chdir(str(cwd))
if platform == "linux" or platform == "linux2":
lib_prefix="lib"
lib_suffix=".so"
lib_path = 'build/cpp-client/src/cppclient-build/'+lib_prefix+'hotrod'+lib_suffix+".1.0"
elif platform == "darwin":
lib_prefix="lib"
lib_suffix=".dylib"
lib_path = 'build/cpp-client/src/cppclient-build/'+lib_prefix+'hotrod'+".1.0"+lib_suffix
elif platform == "win32":
print("Windows is not yet supported")
quit()
setup(
name='infinispan',
version='0.1',
packages=['Infinispan'],
data_files=[('lib', [lib_path])],
ext_modules=[CMakeExtension('Infinispan/Infinispan')],
cmdclass={
'build_ext': build_ext,
'build_py' : build_py, 'egg_info': egg_info},
)