10
10
import os
11
11
import subprocess
12
12
import zipfile
13
+ import re
14
+ import getopt
15
+ import sys
16
+ import shutil
13
17
from mk_exception import *
18
+ from fnmatch import fnmatch
19
+
20
+ def getenv (name , default ):
21
+ try :
22
+ return os .environ [name ].strip (' "\' ' )
23
+ except :
24
+ return default
14
25
15
26
BUILD_DIR = 'build-dist'
16
27
BUILD_X64_DIR = os .path .join ('build-dist' , 'x64' )
@@ -156,44 +167,55 @@ def get_git_hash():
156
167
return ls [0 ]
157
168
158
169
170
+
159
171
# Create a build directory using mk_make.py
160
- def mk_build_dir (path , arch ):
161
- if not check_build_dir (path ) or FORCE_MK :
162
- subprocess .call (["call" , "md" , path , "2>NUL" ], shell = True )
172
+ def mk_build_dir (arch ):
173
+ global ARCHS
174
+ build_path = ARCHS [arch ]
175
+ install_path = DIST_DIR
176
+ if not check_build_dir (build_path ) or FORCE_MK :
177
+ mk_dir (build_path )
163
178
164
179
if arch == "arm64" :
165
180
arch = "amd64_arm64"
166
181
167
- opts0 = ["cd" , path ]
168
-
169
- opts1 = [ ' "C:\\ Program Files\\ Microsoft Visual Studio\\ 2022\\ Enterprise\\ VC\\ Auxiliary\\ Build\\ vcvarsall.bat"' , arch ]
170
-
171
- opts = [ "cmake" , "-S" , "." ]
182
+ cmds = []
183
+ cmds . append ( f"cd { build_path } " )
184
+ cmds . append ( f"call \ " C:\\ Program Files\\ Microsoft Visual Studio\\ 2022\\ Enterprise\\ VC\\ Auxiliary\\ Build\\ vcvarsall.bat\" { arch } " )
185
+ cmd = []
186
+ cmd . append ( "cmake -S ." )
172
187
if DOTNET_CORE_ENABLED :
173
- opts .append ('-DZ3_BUILD_DOTNET_BINDINGS=ON' )
188
+ cmd .append (' -DZ3_BUILD_DOTNET_BINDINGS=ON' )
189
+ cmd .append (' -DZ3_INSTALL_DOTNET_BINDINGS=ON' )
174
190
if JAVA_ENABLED :
175
- opts .append ('-DZ3_BUILD_JAVA_BINDINGS=ON' )
191
+ cmd .append (' -DZ3_BUILD_JAVA_BINDINGS=ON' )
192
+ cmd .append (' -DZ3_INSTALL_JAVA_BINDINGS=ON' )
193
+ if PYTHON_ENABLED :
194
+ cmd .append (' -DZ3_BUILD_PYTHON_BINDINGS=ON' )
195
+ cmd .append (' -DZ3_INSTALL_PYTHON_BINDINGS=ON' )
196
+ cmd .append (' -DCMAKE_INSTALL_PYTHON_PKG_DIR=python' )
197
+
176
198
if GIT_HASH :
177
199
git_hash = get_git_hash ()
178
- opts .append ('-DGIT_HASH=' + git_hash )
179
- if PYTHON_ENABLED :
180
- opts .append ('-DZ3_BUILD_PYTHON_BINDINGS =ON' )
181
- opts .append ('-DZ3_USE_LIB_GMP=OFF ' )
182
- opts .append ('-DZ3_BUILD_LIBZ3_SHARED=ON' )
183
- opts .append ('-DCMAKE_INSTALL_PREFIX=' + path )
184
- opts .append ('-G "NMake Makefiles" ' )
185
- opts .append ('../..' )
186
- args = " " . join ( opts0 ) + "& " + " " . join ( opts1 ) + "& " + " " . join ( opts )
187
- print ( args )
188
- if subprocess . call ( args , shell = True ) != 0 :
189
- raise MKException ("Failed to generate build directory at '%s'" % path )
200
+ cmd .append (' -DGIT_HASH=' + git_hash )
201
+ cmd . append ( ' -DZ3_USE_LIB_GMP=OFF' )
202
+ cmd .append (' -DZ3_BUILD_LIBZ3_SHARED =ON' )
203
+ cmd .append (' -DCMAKE_BUILD_TYPE=RelWithDebInfo ' )
204
+ cmd .append (' -DCMAKE_INSTALL_PREFIX=' + install_path )
205
+ cmd .append (' -G "NMake Makefiles"' )
206
+ cmd .append (' ../.. \n ' )
207
+ cmds .append ("" . join ( cmd ) )
208
+ print ( cmds )
209
+ sys . stdout . flush ( )
210
+ if exec_cmds ( cmds ) != 0 :
211
+ raise MKException ("failed to run commands" )
190
212
191
213
192
214
# Create build directories
193
215
def mk_build_dirs ():
194
216
global ARCHS
195
217
for k in ARCHS :
196
- mk_build_dir (ARCHS [ k ], k )
218
+ mk_build_dir (k )
197
219
198
220
# Check if on Visual Studio command prompt
199
221
def check_vc_cmd_prompt ():
@@ -222,11 +244,8 @@ def exec_cmds(cmds):
222
244
return res
223
245
224
246
def get_build_dir (arch ):
225
- if arch == 'x64' :
226
- return BUILD_X64_DIR
227
- if arch == 'x86' :
228
- return BUILD_X86_DIR
229
- return BUILD_ARM64_DIR
247
+ global ARCHS
248
+ return ARCHS [arch ]
230
249
231
250
def mk_z3 (arch ):
232
251
build_dir = get_build_dir (arch )
@@ -235,7 +254,7 @@ def mk_z3(arch):
235
254
cmds = []
236
255
cmds .append ('call "%VCINSTALLDIR%Auxiliary\\ build\\ vcvarsall.bat" ' + arch + ' ' )
237
256
cmds .append ('cd %s' % build_dir )
238
- cmds .append ('nmake' )
257
+ cmds .append ('nmake install ' )
239
258
if exec_cmds (cmds ) != 0 :
240
259
raise MKException ("Failed to make z3, x64: %s" % x64 )
241
260
@@ -255,28 +274,16 @@ def get_z3_name(arch):
255
274
else :
256
275
return 'z3-%s-%s-win' % (version , arch )
257
276
258
- def mk_dist_dir (arch ):
259
- build_path = get_build_dir (arch )
260
- dist_path = os .path .join (DIST_DIR , get_z3_name (arch ))
261
- mk_dir (dist_path )
262
- mk_win_dist (build_path , dist_path )
263
- if is_verbose ():
264
- print (f"Generated { platform } distribution folder at '{ dist_path } '" )
265
-
266
- def mk_dist_dirs ():
267
- global ARCHS
268
- for k in ARCHS :
269
- mk_dist_dir (k )
270
-
271
- def get_dist_path (arch ):
272
- return get_z3_name (arch )
273
-
277
+
274
278
def mk_zip (arch ):
275
- dist_path = get_dist_path (arch )
279
+ global ARCHS
280
+ build_dir = ARCHS [arch ]
281
+ dist_dir = os .path .join (build_dir , DIST_DIR )
282
+ dist_name = get_z3_name (arch )
276
283
old = os .getcwd ()
277
284
try :
278
- os .chdir (DIST_DIR )
279
- zfname = '%s.zip' % dist_path
285
+ os .chdir (dist_dir )
286
+ zfname = '%s.zip' % dist_name
280
287
zipout = zipfile .ZipFile (zfname , 'w' , zipfile .ZIP_DEFLATED )
281
288
for root , dirs , files in os .walk (dist_path ):
282
289
for f in files :
@@ -324,8 +331,9 @@ def check_root(root):
324
331
if not os .path .isdir (fname ):
325
332
vs_runtime_files .append (fname )
326
333
if not vs_runtime_files :
327
- raise MKException ("Did not find any runtime files to include" )
328
- bin_dist_path = os .path .join (DIST_DIR , get_dist_path (arch ), 'bin' )
334
+ raise MKException ("Did not find any runtime files to include" )
335
+ build_dir = get_build_dir (arch )
336
+ bin_dist_path = os .path .join (build_dir , DIST_DIR , 'bin' )
329
337
for f in vs_runtime_files :
330
338
shutil .copy (f , bin_dist_path )
331
339
if is_verbose ():
@@ -337,7 +345,7 @@ def cp_vs_runtimes():
337
345
cp_vs_runtime (k )
338
346
339
347
def cp_license (arch ):
340
- shutil .copy ("LICENSE.txt" , os .path .join (DIST_DIR , get_dist_path (arch )))
348
+ shutil .copy ("LICENSE.txt" , os .path .join (DIST_DIR , get_z3_name (arch )))
341
349
342
350
def cp_licenses ():
343
351
global ARCHS
@@ -347,11 +355,8 @@ def cp_licenses():
347
355
348
356
def build_for_arch (arch ):
349
357
global ARCHS
350
- build_dir = ARCHS [arch ]
351
- mk_build_dir (build_dir , arch )
358
+ mk_build_dir (arch )
352
359
mk_z3 (arch )
353
- init_project_def ()
354
- mk_dist_dir (arch )
355
360
cp_license (arch )
356
361
cp_vs_runtime (arch )
357
362
if ZIP_BUILD_OUTPUTS :
@@ -374,8 +379,6 @@ def main():
374
379
else :
375
380
mk_build_dirs ()
376
381
mk_z3s ()
377
- init_project_def ()
378
- mk_dist_dirs ()
379
382
cp_licenses ()
380
383
cp_vs_runtimes ()
381
384
if ZIP_BUILD_OUTPUTS :
0 commit comments