blob: 461af5f9c240234d3947930e20f6b6528d3e11b5 [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
Lzu Tao9a721e52018-11-28 01:04:41 +070011
12
Lzu Tao066cfc02018-12-14 11:03:04 +070013def find_version_tuple(filepath):
Lzu Tao23374292018-11-30 11:01:19 +070014 version_file_data = None
15 with open(filepath) as fd:
16 version_file_data = fd.read()
Lzu Tao9a721e52018-11-28 01:04:41 +070017
Lzu Tao23374292018-11-30 11:01:19 +070018 patterns = r"""#\s*define\s+ZSTD_VERSION_MAJOR\s+([0-9]+)
Lzu Tao9a721e52018-11-28 01:04:41 +070019#\s*define\s+ZSTD_VERSION_MINOR\s+([0-9]+)
20#\s*define\s+ZSTD_VERSION_RELEASE\s+([0-9]+)
21"""
Lzu Tao23374292018-11-30 11:01:19 +070022 regex = re.compile(patterns, re.MULTILINE)
23 version_match = regex.search(version_file_data)
24 if version_match:
25 return version_match.groups()
Lzu Tao066cfc02018-12-14 11:03:04 +070026 raise Exception("Unable to find version string")
Lzu Tao9a721e52018-11-28 01:04:41 +070027
28
29def main():
Lzu Tao38728b42018-12-02 22:31:18 +070030 import argparse
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()
Lzu Tao066cfc02018-12-14 11:03:04 +070034 version_tuple = find_version_tuple(args.file)
35 print('.'.join(version_tuple))
Lzu Tao9a721e52018-11-28 01:04:41 +070036
37
38if __name__ == '__main__':
Lzu Tao23374292018-11-30 11:01:19 +070039 main()