2 # #############################################################################
3 # Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
6 # This source code is licensed under both the BSD-style license (found in the
7 # LICENSE file in the root directory of this source tree) and the GPLv2 (found
8 # in the COPYING file in the root directory of this source tree).
9 # #############################################################################
13 def find_version_tuple(filepath):
14 version_file_data = None
15 with open(filepath) as fd:
16 version_file_data = fd.read()
18 patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+)
19 #\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+)
20 #\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+)
22 regex = re.compile(patterns, re.MULTILINE)
23 version_match = regex.search(version_file_data)
25 return version_match.groups()
26 raise Exception("Unable to find version string")
31 parser = argparse.ArgumentParser(description='Print zstd version from lib/zstd.h')
32 parser.add_argument('file', help='path to lib/zstd.h')
33 args = parser.parse_args()
34 version_tuple = find_version_tuple(args.file)
35 print('.'.join(version_tuple))
38 if __name__ == '__main__':