package(default_visibility = ["//visibility:public"])

load("@io_k8s_repo_infra//defs:run_in_workspace.bzl", "workspace_binary")

genrule(
    name = "fetch_jq",
    srcs = select({
        ":darwin": ["@jq_osx//file"],
        ":k8": ["@jq_linux//file"],
    }),
    outs = ["jq"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_helm",
    srcs = select({
        ":darwin": ["@helm_darwin//:file"],
        ":k8": ["@helm_linux//:file"],
    }),
    outs = ["helm"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "com_coreos_etcd",
    srcs = select({
        ":darwin": ["@kubebuilder-tools_darwin_amd64//:etcd"],
        ":k8": ["@kubebuilder-tools_linux_amd64//:etcd"],
    }),
    outs = ["etcd"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "co_honnef_go_tools_staticcheck",
    srcs = select({
        ":darwin": ["@co_honnef_go_tools_staticcheck_osx//:file"],
        ":k8": ["@co_honnef_go_tools_staticcheck_linux//:file"],
    }),
    outs = ["staticcheck"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "io_kubernetes_kube-apiserver",
    srcs = select({
        ":darwin": ["@kubebuilder-tools_darwin_amd64//:kube-apiserver"],
        ":k8": ["@kubebuilder-tools_linux_amd64//:kube-apiserver"],
    }),
    outs = ["kube-apiserver"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_kubectl",
    srcs = select({
        ":darwin": ["@kubectl_1_21_darwin//file"],
        ":k8": ["@kubectl_1_21_linux//file"],
    }),
    outs = ["kubectl"],
    cmd = "cp $(SRCS) $@",
    tags = ["manual"],
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_oc3",
    srcs = select({
        ":k8": ["@oc_3_11_linux//:file"],
    }),
    outs = ["oc3"],
    cmd = "cp $(SRCS) $@",
    tags = ["manual"],
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_buildozer",
    srcs = select({
        ":darwin": ["@buildozer_darwin//file"],
        ":k8": ["@buildozer_linux//file"],
    }),
    outs = ["buildozer"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_kazel",
    srcs = ["@io_k8s_repo_infra//cmd/kazel"],
    outs = ["kazel"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_gazelle",
    srcs = ["@bazel_gazelle//cmd/gazelle"],
    outs = ["gazelle"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_gofmt",
    srcs = ["@go_sdk//:bin/gofmt"],
    outs = ["gofmt"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

workspace_binary(
    name = "go",
    cmd = "@go_sdk//:bin/go",
)

workspace_binary(
    name = "kubectl-cert_manager",
    cmd = "//cmd/ctl:ctl",
)

genrule(
    name = "fetch_kind",
    srcs = select({
        ":darwin": ["@kind_darwin//file"],
        ":k8": ["@kind_linux//file"],
    }),
    outs = ["kind"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_controller-gen",
    srcs = ["@io_k8s_sigs_controller_tools//cmd/controller-gen"],
    outs = ["controller-gen"],
    cmd = "cp $(SRCS) $@",
    visibility = ["//visibility:public"],
)

genrule(
    name = "fetch_ytt",
    srcs = select({
        ":darwin": ["@ytt_darwin//file"],
        ":k8": ["@ytt_linux//file"],
    }),
    outs = ["ytt"],
    cmd = "cp $(SRCS) $@",
)

config_setting(
    name = "k8",
    values = {"host_cpu": "k8"},
    visibility = ["//visibility:private"],
)

config_setting(
    name = "darwin",
    values = {"host_cpu": "darwin"},
    visibility = ["//visibility:private"],
)

filegroup(
    name = "package-srcs",
    srcs = glob(["**"]),
    tags = ["automanaged"],
    visibility = ["//visibility:private"],
)

filegroup(
    name = "all-srcs",
    srcs = [":package-srcs"],
    tags = ["automanaged"],
    visibility = ["//visibility:public"],
)
