From e74a97013eb068dd1513769d9103b4da7625b1e6 Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 3 Aug 2022 10:01:20 +0200 Subject: [PATCH 1/2] build: fix relup app overwrite escript the rel file name is always emqx.rel, has nothing to do with profile --- build | 2 +- scripts/emqx_rel_otp_app_overwrite.escript | 27 ++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/build b/build index 2f773d295..ace072b79 100755 --- a/build +++ b/build @@ -100,7 +100,7 @@ make_relup() { if [ ! -f "${emqx_rel_file}" ]; then ./rebar3 as "${PROFILE}" release fi - scripts/emqx_rel_otp_app_overwrite.escript "${releases_dir}" "${PROFILE}" "${PKG_VSN}" "${RELX_BASE_VERSIONS}" + scripts/emqx_rel_otp_app_overwrite.escript "${releases_dir}" "${PKG_VSN}" "${RELX_BASE_VERSIONS}" fi ./rebar3 as "$PROFILE" relup --relname emqx --relvsn "${PKG_VSN}" diff --git a/scripts/emqx_rel_otp_app_overwrite.escript b/scripts/emqx_rel_otp_app_overwrite.escript index 5eace01ff..85ccca33c 100755 --- a/scripts/emqx_rel_otp_app_overwrite.escript +++ b/scripts/emqx_rel_otp_app_overwrite.escript @@ -7,19 +7,24 @@ %% %% note, we use NEW to overwrite OLD is because the modified NEW rel file will be overwritten by next 'rebar relup' %% -main([Dir, Profile, RelVsn, BASE_VERSIONS]) -> - {ErtsVsn, Overwrites} = get_otp_apps(rel_file(Profile, Dir, RelVsn), RelVsn), +main([Dir, RelVsn, BASE_VERSIONS]) -> + {ErtsVsn, Overwrites} = get_otp_apps(rel_file(Dir, RelVsn), RelVsn), lists:foreach(fun(BaseVer) -> - base_rel_overwrites(BaseVer, Profile, Dir, ErtsVsn, Overwrites) + base_rel_overwrites(BaseVer, Dir, ErtsVsn, Overwrites) end, string:tokens(BASE_VERSIONS, ",")). get_otp_apps(RelFile, RelVsn) -> - {ok, [{release, {"emqx", RelVsn}, {erts, ErtsVsn}, AppList}]} = file:consult(RelFile), - Apps = lists:filter(fun(X) -> lists:member(element(1, X), otp_apps()) end, AppList), - {ErtsVsn, Apps}. + case file:consult(RelFile) of + {ok, [{release, {"emqx", RelVsn}, {erts, ErtsVsn}, AppList}]} -> + Apps = lists:filter(fun(X) -> lists:member(element(1, X), otp_apps()) end, AppList), + {ErtsVsn, Apps}; + {error, Reason} -> + io:format(standard_error, "failed_to_read_file ~p for release ~p~nreason=~p~n", [RelFile, RelVsn, Reason]), + halt(1) + end. -base_rel_overwrites(RelVsn, Profile, Dir, ErtsVsn, Overwrites) -> - RelFile = rel_file(Profile, Dir, RelVsn), +base_rel_overwrites(RelVsn, Dir, ErtsVsn, Overwrites) -> + RelFile = rel_file(Dir, RelVsn), file:copy(RelFile, RelFile++".bak"), {ok, [{release, {"emqx", RelVsn}, {erts, _BaseErtsVsn}, BaseAppList}]} = file:consult(RelFile), NewData = [ {release, {"emqx", RelVsn}, {erts, ErtsVsn}, @@ -34,10 +39,8 @@ base_rel_overwrites(RelVsn, Profile, Dir, ErtsVsn, Overwrites) -> ], ok = file:write_file(RelFile, io_lib:format("~p.", NewData)). -rel_file("emqx-edge", Dir, RelVsn)-> - rel_file("emqx", Dir, RelVsn); -rel_file(Profile, Dir, RelVsn)-> - filename:join([Dir, RelVsn, Profile++".rel"]). +rel_file(Dir, RelVsn)-> + filename:join([Dir, RelVsn, "emqx.rel"]). otp_apps() -> {ok, [Apps]} = file:consult("scripts/rel_otp_apps.eterm"), From ddd6f066e49f3b0cf6f291d3898d712b1f91911c Mon Sep 17 00:00:00 2001 From: "Zaiming (Stone) Shi" Date: Wed, 3 Aug 2022 10:41:45 +0200 Subject: [PATCH 2/2] chore: run escript in compile mode --- scripts/emqx_rel_otp_app_overwrite.escript | 3 ++- scripts/fail-on-old-otp-version.escript | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/emqx_rel_otp_app_overwrite.escript b/scripts/emqx_rel_otp_app_overwrite.escript index 85ccca33c..da1ad7ad6 100755 --- a/scripts/emqx_rel_otp_app_overwrite.escript +++ b/scripts/emqx_rel_otp_app_overwrite.escript @@ -1,4 +1,4 @@ -#!/usr/bin/env escript +#!/usr/bin/env -S escript -c %% This script is part of 'relup' process to overwrite the OTP app versions (incl. ERTS) in rel files from upgrade base %% so that 'rebar relup' call will not generate instructions for restarting OTP apps or restarting the emulator. %% @@ -7,6 +7,7 @@ %% %% note, we use NEW to overwrite OLD is because the modified NEW rel file will be overwritten by next 'rebar relup' %% + main([Dir, RelVsn, BASE_VERSIONS]) -> {ErtsVsn, Overwrites} = get_otp_apps(rel_file(Dir, RelVsn), RelVsn), lists:foreach(fun(BaseVer) -> diff --git a/scripts/fail-on-old-otp-version.escript b/scripts/fail-on-old-otp-version.escript index 0e4cd2a1b..8399028cb 100755 --- a/scripts/fail-on-old-otp-version.escript +++ b/scripts/fail-on-old-otp-version.escript @@ -1,4 +1,4 @@ -#!/usr/bin/env escript +#!/usr/bin/env -S escript -c main(_) -> OtpRelease = list_to_integer(erlang:system_info(otp_release)),