def _local_patched_repository_impl(rctx):
    path = rctx.attr.path

    # This path is a bit ugly to get the actual path if it is relative.
    if path[0] != "/":
        path = rctx.workspace_root.get_child(path)

    # Copy the repository
    rctx.execute(["mkdir", str(rctx.path(""))])
    for child in path.readdir():
        copy_args = ["cp", "-fr", str(child), str(rctx.path(""))]
        if rctx.attr.debug:
            print(copy_args)
        result = rctx.execute(copy_args)
        if result.return_code != 0:
            fail("Failed to copy %s (%s):\n%s" % (rctx.attr.path, result.return_code, result.stderr))

    # Now patch the repository
    for patch_file in rctx.attr.patches:
        patch_file_path_string = str(rctx.path(patch_file).realpath)
        if rctx.attr.debug:
            print("Applying patch file: %s / %s" % (patch_file, patch_file_path_string))
        result = rctx.execute([
            "bash",
            "-c",
            "patch -p0 < " + patch_file_path_string,
        ])
        if result.return_code != 0:
            fail("Failed to apply patch: %s\n%s" % (patch_file, result.stderr))

local_patched_repository = repository_rule(
    implementation = _local_patched_repository_impl,
    attrs = {
        "debug": attr.bool(default = False),
        "patches": attr.label_list(allow_files = True),
        "path": attr.string(mandatory = True),
    },
    local = True,
)

def _create_zephyr_patch_file_impl(rctx):
    script_path = Label("//:generate_diff.py")
    output_file = rctx.attr.filename
    output_file_path = rctx.path(output_file)

    rctx.file(output_file)
    rctx.file("BUILD")

    args = [
        rctx.which("python3"),
        script_path,
        "--root-dir",
        rctx.path(script_path).dirname,
        "-o",
        output_file_path,
    ]
    if rctx.attr.debug:
        print(args)
    result = rctx.execute(args)
    if result.return_code != 0:
        fail("Failed to generate zephyr-bazel diff file (%s):\n%s" % (result.return_code, result.stderr))

    if rctx.attr.debug:
        print("Generated %s" % (output_file_path))
    return [
        DefaultInfo(
            files = depset([output_file_path, rctx.path("BUILD")]),
        ),
    ]

create_zephyr_patch_file = repository_rule(
    implementation = _create_zephyr_patch_file_impl,
    attrs = {
        "debug": attr.bool(default = False),
        "filename": attr.string(
            default = "patch.diff",
            mandatory = True,
        ),
    },
    local = True,
)

###############################################################################

def _print_file_impl(ctx):
    # Get the input file
    input_file = ctx.file.file

    # Create a dummy output file
    output_file = ctx.actions.declare_file(ctx.label.name + ".out")

    # Create a shell action to print the file
    ctx.actions.run_shell(
        outputs = [output_file],
        inputs = [input_file],
        command = "cat {} > {}".format(input_file.path, output_file.path),
    )

    # Return DefaultInfo to signal dependencies on the input file
    return DefaultInfo(files = depset([output_file]))

# Define the rule
print_file = rule(
    implementation = _print_file_impl,
    attrs = {
        "file": attr.label(allow_single_file = True, mandatory = True),
    },
)
