(config_path: str, output_path: str, verbose: bool)
| 12 | from source.exception import DevicetreeException |
| 13 | |
| 14 | def main(config_path: str, output_path: str, verbose: bool) -> int: |
| 15 | print(f"Generating devicetree code\n config: {config_path}\n output: {output_path}") |
| 16 | if not os.path.isdir(config_path): |
| 17 | print(f"Directory not found: {config_path}") |
| 18 | return 1 |
| 19 | |
| 20 | config = parse_config(config_path, os.getcwd()) |
| 21 | if verbose: |
| 22 | pprint(config) |
| 23 | |
| 24 | try: |
| 25 | project_dir = os.path.dirname(os.path.realpath(__file__)) |
| 26 | grammar_path = os.path.join(project_dir, "grammar.lark") |
| 27 | lark_data = read_file(grammar_path) |
| 28 | dts_data = read_file(config.dts) |
| 29 | lark = Lark(lark_data) |
| 30 | parsed = lark.parse(dts_data) |
| 31 | if verbose: |
| 32 | print(parsed.pretty()) |
| 33 | transformed = DtsTransformer().transform(parsed) |
| 34 | if verbose: |
| 35 | pprint(transformed) |
| 36 | binding_files = find_all_bindings(config.bindings) |
| 37 | if verbose: |
| 38 | print("Bindings found:") |
| 39 | for binding_file in binding_files: |
| 40 | print(f" {binding_file}") |
| 41 | if verbose: |
| 42 | print("Parsing bindings") |
| 43 | bindings = [] |
| 44 | for binding_file in binding_files: |
| 45 | bindings.append(parse_binding(binding_file, config.bindings)) |
| 46 | if verbose: |
| 47 | for binding in bindings: |
| 48 | pprint(binding) |
| 49 | generate(output_path, transformed, bindings, config, verbose) |
| 50 | return 0 |
| 51 | except DevicetreeException as caught: |
| 52 | print("\033[31mError: ", caught, "\033[0m") |
| 53 | return 1 |
no test coverage detected