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",
            "+report_warnings",
            "+warn_export_vars",
            "+warn_missing_spec",
            "+warn_obsolete_guard",
            "+warn_untyped_record",
            "+warn_unused_import",
            "+warn_unused_vars",
            "+{warn_format,1}",
        ],
        "//conditions:default": [
            "+debug_info",
            "+deterministic",
            "+report_warnings",
            "+warn_export_vars",
            "+warn_missing_spec",
            "+warn_obsolete_guard",
            "+warn_untyped_record",
            "+warn_unused_import",
            "+warn_unused_vars",
            "+{warn_format,1}",
        ],
    }),
    visibility = [":__subpackages__"],
)

erlang_bytecode(
    name = "parse_transforms",
    testonly = True,
    srcs = [
        "src/vararg.erl",
    ],
    outs = [
        "ebin/vararg.beam",
    ],
    hdrs = [
        "include/proper.hrl",
        "include/proper_common.hrl",
        "include/proper_internal.hrl",
        "include/proper_param_adts.hrl",
    ],
    app_name = "proper",
    erlc_opts = "//:erlc_opts",
)

erlang_bytecode(
    name = "behaviours",
    testonly = True,
    srcs = [
        "src/proper_target.erl",
    ],
    outs = [
        "ebin/proper_target.beam",
    ],
    hdrs = [
        "include/proper.hrl",
        "include/proper_common.hrl",
        "include/proper_internal.hrl",
        "include/proper_param_adts.hrl",
    ],
    app_name = "proper",
    beam = [":parse_transforms"],
    erlc_opts = "//:erlc_opts",
)

erlang_bytecode(
    name = "other_beam",
    testonly = True,
    srcs = [
        "src/proper.erl",
        "src/proper_arith.erl",
        "src/proper_array.erl",
        "src/proper_dict.erl",
        "src/proper_erlang_abstract_code.erl",
        "src/proper_fsm.erl",
        "src/proper_gb_sets.erl",
        "src/proper_gb_trees.erl",
        "src/proper_gen.erl",
        "src/proper_gen_next.erl",
        "src/proper_orddict.erl",
        "src/proper_ordsets.erl",
        "src/proper_prop_remover.erl",
        "src/proper_queue.erl",
        "src/proper_sa.erl",
        "src/proper_sets.erl",
        "src/proper_shrink.erl",
        "src/proper_statem.erl",
        "src/proper_symb.erl",
        "src/proper_transformer.erl",
        "src/proper_types.erl",
        "src/proper_typeserver.erl",
        "src/proper_unicode.erl",
        "src/proper_unused_imports_remover.erl",
    ],
    outs = [
        "ebin/proper.beam",
        "ebin/proper_arith.beam",
        "ebin/proper_array.beam",
        "ebin/proper_dict.beam",
        "ebin/proper_erlang_abstract_code.beam",
        "ebin/proper_fsm.beam",
        "ebin/proper_gb_sets.beam",
        "ebin/proper_gb_trees.beam",
        "ebin/proper_gen.beam",
        "ebin/proper_gen_next.beam",
        "ebin/proper_orddict.beam",
        "ebin/proper_ordsets.beam",
        "ebin/proper_prop_remover.beam",
        "ebin/proper_queue.beam",
        "ebin/proper_sa.beam",
        "ebin/proper_sets.beam",
        "ebin/proper_shrink.beam",
        "ebin/proper_statem.beam",
        "ebin/proper_symb.beam",
        "ebin/proper_transformer.beam",
        "ebin/proper_types.beam",
        "ebin/proper_typeserver.beam",
        "ebin/proper_unicode.beam",
        "ebin/proper_unused_imports_remover.beam",
    ],
    hdrs = [
        "include/proper.hrl",
        "include/proper_common.hrl",
        "include/proper_internal.hrl",
        "include/proper_param_adts.hrl",
    ],
    app_name = "proper",
    beam = [
        ":parse_transforms",
        ":behaviours",
    ],
    erlc_opts = "//:erlc_opts",
)

filegroup(
    name = "beam_files",
    testonly = True,
    srcs = [
        ":behaviours",
        ":other_beam",
        ":parse_transforms",
    ],
)

filegroup(
    name = "srcs",
    testonly = True,
    srcs = [
        "src/proper.app.src",
        "src/proper.erl",
        "src/proper_arith.erl",
        "src/proper_array.erl",
        "src/proper_dict.erl",
        "src/proper_erlang_abstract_code.erl",
        "src/proper_fsm.erl",
        "src/proper_gb_sets.erl",
        "src/proper_gb_trees.erl",
        "src/proper_gen.erl",
        "src/proper_gen_next.erl",
        "src/proper_orddict.erl",
        "src/proper_ordsets.erl",
        "src/proper_prop_remover.erl",
        "src/proper_queue.erl",
        "src/proper_sa.erl",
        "src/proper_sets.erl",
        "src/proper_shrink.erl",
        "src/proper_statem.erl",
        "src/proper_symb.erl",
        "src/proper_target.erl",
        "src/proper_transformer.erl",
        "src/proper_types.erl",
        "src/proper_typeserver.erl",
        "src/proper_unicode.erl",
        "src/proper_unused_imports_remover.erl",
        "src/vararg.erl",
    ],
)

filegroup(
    name = "private_hdrs",
    testonly = True,
)

filegroup(
    name = "public_hdrs",
    testonly = True,
    srcs = [
        "include/proper.hrl",
        "include/proper_common.hrl",
        "include/proper_internal.hrl",
        "include/proper_param_adts.hrl",
    ],
)

filegroup(
    name = "priv",
    testonly = True,
)

filegroup(
    name = "licenses",
    testonly = True,
)

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

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

erlang_app(
    name = "erlang_app",
    testonly = True,
    srcs = [":all_srcs"],
    hdrs = [":public_hdrs"],
    app_name = "proper",
    beam_files = [":beam_files"],
    extra_apps = ["compiler"],
)

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