forked from model-checking/kani
-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-cbmc-viewer-version.py
executable file
·56 lines (43 loc) · 1.71 KB
/
check-cbmc-viewer-version.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env python3
# Copyright Kani Contributors
# SPDX-License-Identifier: Apache-2.0 OR MIT
import argparse
import re
import sys
import subprocess
from subprocess import PIPE
EXIT_CODE_SUCCESS = 0
EXIT_CODE_MISMATCH = 1
EXIT_CODE_FAIL = 2
def cbmc_viewer_version():
cmd = ["cbmc-viewer", "--version"]
try:
version = subprocess.run(cmd, stdout=PIPE, stderr=PIPE, check=True,
universal_newlines=True)
except (OSError, subprocess.SubprocessError) as error:
print(error)
print(f"Can't run command '{' '.join(cmd)}'")
sys.exit(EXIT_CODE_FAIL)
match = re.match("CBMC viewer ([0-9]+).([0-9]+)", version.stdout)
if not match:
print(f"Can't parse CBMC-viewer version string: '{version.stdout.strip()}'")
sys.exit(EXIT_CODE_FAIL)
return match.groups()
def complete_version(*version):
numbers = [int(num) if num else 0 for num in version]
return (numbers + [0, 0])[:2]
def main():
parser = argparse.ArgumentParser(
description='Check CBMC-viewer version matches major/minor')
parser.add_argument('--major', required=True)
parser.add_argument('--minor', required=True)
args = parser.parse_args()
current_version = complete_version(*cbmc_viewer_version())
desired_version = complete_version(args.major, args.minor)
if desired_version > current_version:
version_string = '.'.join([str(num) for num in current_version])
desired_version_string = '.'.join([str(num) for num in desired_version])
print(f'ERROR: CBMC-viewer version is {version_string}, expected at least {desired_version_string}')
sys.exit(EXIT_CODE_MISMATCH)
if __name__ == "__main__":
main()