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/cow_base64url.erl",
        "src/cow_cookie.erl",
        "src/cow_date.erl",
        "src/cow_hpack.erl",
        "src/cow_http.erl",
        "src/cow_http2.erl",
        "src/cow_http2_machine.erl",
        "src/cow_http_hd.erl",
        "src/cow_http_struct_hd.erl",
        "src/cow_http_te.erl",
        "src/cow_iolists.erl",
        "src/cow_link.erl",
        "src/cow_mimetypes.erl",
        "src/cow_multipart.erl",
        "src/cow_qs.erl",
        "src/cow_spdy.erl",
        "src/cow_sse.erl",
        "src/cow_uri.erl",
        "src/cow_uri_template.erl",
        "src/cow_ws.erl",
    ],
    hdrs = [":public_and_private_hdrs"],
    app_name = "cowlib",
    dest = "ebin",
    erlc_opts = "//:erlc_opts",
)

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

filegroup(
    name = "srcs",
    srcs = [
        "src/cow_base64url.erl",
        "src/cow_cookie.erl",
        "src/cow_date.erl",
        "src/cow_hpack.erl",
        "src/cow_http.erl",
        "src/cow_http2.erl",
        "src/cow_http2_machine.erl",
        "src/cow_http_hd.erl",
        "src/cow_http_struct_hd.erl",
        "src/cow_http_te.erl",
        "src/cow_iolists.erl",
        "src/cow_link.erl",
        "src/cow_mimetypes.erl",
        "src/cow_multipart.erl",
        "src/cow_qs.erl",
        "src/cow_spdy.erl",
        "src/cow_sse.erl",
        "src/cow_uri.erl",
        "src/cow_uri_template.erl",
        "src/cow_ws.erl",
    ],
)

filegroup(
    name = "private_hdrs",
    srcs = [
        "src/cow_hpack_dec_huffman_lookup.hrl",
        "src/cow_spdy.hrl",
    ],
)

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

filegroup(name = "priv")

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_description = "Support library for manipulating Web protocols.",
    app_name = "cowlib",
    app_version = "2.13.0",
    beam_files = [":beam_files"],
    extra_apps = ["crypto"],
    license_files = [":license_files"],
    priv = [":priv"],
)

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

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