summaryrefslogtreecommitdiffstats
path: root/contrib/meson/GetLz4LibraryVersion.py
blob: 80b09c9d6784b520775be9c404ce3484d6f4d87e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/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 find_version(filepath):
  version_file_data = None
  with open(filepath) as fd:
    version_file_data = fd.read()

  patterns = r"""#\s*define\s+LZ4_VERSION_MAJOR\s+([0-9]+).*$
#\s*define\s+LZ4_VERSION_MINOR\s+([0-9]+).*$
#\s*define\s+LZ4_VERSION_RELEASE\s+([0-9]+).*$
"""
  regex = re.compile(patterns, re.MULTILINE)
  version_match = regex.search(version_file_data)
  if version_match:
    return version_match.groups()
  raise Exception("Unable to find version string.")


def main():
  import argparse
  parser = argparse.ArgumentParser(description='Print lz4 version from lib/lz4.h')
  parser.add_argument('file', help='path to lib/lz4.h')
  args = parser.parse_args()
  filepath = args.file
  version_tup = find_version(filepath)
  print('.'.join(version_tup))


if __name__ == '__main__':
  main()