% -*- mode: erlang; -*- vim: set ft=erlang:

%% == Erlang Compiler == %%

% but only 24+ is supported
{minimum_otp_vsn, "21.0"}.

{erl_opts, [
    debug_info,
    warn_export_vars,
    warn_missing_spec,
    warn_unused_import,
    warnings_as_errors,
    %
    {platform_define, "^22\\.", 'NO_CT_SUITE_BEHAVIOUR'},
    {platform_define, "^23\\.[0-1]", 'NO_CT_SUITE_BEHAVIOUR'},
    %
    % EEP-48 doc attributes (OTP 27+)
    {platform_define, "^2[7-9]\\.", 'E48'},
    {platform_define, "^[3-9]", 'E48'}
]}.

%% == Dependencies and plugins ==

{deps, []}.

{project_plugins, [
    {erlfmt, "~> 1.7"},
    % excluded on older OTP versions (see rebar.config.script)
    {rebar3_hank, "~> 1.6"},
    {rebar3_hex, "~> 7.1"},
    % excluded on older OTP versions (see rebar.config.script)
    {rebar3_lint, "~> 5.0"}
]}.

%% == Formatter ==

{erlfmt, [
    write,
    {files, [
        "elvis.config",
        "ex_doc.config",
        "rebar.config",
        "shell.config",
        "{src,test,check}/*.{hrl,erl}"
    ]}
]}.

%% == Dialyzer ==

{dialyzer, [
    {warnings, [
        error_handling,
        underspecs,
        unknown,
        unmatched_returns
    ]},
    {plt_extra_apps, [
        common_test
    ]}
]}.

%% == Xref ==

{xref_checks, [
    deprecated_function_calls,
    exports_not_used,
    locals_not_used,
    undefined_function_calls
]}.

%% == Profiles ==

{profiles, [
    % Compiles an extra, parse-transformed downstream consumer module (check/)
    % so that dialyzer and xref examine the transform's output as it appears at a
    % real downstream site. Kept out of the default build and published package.
    {check, [
        {erl_opts, [
            {src_dirs, ["src", "check"]},
            {lager_extra_sinks, [audit]},
            % lager_transform calls fake_lager_pr at transform time, so both must
            % be compiled before the consumer (the first in-build user of the
            % transform). rebar3 already forces the parse-transform module early,
            % but not its runtime callee fake_lager_pr - hence listing it here.
            {erl_first_files, ["src/fake_lager_pr.erl", "src/lager_transform.erl"]}
        ]}
    ]},

    {test, [
        {erl_opts, [
            debug_info,
            nowarn_export_all,
            nowarn_missing_spec,
            nowarnings_as_errors
        ]},
        {shell, [
            {apps, [lager]},
            {config, "test/config/sys.config"}
        ]},
        {cover_enabled, true},
        {cover_opts, [verbose]}
    ]},

    {docs, [
        {edoc_opts, [
            {preprocess, true},
            {doclet, edoc_doclet_chunks},
            {layout, edoc_layout_chunks},
            {dir, "_build/default/lib/lager/doc"}
        ]}
    ]}
]}.

%% == rebar3_hank ==

{hank, [
    {ignore, [
        {"include/lager.hrl", [
            single_use_hrl_attrs,
            unused_macros
        ]}
    ]}
]}.

%% == Docs ==

% Necessary for ExDoc.

{edoc_opts, [
    {preprocess, true},
    {doclet, edoc_doclet_chunks},
    {layout, edoc_layout_chunks},
    {dir, "_build/docs/lib/lager/doc"}
]}.
