blob: 53c61008a792bfac457ede79ef813306b09c35e7 [file] [log] [blame]
Lzu Tao9a721e52018-11-28 01:04:41 +07001#!/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# #############################################################################
10import re
11import sys
12
13
Lzu Tao9a721e52018-11-28 01:04:41 +070014def find_version(filepath):
Lzu Tao23374292018-11-30 11:01:19 +070015 version_file_data = None
16 with open(filepath) as fd:
17 version_file_data = fd.read()
Lzu Tao9a721e52018-11-28 01:04:41 +070018
Lzu Tao23374292018-11-30 11:01:19 +070019 patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+)
Lzu Tao9a721e52018-11-28 01:04:41 +070020#\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+)
21#\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+)
22"""
Lzu Tao23374292018-11-30 11:01:19 +070023 regex = re.compile(patterns, re.MULTILINE)
24 version_match = regex.search(version_file_data)
25 if version_match:
26 return version_match.groups()
Lzu Tao38728b42018-12-02 22:31:18 +070027 raise Exception("Unable to find version string.")
Lzu Tao9a721e52018-11-28 01:04:41 +070028
29
30def main():
Lzu Tao38728b42018-12-02 22:31:18 +070031 import argparse
32 parser = argparse.ArgumentParser(description='Print zstd version from lib/zstd.h')
33 parser.add_argument('file', help='path to lib/zstd.h')
34 args = parser.parse_args()
35 filepath = args.file
Lzu Tao23374292018-11-30 11:01:19 +070036 version_tup = find_version(filepath)
37 print('.'.join(version_tup))
Lzu Tao9a721e52018-11-28 01:04:41 +070038
39
40if __name__ == '__main__':
Lzu Tao23374292018-11-30 11:01:19 +070041 main()