Use the test Makefile for all examples
[SymbiYosys.git] / tests / make / required_tools.py
1 import shutil
2
3 REQUIRED_TOOLS = {
4 ("smtbmc", "yices"): ["yices-smt2"],
5 ("smtbmc", "z3"): ["z3"],
6 ("smtbmc", "cvc4"): ["cvc4"],
7 ("smtbmc", "mathsat"): ["mathsat"],
8 ("smtbmc", "boolector"): ["boolector"],
9 ("smtbmc", "bitwuzla"): ["bitwuzla"],
10 ("smtbmc", "abc"): ["yosys-abc"],
11 ("aiger", "suprove"): ["suprove", "yices"],
12 ("aiger", "avy"): ["avy", "yices"],
13 ("aiger", "aigbmc"): ["aigbmc", "yices"],
14 ("btor", "btormc"): ["btormc", "btorsim"],
15 ("btor", "pono"): ["pono", "btorsim"],
16 ("abc"): ["yices"],
17 }
18
19
20 def found_tools():
21 with open("make/rules/found_tools") as found_tools_file:
22 return [tool.strip() for tool in found_tools_file.readlines()]
23
24
25 if __name__ == "__main__":
26 import subprocess
27 import sys
28 import os
29 from pathlib import Path
30
31 args = sys.argv[1:]
32
33 if args and args[0] == "run":
34 target, command, *required_tools = args[1:]
35
36 with open("make/rules/found_tools") as found_tools_file:
37 found_tools = set(tool.strip() for tool in found_tools_file.readlines())
38
39 if 'verific' in required_tools:
40 result = subprocess.run(["yosys", "-qp", "read -verific"], capture_output=True)
41 if result.returncode:
42 print()
43 print(f"SKIPPING {target}: requires yosys with verific support")
44 print()
45 exit()
46 required_tools.remove('verific')
47
48 missing_tools = sorted(
49 f"`{tool}`" for tool in required_tools if tool not in found_tools
50 )
51 if missing_tools:
52 noskip = "NOSKIP" in os.environ.get("MAKEFLAGS", "")
53 print()
54 print(f"SKIPPING {target}: {', '.join(missing_tools)} not found")
55 if noskip:
56 print("NOSKIP was set, treating this as an error")
57 print()
58 exit(noskip)
59
60 print(command, flush=True)
61 exit(subprocess.call(command, shell=True))
62
63 found_tools = []
64 check_tools = set()
65 for tools in REQUIRED_TOOLS.values():
66 check_tools.update(tools)
67
68 for tool in sorted(check_tools):
69 if not shutil.which(tool):
70 continue
71
72 if tool == "btorsim":
73 error_msg = subprocess.run(
74 ["btorsim", "--vcd"],
75 capture_output=True,
76 text=True,
77 ).stderr
78 if "invalid command line option" in error_msg:
79 print(
80 "found `btorsim` binary is too old "
81 "to support the `--vcd` option, ignoring"
82 )
83 continue
84
85 found_tools.append(tool)
86
87 found_tools = "\n".join(found_tools + [""])
88
89 try:
90 with open("make/rules/found_tools") as found_tools_file:
91 if found_tools_file.read() == found_tools:
92 exit(0)
93 except FileNotFoundError:
94 pass
95
96 Path("make/rules").mkdir(exist_ok=True)
97
98 with open("make/rules/found_tools", "w") as found_tools_file:
99 found_tools_file.write(found_tools)