diff --git a/mix.exs b/mix.exs index d349dc370..3f3845cf7 100644 --- a/mix.exs +++ b/mix.exs @@ -80,6 +80,20 @@ defmodule Ejabberd.MixProject do end end + defp if_type_exported(module, typeDef, okResult) do + try do + {:ok, concrete} = :dialyzer_utils.get_core_from_beam(:code.which(module)) + {:ok, types} = :dialyzer_utils.get_record_and_type_info(concrete) + if Maps.has_key(types, typeDef) do + okResult + else + [] + end + rescue + _ -> [] + end + end + defp erlc_options do # Use our own includes + includes from all dependencies includes = ["include", deps_include()] @@ -97,7 +111,8 @@ defmodule Ejabberd.MixProject do if_version_below(~c"24", [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++ if_version_below(~c"24", [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}]) ++ if_version_below(~c"24", [{:d, :OTP_BELOW_24}]) ++ - if_version_below(~c"25", [{:d, :OTP_BELOW_25}]) + if_version_below(~c"25", [{:d, :OTP_BELOW_25}]) ++ + if_type_exported(:odbc, {:opaque, :connection_reference, 0}, [{:d, :ODBC_HAS_TYPES}]) defines = for {:d, value} <- result, do: {:d, value} result ++ [{:d, :ALL_DEFS, defines}] end diff --git a/rebar.config b/rebar.config index b29da967d..bdf6c6088 100644 --- a/rebar.config +++ b/rebar.config @@ -152,6 +152,7 @@ {if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATEWAY_WORKAROUND'}}, {if_var_true, sip, {d, 'SIP'}}, {if_var_true, stun, {d, 'STUN'}}, + {if_type_exported, {odbc, {opaque, connection_reference, 0}}, {d, 'ODBC_HAS_TYPES'}}, {src_dirs, [src, {if_rebar3, sql}, {if_var_true, tools, tools}]}]}. diff --git a/rebar.config.script b/rebar.config.script index bc1e060db..7d7fa864c 100644 --- a/rebar.config.script +++ b/rebar.config.script @@ -151,6 +151,30 @@ ProcessVars = fun F([], Acc) -> false -> F(Tail, Acc) end; + F([{Type, {Mod, TypeDef}, Value} | Tail], Acc) when + Type == if_type_exported orelse + Type == if_type_not_exported -> + try + {ok, Concrete} = dialyzer_utils:get_core_from_beam(code:which(Mod)), + {ok, Types} = dialyzer_utils:get_record_and_type_info(Concrete), + maps:get(TypeDef, Types, undefined) + of + undefined when Type == if_type_not_exported -> + F(Tail, ProcessSingleVar(F, Value, Acc)); + undefined -> + F(Tail, Acc); + _ when Type == if_type_exported -> + F(Tail, ProcessSingleVar(F, Value, Acc)); + _ -> + F(Tail, Acc) + catch _:_ -> + if + Type == if_type_not_exported -> + F(Tail, ProcessSingleVar(F, Value, Acc)); + true -> + F(Tail, Acc) + end + end; F([Other1 | Tail1], Acc) -> F(Tail1, [F(Other1, []) | Acc]); F(Val, Acc) when is_tuple(Val) -> diff --git a/src/ejabberd_sql.erl b/src/ejabberd_sql.erl index 58580c182..5e5549c45 100644 --- a/src/ejabberd_sql.erl +++ b/src/ejabberd_sql.erl @@ -67,12 +67,8 @@ -export([connecting/2, connecting/3, session_established/2, session_established/3]). --ifdef(OTP_RELEASE). - -if(?OTP_RELEASE >= 27). - -type(odbc_connection_reference() :: odbc:connection_reference()). - -else. - -type(odbc_connection_reference() :: pid()). - -endif. +-ifdef(ODBC_HAS_TYPES). + -type(odbc_connection_reference() :: odbc:connection_reference()). -else. -type(odbc_connection_reference() :: pid()). -endif.