|
4 | 4 | import json |
5 | 5 | from utils import * |
6 | 6 |
|
| 7 | + |
| 8 | +def get_applicable_standards(standard_name, query): |
| 9 | + """Yield applicable standards, including unchanged queries reused by MISRA C:2025.""" |
| 10 | + if standard_name not in {"MISRA-C-2012", "MISRA-C-2025"}: |
| 11 | + yield standard_name |
| 12 | + return |
| 13 | + |
| 14 | + tags = query["tags"] |
| 15 | + if any(tag.startswith("external/misra/c/2012/") for tag in tags): |
| 16 | + yield "MISRA-C-2012" |
| 17 | + if "external/misra/legacy" not in tags: |
| 18 | + yield "MISRA-C-2025" |
| 19 | + |
| 20 | + |
7 | 21 | help_statement = """ |
8 | 22 | Usage: {script_name} |
9 | 23 |
|
|
37 | 51 | rule_packages_file_path = repo_root.joinpath('rule_packages', language_name) |
38 | 52 | for rule_package_file_name in os.listdir(rule_packages_file_path): |
39 | 53 | try: |
40 | | - rule_package_file = open(rule_packages_file_path.joinpath(rule_package_file_name), "r") |
| 54 | + package_definition = json.loads( |
| 55 | + rule_packages_file_path.joinpath(rule_package_file_name).read_text() |
| 56 | + ) |
41 | 57 | except PermissionError: |
42 | 58 | print("Error: No permission to read the rule package file located at '" + str(rule_package_file_name) + "'") |
43 | 59 | sys.exit(1) |
44 | | - else: |
45 | | - with rule_package_file: |
46 | | - package_definition = json.load(rule_package_file) |
47 | | - for standard_name, rules in package_definition.items(): |
48 | | - for rule_id, rule_details in rules.items(): |
49 | | - for query in rule_details["queries"]: |
50 | | - if standard_name in {"MISRA-C-2012", "MISRA-C-2025"}: |
51 | | - applicable_standards = [] |
52 | | - tags = query["tags"] |
53 | | - if any(tag.startswith("external/misra/c/2012/") for tag in tags): |
54 | | - applicable_standards.append("MISRA-C-2012") |
55 | | - # Current suites reuse unchanged queries but exclude legacy variants. |
56 | | - if "external/misra/legacy" not in tags: |
57 | | - applicable_standards.append("MISRA-C-2025") |
58 | | - else: |
59 | | - applicable_standards = [standard_name] |
60 | | - for applicable_standard in applicable_standards: |
61 | | - queries = rules_covered[applicable_standard].setdefault(rule_id, []) |
62 | | - if query["short_name"] not in queries: |
63 | | - queries.append(query["short_name"]) |
| 60 | + for standard_name, rules in package_definition.items(): |
| 61 | + for rule_id, rule_details in rules.items(): |
| 62 | + for query in rule_details["queries"]: |
| 63 | + for applicable_standard in get_applicable_standards(standard_name, query): |
| 64 | + queries = rules_covered[applicable_standard].setdefault(rule_id, []) |
| 65 | + if query["short_name"] not in queries: |
| 66 | + queries.append(query["short_name"]) |
64 | 67 |
|
65 | 68 |
|
66 | 69 | if is_csv: |
|
0 commit comments