diff --git a/scripts/mk_util.py b/scripts/mk_util.py index 875cf449f..a9b3af1cb 100644 --- a/scripts/mk_util.py +++ b/scripts/mk_util.py @@ -74,6 +74,16 @@ VS_PAR=False VS_PAR_NUM=8 GPROF=False +def git_hash(): + try: + r = subprocess.check_output(['git', 'show-ref', '--abbrev=12', 'HEAD'], shell=True).rstrip('\r\n') + except: + raise MKException("Failed to retrieve git hash") + ls = r.split(' ') + if len(ls) != 2: + raise MKException("Unexpected git output") + return ls[0] + def is_windows(): return IS_WINDOWS diff --git a/scripts/mk_win_dist.py b/scripts/mk_win_dist.py index ac85a9c43..a8c4fd3ba 100644 --- a/scripts/mk_win_dist.py +++ b/scripts/mk_win_dist.py @@ -25,6 +25,7 @@ VERBOSE=True DIST_DIR='dist' FORCE_MK=False JAVA_ENABLED=True +GIT_HASH=False def set_verbose(flag): global VERBOSE @@ -55,17 +56,19 @@ def display_help(): print " -b , --build= subdirectory where x86 and x64 Z3 versions will be built (default: build-dist)." print " -f, --force force script to regenerate Makefiles." print " --nojava do not include Java bindings in the binary distribution files." + print " --githash include git hash in the Zip file." exit(0) # Parse configuration option for mk_make script def parse_options(): - global FORCE_MK, JAVA_ENABLED + global FORCE_MK, JAVA_ENABLED, GIT_HASH path = BUILD_DIR options, remainder = getopt.gnu_getopt(sys.argv[1:], 'b:hsf', ['build=', 'help', 'silent', 'force', - 'nojava' + 'nojava', + 'githash' ]) for opt, arg in options: if opt in ('-b', '--build'): @@ -80,6 +83,8 @@ def parse_options(): FORCE_MK = True elif opt == '--nojava': JAVA_ENABLED = False + elif opt == '--githash': + GIT_HASH = True else: raise MKException("Invalid command line option '%s'" % opt) set_build_dir(path) @@ -147,15 +152,25 @@ def mk_z3(): mk_z3_core(False) mk_z3_core(True) -def mk_dist_dir_core(x64): +def get_z3_name(x64): major, minor, build, revision = get_version() + if x64: + platform = "x64" + else: + platform = "x86" + if GIT_HASH: + return 'z3-%s.%s.%s.%s-%s' % (major, minor, build, mk_util.git_hash(), platform) + else: + return 'z3-%s.%s.%s-%s' % (major, minor, build, platform) + +def mk_dist_dir_core(x64): if x64: platform = "x64" build_path = BUILD_X64_DIR else: platform = "x86" build_path = BUILD_X86_DIR - dist_path = os.path.join(DIST_DIR, 'z3-%s.%s.%s-%s' % (major, minor, build, platform)) + dist_path = os.path.join(DIST_DIR, get_z3_name(x64)) mk_dir(dist_path) if JAVA_ENABLED: # HACK: Propagate JAVA_ENABLED flag to mk_util @@ -179,12 +194,7 @@ def mk_zip_visitor(pattern, dir, files): ZIPOUT.write(fname) def get_dist_path(x64): - major, minor, build, revision = get_version() - if x64: - platform = "x64" - else: - platform = "x86" - return 'z3-%s.%s.%s-%s' % (major, minor, build, platform) + return get_z3_name(x64) def mk_zip_core(x64): global ZIPOUT