tests: Windows fixes
[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
10 def collect(path):
11 # don't pick up any paths that need escaping nor any sby workdirs
12 if not SAFE_PATH.match(str(path)) or (path / "config.sby").exists():
13 return
14
15 checked_dirs.append(path)
16 for entry in path.glob("*.sby"):
17 filename = str(entry)
18 if not SAFE_PATH.match(filename):
19 print(f"skipping {filename!r}, use only [a-zA-Z0-9_./] in filenames")
20 continue
21 tests.append(entry)
22 for entry in path.glob("*"):
23 if entry.is_dir():
24 collect(entry)
25
26
27 def unix_path(path):
28 return "/".join(path.parts)
29
30
31 collect(Path("."))
32 collect(Path("../docs/examples"))
33
34 out_file = Path("make/rules/collect.mk")
35 out_file.parent.mkdir(exist_ok=True)
36
37 with out_file.open("w") as output:
38
39 for checked_dir in checked_dirs:
40 print(f"{out_file}: {checked_dir}", file=output)
41
42 for test in tests:
43 test_unix = unix_path(test)
44 print(f"make/rules/test/{test_unix}.mk: {test_unix}", file=output)
45 for ext in [".sh", ".py"]:
46 script_file = test.parent / (test.stem + ext)
47 if script_file.exists():
48 script_file_unix = unix_path(script_file)
49 print(f"make/rules/test/{test_unix}.mk: {script_file_unix}", file=output)
50 print(f"make/rules/test/{test_unix}.mk: make/test_rules.py", file=output)
51 for test in tests:
52 test_unix = unix_path(test)
53 print(f"-include make/rules/test/{test_unix}.mk", file=output)