From 3655ea050c167e5daeff15c58e9d0520b3cc1882 Mon Sep 17 00:00:00 2001 From: William Yang Date: Thu, 21 Jul 2022 10:14:51 +0200 Subject: [PATCH] build(relup): overwrite OTP vers of upgrade bases --- build | 8 +++ scripts/emqx_rel_otp_app_overwrite.escript | 57 ++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100755 scripts/emqx_rel_otp_app_overwrite.escript diff --git a/build b/build index 44287bff5..b028aae75 100755 --- a/build +++ b/build @@ -94,6 +94,14 @@ make_relup() { fi RELX_BASE_VERSIONS="$(IFS=, ; echo "${releases[*]}")" export RELX_BASE_VERSIONS + if [[ ${PKG_VSN} == 4.3* ]]; then + echo "EMQX 4.3 specific, overwrite OTP app versions" + local emqx_rel_file="${releases_dir}/${PKG_VSN}/emqx.rel" + 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}" + 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 new file mode 100755 index 000000000..843628e24 --- /dev/null +++ b/scripts/emqx_rel_otp_app_overwrite.escript @@ -0,0 +1,57 @@ +#!/usr/bin/env escript +%% 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. +%% +%% It simply read OTP app version (incl. ERTS) from the rel file of *NEW* Release ($RelVsn) and write back to the ones +%% in *OLD* versions ($BASE_VERSIONS) +%% +%% 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), + lists:foreach(fun(BaseVer) -> + base_rel_overwrites(BaseVer, Profile, 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}. + +base_rel_overwrites(RelVsn, Profile, Dir, ErtsVsn, Overwrites) -> + RelFile = rel_file(Profile, Dir, RelVsn), + file:copy(RelFile, RelFile++".bak"), + {ok, [{release, {"emqx", RelVsn}, {erts, _BaseErtsVsn}, BaseAppList}]} = file:consult(RelFile), + NewData = [ {release, {"emqx", RelVsn}, {erts, ErtsVsn}, + lists:map(fun(X) -> + Name = element(1, X), + case lists:keyfind(Name, 1, Overwrites) of + false -> X; + Y when is_tuple(Y) -> Y + end + end, BaseAppList) + } + ], + ok = file:write_file(RelFile, io_lib:format("~p.", NewData)). + +rel_file(Profile, Dir, RelVsn)-> + filename:join([Dir, RelVsn, Profile++".rel"]). + + +%% Couldn't find a good way to get this list dynamicly. +otp_apps() -> + [ kernel + , stdlib + , sasl + , crypto + , public_key + , asn1 + , syntax_tools + , ssl + , os_mon + , inets + , compiler + , runtime_tools + , mnesia + , xmerl + ].