-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.py
executable file
·224 lines (181 loc) · 6.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#! /usr/bin/python
import urllib2
import tarfile
import zipfile
import sys, os
import platform
import glob
import subprocess
import shutil
import argparse
### Establish our system
isLinux = platform.system() == 'Linux'
isWindows = os.name == 'nt'
isMac = platform.system() == 'Darwin'
### Parse command line arguments
parser = argparse.ArgumentParser(usage = 'Usage: %(prog)s <options> release|debug', description='')
parser.add_argument('-a', '--architecture', help='The architecture type')
parser.add_argument('buildType', nargs='?', default='release', help='The build type to setup for - must be either "release" or "debug"')
parser.add_argument('compiler', nargs='?', default=None, help='The to use (i.e. gcc, clang, etc)')
architecture = 'x64'
buildType = None
compiler = 'gcc'
compilerVersion = '6'
platform = 'linux'
sharedLibraryExt = 'so'
staticLibraryExt = 'a'
extension = 'tar.gz'
downloadDepsUrl = 'https://artifact-repo.icebreakersentertainment.com/files'
dependenciesDirectory = 'deps/'
librariesDirectory = 'lib/'
# Set defaults
if isWindows:
architecture = 'x64'
compiler = 'msvc'
platform = 'windows'
sharedLibraryExt = 'dll'
staticLibraryExt = 'lib'
extension = 'zip'
if isMac:
compiler = 'clang'
compilerVersion = '8'
platform = 'mac'
sharedLibraryExt = 'dylib'
args = parser.parse_args()
if args.architecture is not None:
architecture = args.architecture
if args.compiler is not None:
compiler = args.compiler
buildType = args.buildType
if (buildType != 'release' and buildType != 'debug'):
print('Invalid buildType - must be either "release" or "debug"')
exit()
if (architecture is not None and architecture != 'x86' and architecture != 'x64'):
print('Invalid architecture - must be either "x86" or "x64"')
exit()
if (compiler is not None and compiler != 'gcc' and compiler != 'clang' and compiler != 'msvc'):
print('Invalid compiler - must be either "gcc", "clang" or "msvc"')
exit()
### Validate the architecture
if (architecture == 'x86' and isLinux):
print('x86 architecture is not yet implemented in setup.py for Linux - sorry!')
exit()
if (architecture == 'x86' and isWindows):
print('x86 architecture is not yet implemented in setup.py for Windows - sorry!')
exit()
if (architecture == 'x86' and isMac):
print('x86 architecture is not yet implemented in setup.py for Mac - sorry!')
exit()
### Validate the compiler
if (compiler == 'msvc' and isLinux):
print('msvc compiler is not available for Linux')
exit()
if (compiler == 'msvc' and isMac):
print('msvc compiler is not available for Mac')
exit()
if (compiler == 'msvc'):
compilerVersion = '16'
if (compiler == 'clang'):
compilerVersion = '8'
# Debug not ready yet...
if (buildType == 'debug'):
print('Debug build type is not ready yet - sorry!')
exit()
print('Setup running')
print('-------------')
print(' Platform: ' + platform)
print('Build Type: ' + buildType)
print(' Compiler: ' + compiler + ' (Version ' + compilerVersion + ')')
print('')
dependencies = dict()
dependencies['boost'] = {'name': 'Boost', 'version': '1.68.0', 'extension': extension}
dependencies['glm'] = {'name': 'GLM', 'version': '0.9.8.3', 'extension': extension}
dependencies['angelscript'] = {'name': 'Angelscript', 'version': '2.32.0', 'extension': extension}
dependencies['assimp'] = {'name': 'Asset Importer', 'version': 'v5.0.1', 'extension': extension}
dependencies['entityx'] = {'name': 'Entityx', 'version': 'master', 'extension': extension}
dependencies['glew'] = {'name': 'GLEW', 'version': '2.1.0', 'extension': extension}
dependencies['sdl'] = {'name': 'SDL', 'version': '2.0.8', 'extension': extension}
dependencies['ctpl'] = {'name': 'CTPL', 'version': 'master', 'extension': extension}
dependencies['freeimage'] = {'name': 'Free Image', 'version': '3.18.0', 'extension': extension}
dependencies['celero'] = {'name': 'Celero', 'version': 'v2.1.0', 'extension': extension}
def getFilename(name, version):
return '{0}_{1}_{2}_{3}{4}.{5}'.format(
name,
version,
buildType,
compiler,
compilerVersion,
extension
)
def copyFile(fromFile, toFile):
try:
shutil.copy(fromFile, toFile)
except:
pass
def copyDirectory(fromDirectory, toDirectory):
try:
shutil.copytree(fromDirectory, toDirectory)
except:
#print('Failed to copy directory!')
pass
def checkSystemDependencies():
"""Check for required system dependencies, and if they are not present, inform the user and quit"""
if isLinux:
packages = ['build-essential']
for p in packages:
devNull = open(os.devnull, "w")
retVal = subprocess.call(["dpkg", "-s", p], stdout = devNull, stderr = subprocess.STDOUT)
devNull.close()
if (retVal != 0):
print("Required package '{0}' is not installed. You will need to install it before you can run setup.py.".format(p))
sys.exit(1)
# TODO: Implement this?
def installSystemDependencies():
"""Install any system libraries we require"""
pass
def download():
"""Download external library files"""
if (not os.path.exists(dependenciesDirectory)):
os.makedirs(dependenciesDirectory)
for k in dependencies.keys():
print('Downloading ' + dependencies[k]['name'])
filename = getFilename(k, dependencies[k]['version'])
url = '{0}/{1}/{2}/{3}'.format(downloadDepsUrl, k, platform, filename)
print('url: ' + url)
response = urllib2.urlopen(url)
contentLength = response.headers["Content-Length"]
data = ''
chunk = 4096
savedSize = 0
with open(dependenciesDirectory + filename, 'wb+') as f:
while True:
data = response.read(chunk)
if not data:
print("\n")
break
f.write( bytearray(data) )
savedSize += len(data)
sys.stdout.write( "\rRead {0} / {1} KB".format(((savedSize)/1000), int(contentLength)/1000) )
sys.stdout.flush()
def extract():
"""Extract external library files"""
for k in dependencies.keys():
name = dependencies[k]['name']
print('Extracting ' + name)
filename = dependenciesDirectory + getFilename(k, dependencies[k]['version'])
if not isWindows:
with tarfile.TarFile.open(filename, 'r:gz') as f:
f.extractall(path=dependenciesDirectory)
folders = [f for f in glob.glob(dependenciesDirectory + k + '*') if os.path.isdir(f)]
for f in folders:
os.rename(f, dependenciesDirectory+k)
else:
with zipfile.ZipFile(filename) as f:
f.extractall(path=dependenciesDirectory)
folders = [f for f in glob.glob(dependenciesDirectory + k + '*') if os.path.isdir(f)]
for f in folders:
os.rename(f, dependenciesDirectory+k)
#checkSystemDependencies()
installSystemDependencies()
download()
extract()