(compile_commands)
| 83 | print_tree(subtree, indent + ' ') |
| 84 | |
| 85 | def extract_source_dirs(compile_commands): |
| 86 | source_dirs = set() |
| 87 | |
| 88 | for entry in compile_commands: |
| 89 | file_path = os.path.abspath(entry['file']) |
| 90 | |
| 91 | if file_path.endswith('.c'): |
| 92 | dir_path = os.path.dirname(file_path) |
| 93 | source_dirs.add(dir_path) |
| 94 | # command or arguments |
| 95 | command = entry.get('command') or entry.get('arguments') |
| 96 | |
| 97 | if isinstance(command, str): |
| 98 | parts = command.split() |
| 99 | else: |
| 100 | parts = command |
| 101 | # 读取-I或者/I |
| 102 | for i, part in enumerate(parts): |
| 103 | if part.startswith('-I'): |
| 104 | include_dir = part[2:] if len(part) > 2 else parts[i + 1] |
| 105 | source_dirs.add(os.path.abspath(include_dir)) |
| 106 | elif part.startswith('/I'): |
| 107 | include_dir = part[2:] if len(part) > 2 else parts[i + 1] |
| 108 | source_dirs.add(os.path.abspath(include_dir)) |
| 109 | |
| 110 | return sorted(source_dirs) |
| 111 | |
| 112 | |
| 113 | def is_path_in_tree(path, tree): |
no test coverage detected