build: refactor rebar.config.erl and mix.exs

Since windows is out:
- bcrypt is no longer a dynamic dependency
- we can remove the windows releated parts
This commit is contained in:
Zaiming (Stone) Shi 2023-12-15 10:48:33 +01:00
parent cf33b3b4b1
commit 8018497d75
3 changed files with 47 additions and 96 deletions

56
mix.exs
View File

@ -98,11 +98,12 @@ defmodule EMQXUmbrella.MixProject do
# set by hackney (dependency) # set by hackney (dependency)
{:ssl_verify_fun, "1.1.7", override: true}, {:ssl_verify_fun, "1.1.7", override: true},
{:rfc3339, github: "emqx/rfc3339", tag: "0.2.3", override: true}, {:rfc3339, github: "emqx/rfc3339", tag: "0.2.3", override: true},
{:bcrypt, github: "emqx/erlang-bcrypt", tag: "0.6.1", override: true},
{:uuid, github: "okeuday/uuid", tag: "v2.0.6", override: true}, {:uuid, github: "okeuday/uuid", tag: "v2.0.6", override: true},
{:quickrand, github: "okeuday/quickrand", tag: "v2.0.6", override: true} {:quickrand, github: "okeuday/quickrand", tag: "v2.0.6", override: true}
] ++ ] ++
emqx_apps(profile_info, version) ++ emqx_apps(profile_info, version) ++
enterprise_deps(profile_info) ++ bcrypt_dep() ++ jq_dep() ++ quicer_dep() enterprise_deps(profile_info) ++ jq_dep() ++ quicer_dep()
end end
defp emqx_apps(profile_info, version) do defp emqx_apps(profile_info, version) do
@ -374,10 +375,8 @@ defmodule EMQXUmbrella.MixProject do
%{ %{
mnesia_rocksdb: enable_rocksdb?(), mnesia_rocksdb: enable_rocksdb?(),
quicer: enable_quicer?(), quicer: enable_quicer?(),
bcrypt: enable_bcrypt?(),
jq: enable_jq?(), jq: enable_jq?(),
observer: is_app?(:observer), observer: is_app?(:observer)
os_mon: enable_os_mon?()
} }
|> Enum.reject(&elem(&1, 1)) |> Enum.reject(&elem(&1, 1))
|> Enum.map(&elem(&1, 0)) |> Enum.map(&elem(&1, 0))
@ -786,12 +785,6 @@ defmodule EMQXUmbrella.MixProject do
defp emqx_schema_mod(:enterprise), do: :emqx_enterprise_schema defp emqx_schema_mod(:enterprise), do: :emqx_enterprise_schema
defp emqx_schema_mod(:community), do: :emqx_conf_schema defp emqx_schema_mod(:community), do: :emqx_conf_schema
defp bcrypt_dep() do
if enable_bcrypt?(),
do: [{:bcrypt, github: "emqx/erlang-bcrypt", tag: "0.6.1", override: true}],
else: []
end
defp jq_dep() do defp jq_dep() do
if enable_jq?(), if enable_jq?(),
do: [{:jq, github: "emqx/jq", tag: "v0.3.12", override: true}], do: [{:jq, github: "emqx/jq", tag: "v0.3.12", override: true}],
@ -805,35 +798,25 @@ defmodule EMQXUmbrella.MixProject do
else: [] else: []
end end
defp enable_bcrypt?() do
not win32?()
end
defp enable_os_mon?() do
not win32?()
end
defp enable_jq?() do defp enable_jq?() do
not Enum.any?([ not Enum.any?([
build_without_jq?(), build_without_jq?()
win32?() ])
]) or "1" == System.get_env("BUILD_WITH_JQ")
end end
defp enable_quicer?() do defp enable_quicer?() do
not Enum.any?([ "1" == System.get_env("BUILD_WITH_QUIC") or
build_without_quic?(), not Enum.any?([
win32?(), macos?(),
centos6?(), build_without_quic?()
macos?() ])
]) or "1" == System.get_env("BUILD_WITH_QUIC")
end end
defp enable_rocksdb?() do defp enable_rocksdb?() do
not Enum.any?([ not Enum.any?([
build_without_rocksdb?(), raspbian?(),
raspbian?() build_without_rocksdb?()
]) or "1" == System.get_env("BUILD_WITH_ROCKSDB") ])
end end
defp pkg_vsn() do defp pkg_vsn() do
@ -848,19 +831,6 @@ defmodule EMQXUmbrella.MixProject do
String.trim(str) String.trim(str)
end end
defp win32?(),
do: match?({:win_32, _}, :os.type())
defp centos6?() do
case File.read("/etc/centos-release") do
{:ok, "CentOS release 6" <> _} ->
true
_ ->
false
end
end
defp macos?() do defp macos?() do
{:unix, :darwin} == :os.type() {:unix, :darwin} == :os.type()
end end

View File

@ -97,6 +97,7 @@
, {uuid, {git, "https://github.com/okeuday/uuid.git", {tag, "v2.0.6"}}} , {uuid, {git, "https://github.com/okeuday/uuid.git", {tag, "v2.0.6"}}}
, {ssl_verify_fun, "1.1.7"} , {ssl_verify_fun, "1.1.7"}
, {rfc3339, {git, "https://github.com/emqx/rfc3339.git", {tag, "0.2.3"}}} , {rfc3339, {git, "https://github.com/emqx/rfc3339.git", {tag, "0.2.3"}}}
, {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {tag, "0.6.1"}}}
]}. ]}.
{xref_ignores, {xref_ignores,

View File

@ -35,9 +35,6 @@ assert_otp() ->
ok ok
end. end.
bcrypt() ->
{bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {tag, "0.6.1"}}}.
quicer() -> quicer() ->
{quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.308"}}}. {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.308"}}}.
@ -47,8 +44,7 @@ jq() ->
deps(Config) -> deps(Config) ->
{deps, OldDeps} = lists:keyfind(deps, 1, Config), {deps, OldDeps} = lists:keyfind(deps, 1, Config),
MoreDeps = MoreDeps =
[bcrypt() || provide_bcrypt_dep()] ++ [jq() || is_jq_supported()] ++
[jq() || is_jq_supported()] ++
[quicer() || is_quicer_supported()], [quicer() || is_quicer_supported()],
lists:keystore(deps, 1, Config, {deps, OldDeps ++ MoreDeps}). lists:keystore(deps, 1, Config, {deps, OldDeps ++ MoreDeps}).
@ -121,45 +117,41 @@ is_community_umbrella_app("apps/emqx_gateway_jt808") -> false;
is_community_umbrella_app("apps/emqx_bridge_syskeeper") -> false; is_community_umbrella_app("apps/emqx_bridge_syskeeper") -> false;
is_community_umbrella_app(_) -> true. is_community_umbrella_app(_) -> true.
%% BUILD_WITHOUT_JQ
%% BUILD_WITHOUT_QUIC
%% BUILD_WITHOUT_ROCKSDB
is_build_without(Name) ->
"1" =:= os:getenv("BUILD_WITHOUT_" ++ Name).
%% BUILD_WITH_QUIC
is_build_with(Name) ->
"1" =:= os:getenv("BUILD_WITH_" ++ Name).
is_jq_supported() -> is_jq_supported() ->
not (false =/= os:getenv("BUILD_WITHOUT_JQ") orelse not is_build_without("JQ").
is_win32()) orelse
"1" == os:getenv("BUILD_WITH_JQ").
is_quicer_supported() -> is_quicer_supported() ->
not (false =/= os:getenv("BUILD_WITHOUT_QUIC") orelse %% for ones who want to build QUIC on macos
is_macos() orelse %% export BUILD_WITH_QUIC=1
is_win32() orelse is_centos_6()) orelse is_build_with("QUIC") orelse
"1" == os:getenv("BUILD_WITH_QUIC"). is_quicer_supported(os:type()).
is_quicer_supported({unix, darwin}) ->
%% no quic on macos so far
false;
is_quicer_supported(_) ->
not is_build_without("QUIC").
is_rocksdb_supported() -> is_rocksdb_supported() ->
not (false =/= os:getenv("BUILD_WITHOUT_ROCKSDB") orelse %% there is no way one can build rocksdb on raspbian
is_raspbian()) orelse %% so no need to check is_build_with
"1" == os:getenv("BUILD_WITH_ROCKSDB"). Distro = os_cmd("./scripts/get-distro.sh"),
is_rocksdb_supported(Distro).
is_macos() -> is_rocksdb_supported("respbian" ++ _) ->
{unix, darwin} =:= os:type(). false;
is_rocksdb_supported(_) ->
is_centos_6() -> not is_build_without("ROCKSDB").
%% reason:
%% glibc is too old
case file:read_file("/etc/centos-release") of
{ok, <<"CentOS release 6", _/binary>>} ->
true;
_ ->
false
end.
is_raspbian() ->
case os_cmd("./scripts/get-distro.sh") of
"raspbian" ++ _ ->
true;
_ ->
false
end.
is_win32() ->
win32 =:= element(1, os:type()).
project_app_dirs() -> project_app_dirs() ->
project_app_dirs(get_edition_from_profile_env()). project_app_dirs(get_edition_from_profile_env()).
@ -421,14 +413,12 @@ relx_apps(ReleaseType, Edition) ->
[{App, load} || App <- BusinessApps]), [{App, load} || App <- BusinessApps]),
lists:foldl(fun proplists:delete/2, Apps, excluded_apps(ReleaseType)). lists:foldl(fun proplists:delete/2, Apps, excluded_apps(ReleaseType)).
excluded_apps(ReleaseType) -> excluded_apps(_ReleaseType) ->
OptionalApps = [ OptionalApps = [
{quicer, is_quicer_supported()}, {quicer, is_quicer_supported()},
{bcrypt, provide_bcrypt_release(ReleaseType)},
{jq, is_jq_supported()}, {jq, is_jq_supported()},
{observer, is_app(observer)}, {observer, is_app(observer)},
{mnesia_rocksdb, is_rocksdb_supported()}, {mnesia_rocksdb, is_rocksdb_supported()}
{os_mon, provide_os_mon_release()}
], ],
[App || {App, false} <- OptionalApps]. [App || {App, false} <- OptionalApps].
@ -531,15 +521,6 @@ is_debug(VarName) ->
_ -> true _ -> true
end. end.
provide_bcrypt_dep() ->
not is_win32().
provide_os_mon_release() ->
not is_win32().
provide_bcrypt_release(ReleaseType) ->
provide_bcrypt_dep() andalso ReleaseType =:= cloud.
erl_opts_i() -> erl_opts_i() ->
[{i, "apps"}] ++ [{i, "apps"}] ++
[{i, Dir} || Dir <- filelib:wildcard(filename:join(["apps", "*", "include"]))]. [{i, Dir} || Dir <- filelib:wildcard(filename:join(["apps", "*", "include"]))].
@ -562,8 +543,7 @@ dialyzer(Config) ->
AppsToExclude = AppNames -- KnownApps, AppsToExclude = AppNames -- KnownApps,
Extra = Extra =
[os_mon, system_monitor, tools, covertool] ++ [system_monitor, tools, covertool] ++
[bcrypt || provide_bcrypt_dep()] ++
[jq || is_jq_supported()] ++ [jq || is_jq_supported()] ++
[quicer || is_quicer_supported()], [quicer || is_quicer_supported()],
NewDialyzerConfig = NewDialyzerConfig =