Parses devicetree.yaml and recursively finds dependencies. Returns a list of DeviceTreeConfig objects in post-order (dependencies first).
(file_path: str, project_root: str)
| 9 | dts: str = "" |
| 10 | |
| 11 | def parse_config(file_path: str, project_root: str) -> DeviceTreeConfig: |
| 12 | """ |
| 13 | Parses devicetree.yaml and recursively finds dependencies. |
| 14 | Returns a list of DeviceTreeConfig objects in post-order (dependencies first). |
| 15 | """ |
| 16 | config = DeviceTreeConfig([], [], "") |
| 17 | visited = set() |
| 18 | |
| 19 | def _parse_recursive(current_path: str, is_root: bool): |
| 20 | abs_path = os.path.abspath(current_path) |
| 21 | if abs_path in visited: |
| 22 | return |
| 23 | visited.add(abs_path) |
| 24 | |
| 25 | # Try to see if it's a directory and contains devicetree.yaml |
| 26 | if os.path.isdir(abs_path): |
| 27 | abs_path = os.path.join(abs_path, "devicetree.yaml") |
| 28 | |
| 29 | with open(abs_path, 'r') as f: |
| 30 | data = yaml.safe_load(f) or {} |
| 31 | |
| 32 | # Handle dependencies before adding current config (post-order) |
| 33 | deps = data.get("dependencies", []) |
| 34 | for dep in deps: |
| 35 | # Dependencies are relative to project_root |
| 36 | dep_path = os.path.join(project_root, dep) |
| 37 | _parse_recursive(dep_path, False) |
| 38 | |
| 39 | if is_root: |
| 40 | config.dependencies += deps |
| 41 | dts_path = data.get("dts", "") |
| 42 | config.dts = os.path.join(current_path, dts_path) |
| 43 | |
| 44 | bindings = data.get("bindings", "") |
| 45 | if bindings: |
| 46 | bindings_resolved = os.path.join(current_path, bindings) |
| 47 | config.bindings.append(bindings_resolved) |
| 48 | |
| 49 | _parse_recursive(file_path, True) |
| 50 | return config |
no test coverage detected