89a68ecaaf009a541f9304f8483f73d5954e6540
[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 collect(Path("../docs/examples"))
30
31 out_file = Path("make/rules/collect.mk")
32 out_file.parent.mkdir(exist_ok=True)
33
34 with out_file.open("w") as output:
35
36
37 for checked_dir in checked_dirs:
38 print(f"{out_file}: {checked_dir}", file=output)
39
40 for test in tests:
41 print(f"make/rules/test/{test}.mk: {test}", file=output)
42 for ext in [".sh", ".py"]:
43 script_file = test.parent / (test.stem + ext)
44 if script_file.exists():
45 print(f"make/rules/test/{test}.mk: {script_file}", file=output)
46 print(f"make/rules/test/{test}.mk: make/test_rules.py", file=output)
47 for test in tests:
48 print(f"-include make/rules/test/{test}.mk", file=output)