generated from efabless/caravel_user_project
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdeactivate_linter_warning.py
executable file
·42 lines (32 loc) · 1.26 KB
/
deactivate_linter_warning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env python
import sys
from pathlib import Path
if len(sys.argv) < 4:
print('Usage: python deactivate_linter_warning.py <base_directory> <file_pattern> <warning>')
print("Example: ./deactivate_linter_warning.py verilog/rtl/Tile \"**/OD*.v:\" UNUSEDSIGNAL")
sys.exit(1)
def find_files(base_dir, pattern):
return list(Path(base_dir).rglob(pattern))
def deactivate_warning(file_path, warning):
lines = Path(file_path).read_text().splitlines()
if not lines:
print(f"File {file_path} is empty")
return
if warning in " ".join(lines):
print(f"Warning {warning} already deactivated in {file_path}")
return
if len(lines) > 1:
lines[0] += f"\n/* verilator lint_off {warning} */\n"
lines[-1] += f"\n/* verilator lint_on {warning} */\n"
Path(file_path).write_text('\n'.join(lines) + '\n')
base_directory = sys.argv[1]
file_pattern = sys.argv[2]
warning = sys.argv[3]
files = find_files(base_directory, file_pattern)
if not files:
print(f"No files found in {base_directory} with pattern {file_pattern}")
sys.exit(1)
for file in files:
deactivate_warning(file, warning)
print(f"Deactivated warning {warning} in {file}")
print(f"Deactivated warning {warning} in {len(files)} files")