25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Determine compile definitions based on Erlang version

This gives a clear definition of what erlang versions require each
workaround, instead of depending on the actual workaround details.
The lib module was removed in OTP 21.0,
and the formatting options were moved to erl_error.
The uri_string module was introduced in OTP 21.0.
This commit is contained in:
Badlop 2022-02-24 21:34:40 +01:00
parent 7381b9db85
commit f721374321
2 changed files with 5 additions and 14 deletions

15
mix.exs
View File

@ -50,15 +50,6 @@ defmodule Ejabberd.MixProject do
++ cond_apps()] ++ cond_apps()]
end end
defp if_function_exported(mod, fun, arity, okResult) do
:code.ensure_loaded(mod)
if :erlang.function_exported(mod, fun, arity) do
okResult
else
[]
end
end
defp if_version_above(ver, okResult) do defp if_version_above(ver, okResult) do
if :erlang.system_info(:otp_release) > ver do if :erlang.system_info(:otp_release) > ver do
okResult okResult
@ -82,15 +73,15 @@ defmodule Ejabberd.MixProject do
cond_options() ++ cond_options() ++
Enum.map(includes, fn (path) -> {:i, path} end) ++ Enum.map(includes, fn (path) -> {:i, path} end) ++
if_version_above('20', [{:d, :DEPRECATED_GET_STACKTRACE}]) ++ if_version_above('20', [{:d, :DEPRECATED_GET_STACKTRACE}]) ++
if_version_above('20', [{:d, :HAVE_URI_STRING}]) ++
if_version_above('20', [{:d, :HAVE_ERL_ERROR}]) ++
if_version_below('21', [{:d, :USE_OLD_HTTP_URI}]) ++ if_version_below('21', [{:d, :USE_OLD_HTTP_URI}]) ++
if_version_below('22', [{:d, :LAGER}]) ++ if_version_below('22', [{:d, :LAGER}]) ++
if_version_below('21', [{:d, :NO_CUSTOMIZE_HOSTNAME_CHECK}]) ++ if_version_below('21', [{:d, :NO_CUSTOMIZE_HOSTNAME_CHECK}]) ++
if_version_below('23', [{:d, :USE_OLD_CRYPTO_HMAC}]) ++ if_version_below('23', [{:d, :USE_OLD_CRYPTO_HMAC}]) ++
if_version_below('23', [{:d, :USE_OLD_PG2}]) ++ if_version_below('23', [{:d, :USE_OLD_PG2}]) ++
if_version_below('24', [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++ if_version_below('24', [{:d, :COMPILER_REPORTS_ONLY_LINES}]) ++
if_version_below('24', [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}]) ++ if_version_below('24', [{:d, :SYSTOOLS_APP_DEF_WITHOUT_OPTIONAL}])
if_function_exported(:uri_string, :normalize, 1, [{:d, :HAVE_URI_STRING}]) ++
if_function_exported(:erl_error, :format_exception, 6, [{:d, :HAVE_ERL_ERROR}])
defines = for {:d, value} <- result, do: {:d, value} defines = for {:d, value} <- result, do: {:d, value}
result ++ [{:d, :ALL_DEFS, defines}] result ++ [{:d, :ALL_DEFS, defines}]
end end

View File

@ -107,6 +107,8 @@
{erl_opts, [nowarn_deprecated_function, {erl_opts, [nowarn_deprecated_function,
{i, "include"}, {i, "include"},
{if_version_above, "20", {d, 'DEPRECATED_GET_STACKTRACE'}}, {if_version_above, "20", {d, 'DEPRECATED_GET_STACKTRACE'}},
{if_version_above, "20", {d, 'HAVE_ERL_ERROR'}},
{if_version_above, "20", {d, 'HAVE_URI_STRING'}},
{if_version_below, "21", {d, 'USE_OLD_HTTP_URI'}}, {if_version_below, "21", {d, 'USE_OLD_HTTP_URI'}},
{if_version_below, "22", {d, 'LAGER'}}, {if_version_below, "22", {d, 'LAGER'}},
{if_version_below, "21", {d, 'NO_CUSTOMIZE_HOSTNAME_CHECK'}}, {if_version_below, "21", {d, 'NO_CUSTOMIZE_HOSTNAME_CHECK'}},
@ -121,8 +123,6 @@
{if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATEWAY_WORKAROUND'}}, {if_var_true, roster_gateway_workaround, {d, 'ROSTER_GATEWAY_WORKAROUND'}},
{if_var_true, sip, {d, 'SIP'}}, {if_var_true, sip, {d, 'SIP'}},
{if_var_true, stun, {d, 'STUN'}}, {if_var_true, stun, {d, 'STUN'}},
{if_have_fun, {erl_error, format_exception, 6}, {d, 'HAVE_ERL_ERROR'}},
{if_have_fun, {uri_string, normalize, 1}, {d, 'HAVE_URI_STRING'}},
{src_dirs, [src, {src_dirs, [src,
{if_rebar3, sql}, {if_rebar3, sql},
{if_var_true, tools, tools}, {if_var_true, tools, tools},