chore(mix): fix mix builds

This commit is contained in:
Ilya Averyanov 2023-03-19 01:16:49 +02:00
parent d5ea435e86
commit 39f22585d0
5 changed files with 85 additions and 41 deletions

View File

@ -152,6 +152,7 @@ $(PROFILES:%=clean-%):
.PHONY: clean-all
clean-all:
@rm -f rebar.lock
@rm -rf deps
@rm -rf _build
.PHONY: deps-all

View File

@ -59,4 +59,12 @@
{statistics, true}
]}.
{project_plugins, [erlfmt]}.
{project_plugins, [
{erlfmt, [
{files, [
"{src,include,test}/*.{hrl,erl,app.src}",
"rebar.config",
"rebar.config.script"
]}
]}
]}.

View File

@ -27,17 +27,17 @@ Bcrypt = {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {tag, "0.6.
Quicer = {quicer, {git, "https://github.com/emqx/quic.git", {tag, "0.0.113"}}}.
Dialyzer = fun(Config) ->
{dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config),
{plt_extra_apps, OldExtra} = lists:keyfind(plt_extra_apps, 1, OldDialyzerConfig),
Extra = OldExtra ++ [quicer || IsQuicSupp()],
NewDialyzerConfig = [{plt_extra_apps, Extra} | OldDialyzerConfig],
lists:keystore(
dialyzer,
1,
Config,
{dialyzer, NewDialyzerConfig}
)
end.
{dialyzer, OldDialyzerConfig} = lists:keyfind(dialyzer, 1, Config),
{plt_extra_apps, OldExtra} = lists:keyfind(plt_extra_apps, 1, OldDialyzerConfig),
Extra = OldExtra ++ [quicer || IsQuicSupp()],
NewDialyzerConfig = [{plt_extra_apps, Extra} | OldDialyzerConfig],
lists:keystore(
dialyzer,
1,
Config,
{dialyzer, NewDialyzerConfig}
)
end.
ExtraDeps = fun(C) ->
{deps, Deps0} = lists:keyfind(deps, 1, C),

25
build
View File

@ -147,7 +147,7 @@ make_rel() {
make_elixir_rel() {
./scripts/pre-compile.sh "$PROFILE"
export_release_vars "$PROFILE"
export_elixir_release_vars "$PROFILE"
# for some reason, this has to be run outside "do"...
mix local.rebar --if-missing --force
# shellcheck disable=SC1010
@ -362,7 +362,7 @@ function join {
# used to control the Elixir Mix Release output
# see docstring in `mix.exs`
export_release_vars() {
export_elixir_release_vars() {
local profile="$1"
case "$profile" in
emqx|emqx-enterprise)
@ -376,27 +376,6 @@ export_release_vars() {
exit 1
esac
export MIX_ENV="$profile"
local erl_opts=()
case "$(is_enterprise "$profile")" in
'yes')
erl_opts+=( "{d, 'EMQX_RELEASE_EDITION', ee}" )
;;
'no')
erl_opts+=( "{d, 'EMQX_RELEASE_EDITION', ce}" )
;;
esac
# At this time, Mix provides no easy way to pass `erl_opts' to
# dependencies. The workaround is to set this variable before
# compiling the project, so that `emqx_release.erl' picks up
# `emqx_vsn' as if it was compiled by rebar3.
erl_opts+=( "{compile_info,[{emqx_vsn,\"${PKG_VSN}\"}]}" )
erl_opts+=( "{d,snk_kind,msg}" )
ERL_COMPILER_OPTIONS="[$(join , "${erl_opts[@]}")]"
export ERL_COMPILER_OPTIONS
}
log "building artifact=$ARTIFACT for profile=$PROFILE"

68
mix.exs
View File

@ -31,16 +31,17 @@ defmodule EMQXUmbrella.MixProject do
def project() do
profile_info = check_profile!()
version = pkg_vsn()
[
app: :emqx_mix,
version: pkg_vsn(),
deps: deps(profile_info),
version: version,
deps: deps(profile_info, version),
releases: releases()
]
end
defp deps(profile_info) do
defp deps(profile_info, version) do
# we need several overrides here because dependencies specify
# other exact versions, and not ranges.
[
@ -61,7 +62,9 @@ defmodule EMQXUmbrella.MixProject do
{:ecpool, github: "emqx/ecpool", tag: "0.5.3", override: true},
{:replayq, github: "emqx/replayq", tag: "0.3.7", override: true},
{:pbkdf2, github: "emqx/erlang-pbkdf2", tag: "2.0.4", override: true},
{:emqtt, github: "emqx/emqtt", tag: "1.8.5", override: true},
# maybe forbid to fetch quicer
{:emqtt,
github: "emqx/emqtt", tag: "1.8.5", override: true, system_env: maybe_no_quic_env()},
{:rulesql, github: "emqx/rulesql", tag: "0.1.4"},
{:observer_cli, "1.7.1"},
{:system_monitor, github: "ieQu1/system_monitor", tag: "3.0.3"},
@ -92,11 +95,15 @@ defmodule EMQXUmbrella.MixProject do
{:gpb, "4.19.5", override: true, runtime: false},
{:hackney, github: "benoitc/hackney", tag: "1.18.1", override: true}
] ++
umbrella_apps() ++
enterprise_apps(profile_info) ++
emqx_apps(profile_info, version) ++
enterprise_deps(profile_info) ++ bcrypt_dep() ++ jq_dep() ++ quicer_dep()
end
defp emqx_apps(profile_info, version) do
apps = umbrella_apps() ++ enterprise_apps(profile_info)
set_emqx_app_system_env(apps, profile_info, version)
end
defp umbrella_apps() do
"apps/*"
|> Path.wildcard()
@ -145,6 +152,46 @@ defmodule EMQXUmbrella.MixProject do
[]
end
defp set_emqx_app_system_env(apps, profile_info, version) do
system_env = emqx_app_system_env(profile_info, version) ++ maybe_no_quic_env()
Enum.map(
apps,
fn {app, opts} ->
{app,
Keyword.update(
opts,
:system_env,
system_env,
&Keyword.merge(&1, system_env)
)}
end
)
end
def emqx_app_system_env(profile_info, version) do
erlc_options(profile_info, version)
|> dump_as_erl()
|> then(&[{"ERL_COMPILER_OPTIONS", &1}])
end
defp erlc_options(%{edition_type: edition_type}, version) do
[
:debug_info,
{:compile_info, [{:emqx_vsn, String.to_charlist(version)}]},
{:d, :EMQX_RELEASE_EDITION, erlang_edition(edition_type)},
{:d, :snk_kind, :msg}
]
end
def maybe_no_quic_env() do
if not enable_quicer?() do
[{"BUILD_WITHOUT_QUIC", "true"}]
else
[]
end
end
defp releases() do
[
emqx: fn ->
@ -804,4 +851,13 @@ defmodule EMQXUmbrella.MixProject do
|> List.first()
end
end
defp dump_as_erl(term) do
term
|> then(&:io_lib.format("~0p", [&1]))
|> :erlang.iolist_to_binary()
end
defp erlang_edition(:community), do: :ce
defp erlang_edition(:enterprise), do: :ee
end