7b0cda3759d8e30030526721bdc8c7ffcde8c619
[SymbiYosys.git] / tests / make / collect_tests.py
1 from pathlib import Path
2 import re
3
4 tests = []
5 checked_dirs = []
6
7 SAFE_PATH = re.compile(r"^[a-zA-Z0-9_./]*$")
8
9 def collect(path):
10 # don't pick up any paths that need escaping nor any sby workdirs
11 if not SAFE_PATH.match(str(path)) or (path / "config.sby").exists():
12 return
13
14 checked_dirs.append(path)
15 for entry in path.glob("*.sby"):
16 filename = str(entry)
17 if not SAFE_PATH.match(filename):
18 continue
19 if not re.match(r"^[a-zA-Z0-9_./]*$", filename):
20 print(f"skipping {filename!r}, use only [a-zA-Z0-9_./] in filenames")
21 continue
22 tests.append(entry)
23 for entry in path.glob("*"):
24 if entry.is_dir():
25 collect(entry)
26
27
28 collect(Path("."))
29
30 out_file = Path("make/rules/collect.mk")
31 out_file.parent.mkdir(exist_ok=True)
32
33 with out_file.open("w") as output:
34
35
36 for checked_dir in checked_dirs:
37 print(f"{out_file}: {checked_dir}", file=output)
38
39 for test in tests:
40 print(f"make/rules/test/{test}.mk: {test} make/rules/found_tools", file=output)
41 for ext in [".sh", ".py"]:
42 script_file = test.parent / (test.stem + ext)
43 if script_file.exists():
44 print(f"make/rules/test/{test}.mk: {script_file}", file=output)
45 print(f"make/rules/test/{test}.mk: make/test_rules.py", file=output)
46 for test in tests:
47 print(f"-include make/rules/test/{test}.mk", file=output)