# Copyright 2024 The Pigweed Authors
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
#     https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.

load("@bazel_tools//tools/cpp:toolchain_utils.bzl", "find_cpp_toolchain", "use_cpp_toolchain")
load("@rules_cc//cc:action_names.bzl", "C_COMPILE_ACTION_NAME")

def _get_inputs(ctx):
    all_input_files = [ctx.file.overlay]
    for label in ctx.attr.references:
        if type(label) == "Target" and label.files.to_list():
            all_input_files.extend(label.files.to_list())
        else:
            fail("Unsupported target kind in references:", label)
    return depset(all_input_files)

def _package_exec_path(ctx):
    workspace_name = ctx.label.workspace_name
    if workspace_name == "":
        return "."
    return "external/" + workspace_name + "/" + ctx.label.package

def _dts_library_impl(ctx):
    sources = [ctx.file.overlay]
    include_paths = ctx.attr.includes
    output_header = ctx.actions.declare_file(ctx.label.name + ".dts")
    cc_toolchain = find_cpp_toolchain(ctx)
    workspace_root = ctx.label.workspace_root
    zephyr_root = Label("@zephyr//:west.yml").workspace_root
    feature_configuration = cc_common.configure_features(
        ctx = ctx,
        cc_toolchain = cc_toolchain,
        requested_features = ctx.features,
        unsupported_features = ctx.disabled_features,
    )
    cxx_compiler_path = cc_common.get_tool_for_action(
        feature_configuration = feature_configuration,
        action_name = C_COMPILE_ACTION_NAME,
    )

    print("Declaring file: ", output_header.path)
    print("workspace_name: ", ctx.label.workspace_root)
    for dep in ctx.attr.deps:
        if hasattr(dep, "files"):
            sources.extend(dep.files)
        else:
            fail("Dependency", dep, "does not contain files.")

    args = [
        "-x",
        "assembler-with-cpp",
        "-nostdinc",
    ]
    source_count = 0
    for src in sources:
        if source_count != 0:
            args.append("-include")
        args.append(src.path)
        source_count += 1

    root_path = _package_exec_path(ctx)
    for path in include_paths:
        flag = "-I" + root_path + "/" + path
        print("    flag=%s" % (flag))
        args.append(flag)
    args.extend([
        "-I",
        "-D__DTS__",
        "-E",
        "-o",
        output_header.path,
    ])
    print("Running: ", cxx_compiler_path, " ".join(args))

    ctx.actions.run(
        inputs = _get_inputs(ctx),
        outputs = [output_header],
        arguments = args,
        executable = cxx_compiler_path,
        tools = cc_toolchain.all_files,
        mnemonic = "DtsPreCompile",
    )
    return [
        DefaultInfo(files = depset([output_header])),
    ]

dts_library = rule(
    implementation = _dts_library_impl,
    attrs = {
        "deps": attr.label_list(allow_files = False),
        "includes": attr.string_list(),
        "overlay": attr.label(mandatory = True, allow_single_file = True),
        "references": attr.label_list(allow_files = True),
        "_cc_toolchain": attr.label(
            default = Label("@bazel_tools//tools/cpp:current_cc_toolchain"),
        ),
    },
    toolchains = use_cpp_toolchain(),
    fragments = ["cpp"],
)

def _dts_cc_library_impl(ctx):
    output_dts = ctx.actions.declare_file("dts_out.dts")
    output_header_name = "zephyr/devicetree_generated.h"
    output_header = ctx.actions.declare_file(output_header_name)
    dts_file = ctx.attr.dts_lib[DefaultInfo].files.to_list()[0]

    gen_defines_target = ctx.attr._gen_defines[DefaultInfo]

    args = [
        "--dts",
        dts_file.path,
        "--bindings-dirs",
        "external/zephyr/dts/bindings",
        "--header-out",
        output_header.path,
        "--dts-out",
        output_dts.path,
        "--dtc-flags",
        "Wno-simple_bus_reg",
    ]
    print(" ".join(args))
    ctx.actions.run(
        inputs = gen_defines_target.files.to_list() + [dts_file],
        outputs = [output_header, output_dts],
        executable = gen_defines_target.files_to_run.executable,
        arguments = args,
        mnemonic = "DtsGenDefines",
        progress_message = "Running DTS definition generator",
    )
    return [
        DefaultInfo(files = depset([output_header])),
        CcInfo(
            compilation_context = cc_common.create_compilation_context(
                includes = depset([output_header.path[:-len(output_header_name)]]),
                headers = depset([output_header]),
            ),
        ),
    ]

dts_cc_library = rule(
    implementation = _dts_cc_library_impl,
    attrs = {
        "dts_lib": attr.label(allow_files = False),
        "_gen_defines": attr.label(
            default = "//scripts/dts:gen_defines",
            executable = True,
            cfg = "exec",
        ),
    },
    provides = [CcInfo],
)
