2
0

GetZstdLibraryVersion.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/usr/bin/env python3
  2. # #############################################################################
  3. # Copyright (c) 2018-present lzutao <taolzu(at)gmail.com>
  4. # All rights reserved.
  5. #
  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. # #############################################################################
  10. import re
  11. def find_version_tuple(filepath):
  12. version_file_data = None
  13. with open(filepath) as fd:
  14. version_file_data = fd.read()
  15. patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+)
  16. #\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+)
  17. #\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+)
  18. """
  19. regex = re.compile(patterns, re.MULTILINE)
  20. version_match = regex.search(version_file_data)
  21. if version_match:
  22. return version_match.groups()
  23. raise Exception("Unable to find version string")
  24. def main():
  25. import argparse
  26. parser = argparse.ArgumentParser(description='Print zstd version from lib/zstd.h')
  27. parser.add_argument('file', help='path to lib/zstd.h')
  28. args = parser.parse_args()
  29. version_tuple = find_version_tuple(args.file)
  30. print('.'.join(version_tuple))
  31. if __name__ == '__main__':
  32. main()