"Toolchain repository"

def _toolchains_repo_impl(repository_ctx):
    build_content = """# Generated by toolchains_repo.bzl
toolchain(
    name = "toolchain",
    toolchain = "@{user_repository_name}//:bats_toolchain",
    toolchain_type = "@rules_bats//bats:toolchain_type",
)
""".format(
        user_repository_name = repository_ctx.attr.user_repository_name,
    )

    repository_ctx.file("BUILD.bazel", build_content)

toolchains_repo = repository_rule(
    _toolchains_repo_impl,
    doc = """Creates a repository with toolchain definitions for all known platforms
     which can be registered or selected.""",
    attrs = {
        "user_repository_name": attr.string(doc = "what the user chose for the base name"),
    },
)
