2018-11-27 18:04:41 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# #############################################################################
|
|
|
|
# Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under both the BSD-style license (found in the
|
|
|
|
# LICENSE file in the root directory of this source tree) and the GPLv2 (found
|
|
|
|
# in the COPYING file in the root directory of this source tree).
|
|
|
|
# #############################################################################
|
|
|
|
import re
|
|
|
|
import sys
|
|
|
|
|
|
|
|
|
|
|
|
def usage():
|
2018-11-30 04:01:19 +00:00
|
|
|
print('usage: python3 GetZstdLibraryVersion.py <path/to/zstd.h>')
|
|
|
|
sys.exit(1)
|
2018-11-27 18:04:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def find_version(filepath):
|
2018-11-30 04:01:19 +00:00
|
|
|
version_file_data = None
|
|
|
|
with open(filepath) as fd:
|
|
|
|
version_file_data = fd.read()
|
2018-11-27 18:04:41 +00:00
|
|
|
|
2018-11-30 04:01:19 +00:00
|
|
|
patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+)
|
2018-11-27 18:04:41 +00:00
|
|
|
#\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+)
|
|
|
|
#\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+)
|
|
|
|
"""
|
2018-11-30 04:01:19 +00:00
|
|
|
regex = re.compile(patterns, re.MULTILINE)
|
|
|
|
version_match = regex.search(version_file_data)
|
|
|
|
if version_match:
|
|
|
|
return version_match.groups()
|
|
|
|
raise RuntimeError("Unable to find version string.")
|
2018-11-27 18:04:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2018-11-30 04:01:19 +00:00
|
|
|
if len(sys.argv) < 2:
|
|
|
|
usage()
|
2018-11-27 18:04:41 +00:00
|
|
|
|
2018-11-30 04:01:19 +00:00
|
|
|
filepath = sys.argv[1]
|
|
|
|
version_tup = find_version(filepath)
|
|
|
|
print('.'.join(version_tup))
|
2018-11-27 18:04:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2018-11-30 04:01:19 +00:00
|
|
|
main()
|