Hugo McNally | 749cc2e | 2023-02-16 14:07:49 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # Copyright lowRISC contributors. |
| 3 | # Licensed under the Apache License, Version 2.0, see LICENSE for details. |
| 4 | # SPDX-License-Identifier: Apache-2.0 |
| 5 | import json |
| 6 | import sys |
| 7 | import io |
| 8 | import re |
| 9 | from pathlib import Path |
| 10 | |
| 11 | import dashboard.gen_dashboard_entry as dashboard |
| 12 | from mdbook import utils as md_utils |
| 13 | |
| 14 | # We are looking to match on the following example strings |
| 15 | # {{#dashboard comportable }} |
| 16 | DASHBOARD_PATTERN = re.compile(r'\{\{#dashboard\s+?(.+?)\s*\}\}') |
| 17 | IP_CFG_PATTERN = re.compile(r'.+/data/(?!.+(_testplan|example)).+\.hjson') |
| 18 | REPO_TOP = Path(__file__).resolve().parents[1] |
| 19 | |
| 20 | # FIXME: It would be nice if this isn't hard coded. |
| 21 | DASHBOARDS = { |
| 22 | 'comportable': [ |
| 23 | "hw/ip/aes/data/aes.hjson", |
| 24 | "hw/ip/aon_timer/data/aon_timer.hjson", |
| 25 | "hw/ip/entropy_src/data/entropy_src.hjson", |
| 26 | "hw/ip/csrng/data/csrng.hjson", |
| 27 | "hw/ip/adc_ctrl/data/adc_ctrl.hjson", |
| 28 | "hw/ip/edn/data/edn.hjson", |
| 29 | "hw/ip/flash_ctrl/data/flash_ctrl.hjson", |
| 30 | "hw/ip/gpio/data/gpio.hjson", |
| 31 | "hw/ip/hmac/data/hmac.hjson", |
| 32 | "hw/ip/i2c/data/i2c.hjson", |
| 33 | "hw/ip/keymgr/data/keymgr.hjson", |
| 34 | "hw/ip/kmac/data/kmac.hjson", |
| 35 | "hw/ip/lc_ctrl/data/lc_ctrl.hjson", |
| 36 | "hw/ip/otbn/data/otbn.hjson", |
| 37 | "hw/ip/otp_ctrl/data/otp_ctrl.hjson", |
| 38 | "hw/ip/pattgen/data/pattgen.hjson", |
| 39 | "hw/ip/pwm/data/pwm.hjson", |
| 40 | "hw/ip/rom_ctrl/data/rom_ctrl.hjson", |
| 41 | "hw/ip/rv_dm/data/rv_dm.hjson", |
| 42 | "hw/ip/rv_core_ibex/data/rv_core_ibex.hjson", |
| 43 | "hw/ip/rv_timer/data/rv_timer.hjson", |
| 44 | "hw/ip/spi_host/data/spi_host.hjson", |
| 45 | "hw/ip/spi_device/data/spi_device.hjson", |
| 46 | "hw/ip/sram_ctrl/data/sram_ctrl.hjson", |
| 47 | "hw/ip/sysrst_ctrl/data/sysrst_ctrl.hjson", |
| 48 | "hw/ip/uart/data/uart.hjson", |
| 49 | "hw/ip/usbdev/data/usbdev.hjson", |
| 50 | ], |
| 51 | 'top_earlgrey': [ |
| 52 | "hw/top_earlgrey/ip_autogen/alert_handler/data/alert_handler.hjson", |
| 53 | "hw/top_earlgrey/ip/pinmux/data/autogen/pinmux.hjson", |
| 54 | "hw/top_earlgrey/ip/clkmgr/data/autogen/clkmgr.hjson", |
| 55 | "hw/top_earlgrey/ip/pwrmgr/data/autogen/pwrmgr.hjson", |
| 56 | "hw/top_earlgrey/ip/rstmgr/data/autogen/rstmgr.hjson", |
| 57 | "hw/top_earlgrey/ip/sensor_ctrl/data/sensor_ctrl.hjson", |
| 58 | "hw/top_earlgrey/ip_autogen/rv_plic/data/rv_plic.hjson", |
| 59 | ], |
| 60 | } |
| 61 | |
| 62 | DASHBOARD_TEMPLATE = """ |
| 63 | <table class="hw-project-dashboard"> |
| 64 | <thead> |
| 65 | <tr> |
| 66 | <th>Design Spec</th> |
| 67 | <th>DV Document</th> |
| 68 | <th><a href="/doc/project_governance/development_stages.html#versioning">Spec Version</a></th> |
| 69 | <th colspan="4"> |
| 70 | <a href="/doc/project_governance/development_stages.html#life-stages"> |
| 71 | Development Stage |
| 72 | </a> |
| 73 | </th> |
| 74 | <th>Notes</th> |
| 75 | </tr> |
| 76 | </thead> |
| 77 | <tbody> |
| 78 | {} |
| 79 | </tbody> |
| 80 | </table> |
| 81 | """ |
| 82 | |
| 83 | |
| 84 | def main() -> None: |
| 85 | md_utils.supports_html_only() |
| 86 | |
| 87 | # Generate the dashboards |
| 88 | # gen_dashboards() |
| 89 | |
| 90 | # load both the context and the book from stdin |
| 91 | context, book = json.load(sys.stdin) |
| 92 | |
| 93 | for chapter in md_utils.chapters(book["sections"]): |
| 94 | # Add in the generated dashboard html |
| 95 | chapter['content'] = DASHBOARD_PATTERN.sub( |
| 96 | replace_with_dashboard, |
| 97 | chapter['content']) |
| 98 | |
| 99 | # dump the book into stdout |
| 100 | print(json.dumps(book)) |
| 101 | |
| 102 | |
| 103 | def replace_with_dashboard(m: re.Match) -> str: |
| 104 | name = m.group(1) |
| 105 | |
| 106 | try: |
| 107 | cfg_files = DASHBOARDS[name] |
| 108 | except KeyError: |
| 109 | sys.exit("A dashboard with name {}, {{#dashboard {} }}, doesn't exist".format(name, name)) |
| 110 | |
| 111 | buffer = io.StringIO() |
| 112 | for cfg_file in sorted(cfg_files): |
| 113 | dashboard.gen_dashboard_html(REPO_TOP / cfg_file, buffer) |
| 114 | |
| 115 | return DASHBOARD_TEMPLATE.format(buffer.getvalue()) |
| 116 | |
| 117 | |
| 118 | if __name__ == "__main__": |
| 119 | main() |