-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModule.py
More file actions
252 lines (198 loc) · 9 KB
/
Module.py
File metadata and controls
252 lines (198 loc) · 9 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
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import os
import hashlib
def sha512(fname):
hash = hashlib.sha512()
with open(fname, "rb") as f:
for chunk in iter(lambda: f.read(4096), b""):
hash.update(chunk)
return hash.hexdigest()
class Module:
def __init__(self, name, type, cwd, compile_config, working_directory, modules, hashes):
self.name = name
self.type = type
self.source_files = []
self.header_files = []
self.object_files = []
self.reflection_src_files = []
self.cwd = cwd
self.compile_config = compile_config
self.working_directory = working_directory
self.modules = modules
self.hashes = hashes
self.directory = ''
self.generated_reflection_objs = []
self.forceCompile = False
def generateReflection(self):
for h in self.header_files:
# try:
# subprocess.call(['bin/ReflectionGenerator.exe', '-b bin', '-i ' + h, '-cwd ' + self.cwd])
# except:
# print(os.sys.exc_info())
splitted = h.split(os.sep)
res = ''
for i in range(1, len(splitted) - 1):
res += splitted[i] + '\\'
res += splitted[len(splitted) - 1].split('.')[0] + '.Generated.cpp'
if os.path.isfile(self.cwd + '/__generated_reflection__/' + res):
self.reflection_src_files.append(res)
def compileWhole(self, lib_updated, process):
flags = ''
defs = ''
whole_compile = False
includes = ''
libs = ''
for key in self.compile_config['flags']:
flags += key + ' '
for key in self.compile_config['definitions']:
defs += '/D' + key + ' '
for key in self.compile_config['includes']:
key = key.replace('$CWD$', self.cwd)
includes += '/I"' + key + '" '
for key in self.compile_config['lib_paths']:
key = key.replace('$CWD$', self.cwd)
libs += '/LIBPATH:"' + key + '" '
for key in self.compile_config['libs']:
libs += key + ' '
for key in self.modules:
if key['type'] == 'lib':
libs += key['name'] + '.lib '
for src in self.reflection_src_files:
splitted = src.split(os.sep)
dir_ = self.cwd + '/' + self.working_directory
obj_dir = ''
for s in range(0, len(splitted) - 1):
dir_ += '/' + splitted[s]
obj_dir += splitted[s] + '/'
if os.path.isdir(dir_):
process.WriteInput('cd ' + dir_)
process.Wait()
else:
os.mkdir(dir_)
process.WriteInput('cd ' + dir_)
process.Wait()
compile = True
found = False
res = ''
for i in range(0, len(splitted) - 1):
res += splitted[i]
if i < len(splitted) - 2:
res += '/'
for key in self.hashes:
if key['folder'] == res:
found = True
found2 = False
for f in key['files']:
if f['filename'] == os.path.basename(src):
found2 = True
if f['hash'] == sha512(self.cwd + '/__generated_reflection__/' + src):
compile = False
break
else:
f['hash'] = sha512(self.cwd + '/__generated_reflection__/' + src)
if not found2:
key['files'].append({ 'filename': os.path.basename(src), 'hash': sha512(self.cwd + '/__generated_reflection__/' + src) })
else:
break
if not found:
self.hashes.append({ 'folder': res, 'files': [{ 'filename': os.path.basename(src), 'hash': sha512(self.cwd + '/__generated_reflection__/' + src) }] })
if compile or not os.path.isfile(dir_ + '/' + splitted[len(splitted) - 1].split('.')[0] + '.Generated.obj'):
whole_compile = True
process.WriteInput('cl ' + flags + ' ' + defs + ' ' + includes + ' /c ' + self.cwd + '/__generated_reflection__/' + src)
process.Wait()
if process.WasError():
print("Error while compiling gen obj:", process.GetErrorMessage())
process.SetError(False)
process.WriteInput('cd ' + self.cwd + '/' + self.working_directory)
process.Wait()
obj = self.working_directory + '/' + obj_dir + splitted[len(splitted) - 1].split('.')[0] + '.Generated.obj'
self.object_files.append(obj)
self.generated_reflection_objs.append(obj)
for src in self.source_files:
splitted = src.split(os.sep)
dir_ = self.cwd + '/' + self.working_directory
obj_dir = ''
for s in range(1, len(splitted) - 1):
dir_ += '/' + splitted[s]
obj_dir += splitted[s] + '/'
if os.path.isdir(dir_):
process.WriteInput('cd ' + dir_)
process.Wait()
else:
os.mkdir(dir_)
process.WriteInput('cd ' + dir_)
process.Wait()
compile = True
found = False
res = ''
for i in range(0, len(splitted) - 1):
res += splitted[i]
if i < len(splitted) - 2:
res += '/'
for key in self.hashes:
if key['folder'] == res:
found = True
found2 = False
for f in key['files']:
if f['filename'] == os.path.basename(src):
found2 = True
if f['hash'] == sha512(src):
compile = False
break
else:
f['hash'] = sha512(src)
if not found2:
key['files'].append({ 'filename': os.path.basename(src), 'hash': sha512(src) })
else:
break
if not found:
self.hashes.append({ 'folder': res, 'files': [{ 'filename': os.path.basename(src), 'hash': sha512(src) }] })
if compile or not os.path.isfile(dir_ + '/' + splitted[len(splitted) - 1].split('.')[0] + '.obj'):
whole_compile = True
process.WriteInput('cl ' + flags + ' ' + defs + ' ' + includes + ' /c ' + self.cwd + '/' + src)
process.Wait()
if process.WasError():
print("Error while compiling obj:", process.GetErrorMessage())
process.SetError(False)
process.WriteInput('cd ' + self.cwd + '/' + self.working_directory)
process.Wait()
self.object_files.append(self.working_directory + '/' + obj_dir + splitted[len(splitted) - 1].split('.')[0] + '.obj')
if whole_compile or lib_updated or self.forceCompile:
obj_files = ''
for o in self.object_files:
obj_files += self.cwd + '/' + o + ' '
process.WriteInput('cd ' + self.cwd + '/' + self.working_directory + '/' + self.name)
process.Wait()
if self.type == 'lib':
lib_updated = True
process.WriteInput('lib ' + obj_files + '/OUT:' + self.cwd + '/bin/' + self.name + '.lib')
process.Wait()
if process.WasError():
print("Error while compiling lib:", process.GetErrorMessage())
process.SetError(False)
elif self.type == 'dll':
for key in self.compile_config['dll']:
flags += key + ' '
process.WriteInput('cl ' +
flags + ' ' +
defs + ' ' +
includes + ' ' +
' /Fe' + self.cwd + '/bin/' + self.name + '.dll ' +
obj_files + '/link ' + ' ' + libs
)
process.Wait()
if process.WasError():
print("Error while compiling dll:", process.GetErrorMessage())
process.SetError(False)
elif self.type == 'exe':
process.WriteInput('cl ' +
flags + ' ' +
defs + ' ' +
includes + ' ' +
'/Fe' + self.cwd + '/bin/' + self.name + '.exe ' +
obj_files + ' /link ' + ' ' + libs
)
process.Wait()
if process.WasError():
print("Error while compiling exe:", process.GetErrorMessage())
process.SetError(False)
return lib_updated