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",
            "+strict_validation",
            "+warn_bif_clash",
            "+warn_deprecated_function",
            "+warn_export_all",
            "+warn_export_vars",
            "+warn_exported_vars",
            "+warn_obsolete_guard",
            "+warn_shadow_vars",
            "+warn_unused_function",
            "+warn_unused_import",
            "+warn_unused_record",
            "+warn_unused_vars",
            "+warnings_as_errors",
        ],
        "//conditions:default": [
            "+debug_info",
            "+deterministic",
            "+strict_validation",
            "+warn_bif_clash",
            "+warn_deprecated_function",
            "+warn_export_all",
            "+warn_export_vars",
            "+warn_exported_vars",
            "+warn_obsolete_guard",
            "+warn_shadow_vars",
            "+warn_unused_function",
            "+warn_unused_import",
            "+warn_unused_record",
            "+warn_unused_vars",
            "+warnings_as_errors",
        ],
    }),
    visibility = [":__subpackages__"],
)

erlang_bytecode(
    name = "behaviours",
    srcs = [
        "src/prometheus_collector.erl",
        "src/prometheus_format.erl",
        "src/prometheus_instrumenter.erl",
        "src/prometheus_metric.erl",
    ],
    outs = [
        "ebin/prometheus_collector.beam",
        "ebin/prometheus_format.beam",
        "ebin/prometheus_instrumenter.beam",
        "ebin/prometheus_metric.beam",
    ],
    hdrs = [
        "include/prometheus.hrl",
        "include/prometheus_model.hrl",
    ],
    app_name = "prometheus",
    erlc_opts = "//:erlc_opts",
)

erlang_bytecode(
    name = "other_beam",
    srcs = [
        "src/collectors/mnesia/prometheus_mnesia_collector.erl",
        "src/collectors/vm/prometheus_vm_dist_collector.erl",
        "src/collectors/vm/prometheus_vm_memory_collector.erl",
        "src/collectors/vm/prometheus_vm_msacc_collector.erl",
        "src/collectors/vm/prometheus_vm_statistics_collector.erl",
        "src/collectors/vm/prometheus_vm_system_info_collector.erl",
        "src/contrib/prometheus_http.erl",
        "src/contrib/prometheus_mnesia.erl",
        "src/contrib/prometheus_test_instrumenter.erl",
        "src/formats/prometheus_protobuf_format.erl",
        "src/formats/prometheus_text_format.erl",
        "src/metrics/prometheus_boolean.erl",
        "src/metrics/prometheus_counter.erl",
        "src/metrics/prometheus_gauge.erl",
        "src/metrics/prometheus_histogram.erl",
        "src/metrics/prometheus_quantile_summary.erl",
        "src/metrics/prometheus_summary.erl",
        "src/model/prometheus_model.erl",
        "src/model/prometheus_model_helpers.erl",
        "src/prometheus.erl",
        "src/prometheus_buckets.erl",
        "src/prometheus_metric_spec.erl",
        "src/prometheus_misc.erl",
        "src/prometheus_registry.erl",
        "src/prometheus_sup.erl",
        "src/prometheus_time.erl",
    ],
    outs = [
        "ebin/prometheus.beam",
        "ebin/prometheus_boolean.beam",
        "ebin/prometheus_buckets.beam",
        "ebin/prometheus_counter.beam",
        "ebin/prometheus_gauge.beam",
        "ebin/prometheus_histogram.beam",
        "ebin/prometheus_http.beam",
        "ebin/prometheus_metric_spec.beam",
        "ebin/prometheus_misc.beam",
        "ebin/prometheus_mnesia.beam",
        "ebin/prometheus_mnesia_collector.beam",
        "ebin/prometheus_model.beam",
        "ebin/prometheus_model_helpers.beam",
        "ebin/prometheus_protobuf_format.beam",
        "ebin/prometheus_quantile_summary.beam",
        "ebin/prometheus_registry.beam",
        "ebin/prometheus_summary.beam",
        "ebin/prometheus_sup.beam",
        "ebin/prometheus_test_instrumenter.beam",
        "ebin/prometheus_text_format.beam",
        "ebin/prometheus_time.beam",
        "ebin/prometheus_vm_dist_collector.beam",
        "ebin/prometheus_vm_memory_collector.beam",
        "ebin/prometheus_vm_msacc_collector.beam",
        "ebin/prometheus_vm_statistics_collector.beam",
        "ebin/prometheus_vm_system_info_collector.beam",
    ],
    hdrs = [
        "include/prometheus.hrl",
        "include/prometheus_model.hrl",
    ],
    app_name = "prometheus",
    beam = [":behaviours"],
    erlc_opts = "//:erlc_opts",
    deps = ["@quantile_estimator//:erlang_app"],
)

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

filegroup(
    name = "srcs",
    srcs = [
        "src/collectors/mnesia/prometheus_mnesia_collector.erl",
        "src/collectors/vm/prometheus_vm_dist_collector.erl",
        "src/collectors/vm/prometheus_vm_memory_collector.erl",
        "src/collectors/vm/prometheus_vm_msacc_collector.erl",
        "src/collectors/vm/prometheus_vm_statistics_collector.erl",
        "src/collectors/vm/prometheus_vm_system_info_collector.erl",
        "src/contrib/prometheus_http.erl",
        "src/contrib/prometheus_mnesia.erl",
        "src/contrib/prometheus_test_instrumenter.erl",
        "src/formats/prometheus_protobuf_format.erl",
        "src/formats/prometheus_text_format.erl",
        "src/metrics/prometheus_boolean.erl",
        "src/metrics/prometheus_counter.erl",
        "src/metrics/prometheus_gauge.erl",
        "src/metrics/prometheus_histogram.erl",
        "src/metrics/prometheus_quantile_summary.erl",
        "src/metrics/prometheus_summary.erl",
        "src/model/prometheus_model.erl",
        "src/model/prometheus_model_helpers.erl",
        "src/prometheus.app.src",
        "src/prometheus.erl",
        "src/prometheus_buckets.erl",
        "src/prometheus_collector.erl",
        "src/prometheus_format.erl",
        "src/prometheus_instrumenter.erl",
        "src/prometheus_metric.erl",
        "src/prometheus_metric_spec.erl",
        "src/prometheus_misc.erl",
        "src/prometheus_registry.erl",
        "src/prometheus_sup.erl",
        "src/prometheus_time.erl",
    ],
)

filegroup(
    name = "private_hdrs",
    srcs = [],
)

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

filegroup(
    name = "priv",
    srcs = [],
)

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 = "prometheus",
    beam_files = [":beam_files"],
    deps = ["@quantile_estimator//:erlang_app"],
)

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