Debian Codegraph @

crt/aws-c-common/verification/cbmc/proofs/lib/print_tool_versions.py

raw symbols SCIP
1 #!/usr/bin/env python3
2 #
3 # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4 # SPDX-License-Identifier: MIT-0
5
6
7 import logging
8 import pathlib
9 import shutil
10 import subprocess
11
12
13 _TOOLS = [
14 "cadical",
15 "cbmc",
16 "cbmc-viewer",
17 "cbmc-starter-kit-update",
18 "kissat",
19 "litani",
20 ]
21
22
23 def _format_versions(table):
24 lines = [
25 "<table>",
26 '<tr><td colspan="2" style="font-weight: bold">Tool Versions</td></tr>',
27 ]
28 for tool, version in table.items():
29 if version:
30 v_str = f'<code><pre style="margin: 0">{version}</pre></code>'
31 else:
32 v_str = '<em>not found</em>'
33 lines.append(
34 f'<tr><td style="font-weight: bold; padding-right: 1em; '
35 f'text-align: right;">{tool}:</td>'
36 f'<td>{v_str}</td></tr>')
37 lines.append("</table>")
38 return "\n".join(lines)
39
40
41 def _get_tool_versions():
42 ret = {}
43 for tool in _TOOLS:
44 err = f"Could not determine version of {tool}: "
45 ret[tool] = None
46 if not shutil.which(tool):
47 logging.error("%s'%s' not found on $PATH", err, tool)
48 continue
49 cmd = [tool, "--version"]
50 proc = subprocess.Popen(cmd, text=True, stdout=subprocess.PIPE)
51 try:
52 out, _ = proc.communicate(timeout=10)
53 except subprocess.TimeoutExpired:
54 logging.error("%s'%s --version' timed out", err, tool)
55 continue
56 if proc.returncode:
57 logging.error(
58 "%s'%s --version' returned %s", err, tool, str(proc.returncode))
59 continue
60 ret[tool] = out.strip()
61 return ret
62
63
64 def main():
65 exe_name = pathlib.Path(__file__).name
66 logging.basicConfig(format=f"{exe_name}: %(message)s")
67
68 table = _get_tool_versions()
69 out = _format_versions(table)
70 print(out)
71
72
73 if __name__ == "__main__":
74 main()