11
11
import subprocess
12
12
import zipfile
13
13
from mk_exception import *
14
- from mk_project import *
15
- import mk_util
16
14
17
15
BUILD_DIR = 'build-dist'
18
16
BUILD_X64_DIR = os .path .join ('build-dist' , 'x64' )
33
31
ARM64ONLY = False # ARM64 flag
34
32
MAKEJOBS = getenv ("MAKEJOBS" , "24" )
35
33
34
+ ARCHS = []
36
35
37
36
def set_verbose (flag ):
38
37
global VERBOSE
@@ -46,11 +45,12 @@ def mk_dir(d):
46
45
os .makedirs (d )
47
46
48
47
def set_build_dir (path ):
49
- global BUILD_DIR , BUILD_X86_DIR , BUILD_X64_DIR , BUILD_ARM64_DIR
50
- BUILD_DIR = mk_util . norm_path ( path )
48
+ global BUILD_DIR , BUILD_X86_DIR , BUILD_X64_DIR , BUILD_ARM64_DIR , ARCHS
49
+ BUILD_DIR = os . path . expanduser ( os . path . normpath ( path ) )
51
50
BUILD_X86_DIR = os .path .join (path , 'x86' )
52
51
BUILD_X64_DIR = os .path .join (path , 'x64' )
53
52
BUILD_ARM64_DIR = os .path .join (path , 'arm64' ) # Set ARM64 build directory
53
+ ARCHS = {'x64' : BUILD_X64_DIR , 'x86' :BUILD_X86_DIR , 'arm64' :BUILD_ARM64_DIR }
54
54
mk_dir (BUILD_X86_DIR )
55
55
mk_dir (BUILD_X64_DIR )
56
56
mk_dir (BUILD_ARM64_DIR )
@@ -59,11 +59,12 @@ def display_help():
59
59
print ("mk_win_dist.py: Z3 Windows distribution generator\n " )
60
60
print ("This script generates the zip files containing executables, dlls, header files for Windows." )
61
61
print ("It must be executed from the Z3 root directory." )
62
- print ("\n Options:" )
62
+ print ("\n Options:" )
63
63
print (" -h, --help display this message." )
64
64
print (" -s, --silent do not print verbose messages." )
65
65
print (" -b <sudir>, --build=<subdir> subdirectory where x86 and x64 Z3 versions will be built (default: build-dist)." )
66
66
print (" -f, --force force script to regenerate Makefiles." )
67
+ print (" --version=<version> release version." )
67
68
print (" --assembly-version assembly version for dll" )
68
69
print (" --nodotnet do not include .NET bindings in the binary distribution files." )
69
70
print (" --dotnet-key=<file> strongname sign the .NET assembly with the private key in <file>." )
@@ -134,6 +135,27 @@ def parse_options():
134
135
def check_build_dir (path ):
135
136
return os .path .exists (path ) and os .path .exists (os .path .join (path , 'Makefile' ))
136
137
138
+ def check_output (cmd ):
139
+ out = subprocess .Popen (cmd , stdout = subprocess .PIPE ).communicate ()[0 ]
140
+ if out != None :
141
+ enc = sys .getdefaultencoding ()
142
+ if enc != None : return out .decode (enc ).rstrip ('\r \n ' )
143
+ else : return out .rstrip ('\r \n ' )
144
+ else :
145
+ return ""
146
+
147
+ def get_git_hash ():
148
+ try :
149
+ branch = check_output (['git' , 'rev-parse' , '--abbrev-ref' , 'HEAD' ])
150
+ r = check_output (['git' , 'show-ref' , '--abbrev=12' , 'refs/heads/%s' % branch ])
151
+ except :
152
+ raise MKException ("Failed to retrieve git hash" )
153
+ ls = r .split (' ' )
154
+ if len (ls ) != 2 :
155
+ raise MKException ("Unexpected git output " + r )
156
+ return ls [0 ]
157
+
158
+
137
159
# Create a build directory using mk_make.py
138
160
def mk_build_dir (path , arch ):
139
161
if not check_build_dir (path ) or FORCE_MK :
@@ -149,18 +171,14 @@ def mk_build_dir(path, arch):
149
171
opts = ["cmake" , "-S" , "." ]
150
172
if DOTNET_CORE_ENABLED :
151
173
opts .append ('-DZ3_BUILD_DOTNET_BINDINGS=ON' )
152
- if DOTNET_KEY_FILE is not None :
153
- opts .append ('-DDOTNET_SIGNING_KEY_FILE=' + DOTNET_KEY_FILE )
154
- if ASSEMBLY_VERSION is not None :
155
- opts .append ('-DZ3_ASSEMBLY_VERSION=' + ASSEMBLY_VERSION )
156
174
if JAVA_ENABLED :
157
175
opts .append ('-DZ3_BUILD_JAVA_BINDINGS=ON' )
158
176
if GIT_HASH :
159
- git_hash = mk_util . git_hash ()
177
+ git_hash = get_git_hash ()
160
178
opts .append ('-DGIT_HASH=' + git_hash )
161
179
if PYTHON_ENABLED :
162
180
opts .append ('-DZ3_BUILD_PYTHON_BINDINGS=ON' )
163
- opts .append ('-DZ3_USE_LIBGMP =OFF' )
181
+ opts .append ('-DZ3_USE_LIB_GMP =OFF' )
164
182
opts .append ('-DZ3_BUILD_LIBZ3_SHARED=ON' )
165
183
opts .append ('-DCMAKE_INSTALL_PREFIX=' + path )
166
184
opts .append ('-G "NMake Makefiles"' )
@@ -173,10 +191,10 @@ def mk_build_dir(path, arch):
173
191
174
192
# Create build directories
175
193
def mk_build_dirs ():
176
- mk_build_dir ( BUILD_X86_DIR , 'x86' )
177
- mk_build_dir ( BUILD_X64_DIR , 'x64' )
178
- mk_build_dir ( BUILD_ARM64_DIR , 'arm64' ) # ARM64 build directory creation
179
-
194
+ global ARCHS
195
+ for k in ARCHS :
196
+ mk_build_dir ( ARCHS [ k ], k )
197
+
180
198
# Check if on Visual Studio command prompt
181
199
def check_vc_cmd_prompt ():
182
200
try :
@@ -222,18 +240,20 @@ def mk_z3(arch):
222
240
raise MKException ("Failed to make z3, x64: %s" % x64 )
223
241
224
242
def mk_z3s ():
225
- mk_z3 ( 'x86' )
226
- mk_z3 ( 'x64' )
227
- mk_z3 ('arm64' )
243
+ global ARCHS
244
+ for k in ARCHS :
245
+ mk_z3 (k )
228
246
229
247
def get_z3_name (arch ):
230
- major , minor , build , revision = get_version ()
231
- print ("Assembly version:" , major , minor , build , revision )
232
- platform = arch
248
+ global ASSEMBLY_VERSION
249
+ version = "4"
250
+ if ASSEMBLY_VERSION :
251
+ version = ASSEMBLY_VERSION
252
+ print ("Assembly version:" , version )
233
253
if GIT_HASH :
234
- return 'z3-%s.%s.%s.%s -%s-win' % (major , minor , build , mk_util . git_hash (), platform )
254
+ return 'z3-%s.%s-%s-win' % (version , get_git_hash (), arch )
235
255
else :
236
- return 'z3-%s.%s.%s -%s-win' % (major , minor , build , platform )
256
+ return 'z3-%s-%s-win' % (version , arch )
237
257
238
258
def mk_dist_dir (arch ):
239
259
build_path = get_build_dir (arch )
@@ -244,10 +264,10 @@ def mk_dist_dir(arch):
244
264
print (f"Generated { platform } distribution folder at '{ dist_path } '" )
245
265
246
266
def mk_dist_dirs ():
247
- mk_dist_dir ( "x86" )
248
- mk_dist_dir ( "x64" )
249
- mk_dist_dir ("arm64" )
250
-
267
+ global ARCHS
268
+ for k in ARCHS :
269
+ mk_dist_dir (k )
270
+
251
271
def get_dist_path (arch ):
252
272
return get_z3_name (arch )
253
273
@@ -269,8 +289,9 @@ def mk_zip(arch):
269
289
270
290
# Create a zip file for each platform
271
291
def mk_zips ():
272
- mk_zip (False )
273
- mk_zip (True )
292
+ global ARCHS
293
+ for k in ARCHS :
294
+ mk_zip (k )
274
295
275
296
276
297
VS_RUNTIME_PATS = [re .compile (r'vcomp.*\.dll' ),
@@ -311,65 +332,45 @@ def check_root(root):
311
332
print ("Copied '%s' to '%s'" % (f , bin_dist_path ))
312
333
313
334
def cp_vs_runtimes ():
314
- cp_vs_runtime ( "x86" )
315
- cp_vs_runtime ( "x64" )
316
- cp_vs_runtime ("arm64" )
317
-
335
+ global ARCHS
336
+ for k in ARCHS :
337
+ cp_vs_runtime (k )
338
+
318
339
def cp_license (arch ):
319
340
shutil .copy ("LICENSE.txt" , os .path .join (DIST_DIR , get_dist_path (arch )))
320
341
321
342
def cp_licenses ():
322
- cp_license ("x86" )
323
- cp_license ("x64" )
324
- cp_license ("arm64" )
325
-
326
- def init_flags ():
327
- global DOTNET_KEY_FILE , JAVA_ENABLED , PYTHON_ENABLED , ASSEMBLY_VERSION
328
- mk_util .DOTNET_CORE_ENABLED = True
329
- mk_util .DOTNET_KEY_FILE = DOTNET_KEY_FILE
330
- mk_util .ASSEMBLY_VERSION = ASSEMBLY_VERSION
331
- mk_util .JAVA_ENABLED = JAVA_ENABLED
332
- mk_util .PYTHON_ENABLED = PYTHON_ENABLED
333
- mk_util .ALWAYS_DYNAMIC_BASE = True
334
-
335
-
343
+ global ARCHS
344
+ for k in ARCHS :
345
+ cp_license (k )
346
+
347
+
348
+ def build_for_arch (arch ):
349
+ global ARCHS
350
+ build_dir = ARCHS [arch ]
351
+ mk_build_dir (build_dir , arch )
352
+ mk_z3 (arch )
353
+ init_project_def ()
354
+ mk_dist_dir (arch )
355
+ cp_license (arch )
356
+ cp_vs_runtime (arch )
357
+ if ZIP_BUILD_OUTPUTS :
358
+ mk_zip (arch )
359
+
336
360
# Entry point
337
361
def main ():
338
362
if os .name != 'nt' :
339
363
raise MKException ("This script is for Windows only" )
340
364
341
365
parse_options ()
342
366
check_vc_cmd_prompt ()
343
- init_flags ()
344
367
345
368
if X86ONLY :
346
- mk_build_dir (BUILD_X86_DIR , 'x86' )
347
- mk_z3 ('x86' )
348
- init_project_def ()
349
- mk_dist_dir ('x86' )
350
- cp_license ('x86' )
351
- cp_vs_runtime ('x86' )
352
- if ZIP_BUILD_OUTPUTS :
353
- mk_zip ('x86' )
369
+ build_for_arch ("x86" )
354
370
elif X64ONLY :
355
- mk_build_dir (BUILD_X64_DIR , 'x64' )
356
- mk_z3 ('x64' )
357
- init_project_def ()
358
- mk_dist_dir ('x64' )
359
- cp_license ('x64' )
360
- cp_vs_runtime ('x64' )
361
- if ZIP_BUILD_OUTPUTS :
362
- mk_zip ('x64' )
363
- elif ARM64ONLY : # ARM64 build process
364
- mk_build_dir (BUILD_ARM64_DIR , 'arm64' )
365
- mk_z3 ('arm64' )
366
- init_project_def ()
367
- mk_dist_dir ('arm64' )
368
- cp_license ('arm64' )
369
- cp_vs_runtime ('arm64' )
370
- if ZIP_BUILD_OUTPUTS :
371
- mk_zip ('arm64' )
372
-
371
+ build_for_arch ("x64" )
372
+ elif ARM64ONLY :
373
+ build_for_arch ("arm64" )
373
374
else :
374
375
mk_build_dirs ()
375
376
mk_z3s ()
0 commit comments