#!/usr/bin/env python3
# Copyright lowRISC contributors.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

import logging
import subprocess
import sys
from pathlib import Path
from typing import List

from autogen_banner import get_autogen_banner
from make_new_dif.ip import Ip
from mako.template import Template

# This file is $REPO_TOP/util/autogen_testutils.py, so it takes two parent()
# calls to get back to the top.
REPO_TOP = Path(__file__).resolve().parent.parent.parent


def gen_testutils(ips_with_difs: List[Ip]) -> None:
    """Generate testutils libraries that are rendered from Mako templates.

    Args:
        ips_with_difs: List of IP objects that have existing DIF libraries.

    Returns:
        None
    """
    # Sort input so the templates get rendered in the same order every time.
    ips_with_difs.sort(key=lambda ip: ip.name_snake)

    # Define input/output directories.
    testutils_templates_dir = REPO_TOP / "util/autogen_testutils/templates"
    autogen_testutils_dir = REPO_TOP / "sw/device/lib/testing/autogen"

    # Create output directories if needed.
    autogen_testutils_dir.mkdir(exist_ok=True)

    testutilses = []

    # Render templates.
    for testutils_template_path in testutils_templates_dir.iterdir():
        if testutils_template_path.suffix == ".tpl":
            comment_syntax = "#" if testutils_template_path.stem.endswith(
                ".build") else "//"
            # Read in template, render it, and write it to the output file.
            testutils_template = Template(testutils_template_path.read_text())
            testutils = autogen_testutils_dir / testutils_template_path.stem
            testutils.write_text(
                testutils_template.render(ips_with_difs=ips_with_difs,
                                          autogen_banner=get_autogen_banner(
                                              "util/autogen_testutils.py",
                                              comment=comment_syntax)))
            testutilses += [testutils]

    # Format autogenerated file with clang-format.
    try:
        subprocess.check_call(
            ["./bazelisk.sh", "run", "//quality:clang_format_fix", "--"] + testutilses
        )
    except subprocess.CalledProcessError:
        logging.error(
            f"failed to format {testutilses} with clang-format.")
        sys.exit(1)

    print(f"testutils successfully written to {str(testutilses)}.")
