diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-01-16 02:51:12 (GMT) |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-01-30 17:55:03 (GMT) |
commit | 7ab223b7fa2f5b28cfaa4c800db78ad82287be40 (patch) | |
tree | 22999d2208c0a4cbedb06a1e688433f46cb75a12 /build/meson/GetLz4LibraryVersion.py | |
parent | 1f3adea1c68ea61f41903d959b4f98f45aa527a7 (diff) | |
download | lz4-7ab223b7fa2f5b28cfaa4c800db78ad82287be40.zip lz4-7ab223b7fa2f5b28cfaa4c800db78ad82287be40.tar.gz lz4-7ab223b7fa2f5b28cfaa4c800db78ad82287be40.tar.bz2 |
build: move meson files from contrib, to go alongside other build systems
Diffstat (limited to 'build/meson/GetLz4LibraryVersion.py')
-rw-r--r-- | build/meson/GetLz4LibraryVersion.py | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/build/meson/GetLz4LibraryVersion.py b/build/meson/GetLz4LibraryVersion.py new file mode 100644 index 0000000..d8abfcb --- /dev/null +++ b/build/meson/GetLz4LibraryVersion.py @@ -0,0 +1,39 @@ +#!/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 + + +def find_version_tuple(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() + version_tuple = find_version_tuple(args.file) + print('.'.join(version_tuple)) + + +if __name__ == '__main__': + main() |