From 6fb5c9de424695b09a28d1020500f16c1355eee7 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Tue, 2 Mar 2021 18:10:26 +0100 Subject: [PATCH 1/4] chore(deps): upgrade replayq to version 0.3.2 --- rebar.config | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rebar.config b/rebar.config index 034c9225b..f1fe1d3b2 100644 --- a/rebar.config +++ b/rebar.config @@ -46,7 +46,7 @@ , {cuttlefish, {git, "https://github.com/emqx/cuttlefish", {tag, "v3.1.0"}}} , {minirest, {git, "https://github.com/emqx/minirest", {tag, "0.3.3"}}} , {ecpool, {git, "https://github.com/emqx/ecpool", {tag, "0.5.0"}}} - , {replayq, {git, "https://github.com/emqx/replayq", {tag, "0.3.1"}}} + , {replayq, {git, "https://github.com/emqx/replayq", {tag, "0.3.2"}}} , {pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.4"}}} , {emqtt, {git, "https://github.com/emqx/emqtt", {tag, "1.2.3"}}} , {rulesql, {git, "https://github.com/emqx/rulesql", {tag, "0.1.2"}}} From e3407b95565cd199c6f6d6bbe11cc6cdf8e6dd48 Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Tue, 2 Mar 2021 20:14:06 +0100 Subject: [PATCH 2/4] chore(build): fix rebar dependency and add a script to ensure integrity --- apps/emqx_sasl/rebar.config | 2 +- apps/emqx_telemetry/rebar.config | 15 +------ scripts/check-deps-integrity.escript | 63 ++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 15 deletions(-) create mode 100755 scripts/check-deps-integrity.escript diff --git a/apps/emqx_sasl/rebar.config b/apps/emqx_sasl/rebar.config index 40adb664a..318f82a0b 100644 --- a/apps/emqx_sasl/rebar.config +++ b/apps/emqx_sasl/rebar.config @@ -1,5 +1,5 @@ {deps, - [{pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.3"}}} + [{pbkdf2, {git, "https://github.com/emqx/erlang-pbkdf2.git", {branch, "2.0.4"}}} ]}. {edoc_opts, [{preprocess, true}]}. diff --git a/apps/emqx_telemetry/rebar.config b/apps/emqx_telemetry/rebar.config index 0e8d1ef9b..7b30a8fd8 100644 --- a/apps/emqx_telemetry/rebar.config +++ b/apps/emqx_telemetry/rebar.config @@ -1,14 +1 @@ -{edoc_opts, [{preprocess, true}]}. -{erl_opts, [warn_unused_vars, - warn_shadow_vars, - warn_unused_import, - warn_obsolete_guard, - debug_info, - {parse_transform}]}. - -{xref_checks, [undefined_function_calls, undefined_functions, - locals_not_used, deprecated_function_calls, - warnings_as_errors, deprecated_functions]}. -{cover_enabled, true}. -{cover_opts, [verbose]}. -{cover_export_enabled, true}. +{deps, []}. diff --git a/scripts/check-deps-integrity.escript b/scripts/check-deps-integrity.escript new file mode 100755 index 000000000..2dd16afb9 --- /dev/null +++ b/scripts/check-deps-integrity.escript @@ -0,0 +1,63 @@ +#!/usr/bin/env escript + +%% NOTE: this script should be executed at project root. + +-mode(compile). + +main([]) -> + AppsDir = case filelib:is_file("EMQX_ENTERPRISE") of + true -> "lib-ee"; + false -> "lib-ce" + end, + true = filelib:is_dir(AppsDir), + Files = ["rebar.config"] ++ + apps_rebar_config("apps") ++ + apps_rebar_config(AppsDir), + Deps = collect_deps(Files, #{}), + case count_bad_deps(Deps) of + 0 -> + io:format("OK~n"); + N -> + io:format(standard_error, "~p dependency discrepancies", [N]), + halt(1) + end. + +apps_rebar_config(Dir) -> + filelib:wildcard(filename:join([Dir, "*", "rebar.config"])). + +%% collect a kv-list of {DepName, [{DepReference, RebarConfigFile}]} +%% the value part should have unique DepReference +collect_deps([], Acc) -> maps:to_list(Acc); +collect_deps([File | Files], Acc) -> + Deps = + try + {ok, Config} = file:consult(File), + {deps, Deps0} = lists:keyfind(deps, 1, Config), + Deps0 + catch + C : E : St -> + erlang:raise(C, {E, {failed_to_find_deps_in_rebar_config, File}}, St) + end, + collect_deps(Files, do_collect_deps(Deps, File, Acc)). + +do_collect_deps([], _File, Acc) -> Acc; +do_collect_deps([{Name, Ref} | Deps], File, Acc) -> + Refs = maps:get(Name, Acc, []), + do_collect_deps(Deps, File, Acc#{Name => [{Ref, File} | Refs]}). + +count_bad_deps([]) -> 0; +count_bad_deps([{Name, Refs0} | Rest]) -> + Refs = lists:keysort(1, Refs0), + case is_unique_ref(Refs) of + true -> + count_bad_deps(Rest); + false -> + io:format(standard_error, "~p:~n~p~n", [Name, Refs]), + 1 + count_bad_deps(Rest) + end. + +is_unique_ref([_]) -> true; +is_unique_ref([{Ref, _File1}, {Ref, File2} | Rest]) -> + is_unique_ref([{Ref, File2} | Rest]); +is_unique_ref(_) -> + false. From c61080c8627e3b2fe3b7070af0a821b713817f2d Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Tue, 2 Mar 2021 20:37:45 +0100 Subject: [PATCH 3/4] chore(build): write rendered rebar.config only when debugging --- rebar.config.erl | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/rebar.config.erl b/rebar.config.erl index 1492114a1..1753e97ff 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -5,7 +5,7 @@ do(_Dir, CONFIG) -> C1 = deps(CONFIG), Config = dialyzer(C1), - dump(Config ++ [{overrides, overrides()}] ++ coveralls() ++ config()). + maybe_dump(Config ++ [{overrides, overrides()}] ++ coveralls() ++ config()). bcrypt() -> {bcrypt, {git, "https://github.com/emqx/erlang-bcrypt.git", {branch, "0.6.0"}}}. @@ -286,10 +286,19 @@ get_vsn() -> Vsn2 = re:replace(PkgVsn, "v", "", [{return ,list}]), re:replace(Vsn2, "\n", "", [{return ,list}]). -dump(Config) -> - file:write_file("rebar.config.rendered", [io_lib:format("~p.\n", [I]) || I <- Config]), +maybe_dump(Config) -> + is_debug() andalso file:write_file("rebar.config.rendered", [io_lib:format("~p.\n", [I]) || I <- Config]), Config. +is_debug() -> is_debug("DEBUG") orelse is_debug("DIAGNOSTIC"). + +is_debug(VarName) -> + case os:getenv(VarName) of + false -> false; + "" -> false; + _ -> true + end. + provide_bcrypt_dep() -> case os:type() of {win32, _} -> false; From b176300635d004d5ed382065c809a9d8abef934b Mon Sep 17 00:00:00 2001 From: Zaiming Shi Date: Tue, 2 Mar 2021 20:38:44 +0100 Subject: [PATCH 4/4] chore(ci): check rebar dependency integrity in CI --- .github/workflows/check_deps_integrity.yaml | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .github/workflows/check_deps_integrity.yaml diff --git a/.github/workflows/check_deps_integrity.yaml b/.github/workflows/check_deps_integrity.yaml new file mode 100644 index 000000000..eb0ff1fee --- /dev/null +++ b/.github/workflows/check_deps_integrity.yaml @@ -0,0 +1,13 @@ +name: Check Rebar Dependencies + +on: [pull_request] + +jobs: + check_deps_integrity: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v2 + - name: Run check-deps-integrity.escript + run: | + docker run --rm -v "$(pwd):/emqx" emqx/build-env:erl23.2.2-ubuntu20.04 sh -c 'cd /emqx && ./scripts/check-deps-integrity.escript' +