load("@rules_erlang//:erlang_bytecode2.bzl", "erlang_bytecode", "erlc_opts")
load("@rules_erlang//:erlang_app.bzl", "erlang_app")

erlc_opts(
    name = "erlc_opts",
    values = select({
        "@rules_erlang//:debug_build": [
            "+debug_info",
        ],
        "//conditions:default": [
            "+debug_info",
            "+deterministic",
        ],
    }),
    visibility = [":__subpackages__"],
)

erlang_bytecode(
    name = "other_beam",
    srcs = [
        "src/clients/eetcd_auth_gen.erl",
        "src/clients/eetcd_cluster_gen.erl",
        "src/clients/eetcd_election_gen.erl",
        "src/clients/eetcd_health_gen.erl",
        "src/clients/eetcd_kv_gen.erl",
        "src/clients/eetcd_lease_gen.erl",
        "src/clients/eetcd_lock_gen.erl",
        "src/clients/eetcd_maintenance_gen.erl",
        "src/clients/eetcd_watch_gen.erl",
        "src/eetcd.erl",
        "src/eetcd_app.erl",
        "src/eetcd_auth.erl",
        "src/eetcd_cluster.erl",
        "src/eetcd_compare.erl",
        "src/eetcd_conn.erl",
        "src/eetcd_conn_sup.erl",
        "src/eetcd_data_coercion.erl",
        "src/eetcd_election.erl",
        "src/eetcd_grpc.erl",
        "src/eetcd_kv.erl",
        "src/eetcd_lease.erl",
        "src/eetcd_lease_sup.erl",
        "src/eetcd_lock.erl",
        "src/eetcd_maintenance.erl",
        "src/eetcd_op.erl",
        "src/eetcd_stream.erl",
        "src/eetcd_sup.erl",
        "src/eetcd_watch.erl",
        "src/protos/auth_pb.erl",
        "src/protos/gogo_pb.erl",
        "src/protos/health_pb.erl",
        "src/protos/kv_pb.erl",
        "src/protos/router_pb.erl",
    ],
    outs = [
        "ebin/auth_pb.beam",
        "ebin/eetcd.beam",
        "ebin/eetcd_app.beam",
        "ebin/eetcd_auth.beam",
        "ebin/eetcd_auth_gen.beam",
        "ebin/eetcd_cluster.beam",
        "ebin/eetcd_cluster_gen.beam",
        "ebin/eetcd_compare.beam",
        "ebin/eetcd_conn.beam",
        "ebin/eetcd_conn_sup.beam",
        "ebin/eetcd_data_coercion.beam",
        "ebin/eetcd_election.beam",
        "ebin/eetcd_election_gen.beam",
        "ebin/eetcd_grpc.beam",
        "ebin/eetcd_health_gen.beam",
        "ebin/eetcd_kv.beam",
        "ebin/eetcd_kv_gen.beam",
        "ebin/eetcd_lease.beam",
        "ebin/eetcd_lease_gen.beam",
        "ebin/eetcd_lease_sup.beam",
        "ebin/eetcd_lock.beam",
        "ebin/eetcd_lock_gen.beam",
        "ebin/eetcd_maintenance.beam",
        "ebin/eetcd_maintenance_gen.beam",
        "ebin/eetcd_op.beam",
        "ebin/eetcd_stream.beam",
        "ebin/eetcd_sup.beam",
        "ebin/eetcd_watch.beam",
        "ebin/eetcd_watch_gen.beam",
        "ebin/gogo_pb.beam",
        "ebin/health_pb.beam",
        "ebin/kv_pb.beam",
        "ebin/router_pb.beam",
    ],
    hdrs = [
        "include/eetcd.hrl",
    ],
    app_name = "eetcd",
    erlc_opts = "//:erlc_opts",
)

filegroup(
    name = "beam_files",
    srcs = [":other_beam"],
)

filegroup(
    name = "srcs",
    srcs = [
        "src/clients/eetcd_auth_gen.erl",
        "src/clients/eetcd_cluster_gen.erl",
        "src/clients/eetcd_election_gen.erl",
        "src/clients/eetcd_health_gen.erl",
        "src/clients/eetcd_kv_gen.erl",
        "src/clients/eetcd_lease_gen.erl",
        "src/clients/eetcd_lock_gen.erl",
        "src/clients/eetcd_maintenance_gen.erl",
        "src/clients/eetcd_watch_gen.erl",
        "src/eetcd.app.src",
        "src/eetcd.erl",
        "src/eetcd_app.erl",
        "src/eetcd_auth.erl",
        "src/eetcd_cluster.erl",
        "src/eetcd_compare.erl",
        "src/eetcd_conn.erl",
        "src/eetcd_conn_sup.erl",
        "src/eetcd_data_coercion.erl",
        "src/eetcd_election.erl",
        "src/eetcd_grpc.erl",
        "src/eetcd_kv.erl",
        "src/eetcd_lease.erl",
        "src/eetcd_lease_sup.erl",
        "src/eetcd_lock.erl",
        "src/eetcd_maintenance.erl",
        "src/eetcd_op.erl",
        "src/eetcd_stream.erl",
        "src/eetcd_sup.erl",
        "src/eetcd_watch.erl",
        "src/protos/auth_pb.erl",
        "src/protos/gogo_pb.erl",
        "src/protos/health_pb.erl",
        "src/protos/kv_pb.erl",
        "src/protos/router_pb.erl",
    ],
)

filegroup(name = "private_hdrs")

filegroup(
    name = "public_hdrs",
    srcs = [
        "include/eetcd.hrl",
    ],
)

filegroup(
    name = "priv",
    srcs = [
        "priv/protos",
        "priv/protos/auth.proto",
        "priv/protos/gogo.proto",
        "priv/protos/kv.proto",
        "priv/protos/router.proto",
    ],
)

filegroup(
    name = "licenses",
    srcs = [
        "LICENSE",
    ],
)

filegroup(
    name = "public_and_private_hdrs",
    srcs = [
        ":private_hdrs",
        ":public_hdrs",
    ],
)

filegroup(
    name = "all_srcs",
    srcs = [
        ":public_and_private_hdrs",
        ":srcs",
    ],
)

erlang_app(
    name = "erlang_app",
    srcs = [":all_srcs"],
    hdrs = [":public_hdrs"],
    app_name = "eetcd",
    beam_files = [":beam_files"],
    deps = ["@gun//:erlang_app"],
)

alias(
    name = "eetcd",
    actual = ":erlang_app",
    visibility = ["//visibility:public"],
)
