chore(appup): make update_appup.escript output only differences for

external dependencies

Currently, the update_appup.escript outputs as an error the full appup
file for external dependencies, even if all the changes are already
contained in the depency.  Here, we make it only output the missing
actions to be inserted, to aid in seeing what are the differences.
This commit is contained in:
Thales Macedo Garitezi 2021-11-25 15:02:18 -03:00
parent 18a9c0e177
commit 0932920d36
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
1 changed files with 69 additions and 8 deletions

View File

@ -99,8 +99,31 @@ main(Options, Baseline) ->
[] -> [] ->
ok; ok;
_ -> _ ->
set_invalid(), Diffs =
log("ERROR: The appup files are incomplete. Missing changes:~n ~p", [AppupChanges]) lists:filtermap(
fun({App, {Upgrade, Downgrade, OldUpgrade, OldDowngrade}}) ->
DiffUp = diff_appup_instructions(Upgrade, OldUpgrade),
DiffDown = diff_appup_instructions(Downgrade, OldDowngrade),
case {DiffUp, DiffDown} of
{[], []} ->
%% no diff for external dependency
false;
_ ->
Diffs = #{ up => DiffUp
, down => DiffDown
},
{true, {App, Diffs}}
end
end,
AppupChanges),
case Diffs =:= [] of
true ->
ok;
false ->
set_invalid(),
log("ERROR: The appup files are incomplete. Missing changes:~n ~p",
[Diffs])
end
end; end;
false -> false ->
update_appups(AppupChanges) update_appups(AppupChanges)
@ -189,9 +212,35 @@ find_appup_actions(App, CurrAppIdx, PrevAppIdx = #app{version = PrevVersion}) ->
%% The appup file has been already updated: %% The appup file has been already updated:
[]; [];
true -> true ->
[{App, {Upgrade, Downgrade}}] [{App, {Upgrade, Downgrade, OldUpgrade, OldDowngrade}}]
end. end.
%% For external dependencies, show only the changes that are missing
%% in their current appup.
diff_appup_instructions(ComputedChanges, PresentChanges) ->
lists:foldr(
fun({Vsn, ComputedActions}, Acc) ->
case find_matching_version(Vsn, PresentChanges) of
undefined ->
[{Vsn, ComputedActions} | Acc];
PresentActions ->
DiffActions = ComputedActions -- PresentActions,
case DiffActions of
[] ->
%% no diff
Acc;
_ ->
[{Vsn, DiffActions} | Acc]
end
end
end,
[],
ComputedChanges).
%% TODO: handle regexes
find_matching_version(Vsn, PresentChanges) ->
proplists:get_value(Vsn, PresentChanges).
find_old_appup_actions(App, PrevVersion) -> find_old_appup_actions(App, PrevVersion) ->
{Upgrade0, Downgrade0} = {Upgrade0, Downgrade0} =
case locate(ebin_current, App, ".appup") of case locate(ebin_current, App, ".appup") of
@ -270,12 +319,12 @@ check_appup_files() ->
update_appups(Changes) -> update_appups(Changes) ->
lists:foreach( lists:foreach(
fun({App, {Upgrade, Downgrade}}) -> fun({App, {Upgrade, Downgrade, OldUpgrade, OldDowngrade}}) ->
do_update_appup(App, Upgrade, Downgrade) do_update_appup(App, Upgrade, Downgrade, OldUpgrade, OldDowngrade)
end, end,
Changes). Changes).
do_update_appup(App, Upgrade, Downgrade) -> do_update_appup(App, Upgrade, Downgrade, OldUpgrade, OldDowngrade) ->
case locate(src, App, ".appup.src") of case locate(src, App, ".appup.src") of
{ok, AppupFile} -> {ok, AppupFile} ->
render_appfile(AppupFile, Upgrade, Downgrade); render_appfile(AppupFile, Upgrade, Downgrade);
@ -284,8 +333,20 @@ do_update_appup(App, Upgrade, Downgrade) ->
{ok, AppupFile} -> {ok, AppupFile} ->
render_appfile(AppupFile, Upgrade, Downgrade); render_appfile(AppupFile, Upgrade, Downgrade);
false -> false ->
set_invalid(), DiffUp = diff_appup_instructions(Upgrade, OldUpgrade),
log("ERROR: Appup file for the external dependency '~p' is not complete.~n Missing changes: ~p~n", [App, Upgrade]) DiffDown = diff_appup_instructions(Downgrade, OldDowngrade),
case {DiffUp, DiffDown} of
{[], []} ->
%% no diff for external dependency; ignore
ok;
_ ->
set_invalid(),
Diffs = #{ up => DiffUp
, down => DiffDown
},
log("ERROR: Appup file for the external dependency '~p' is not complete.~n Missing changes: ~100p~n", [App, Diffs]),
log("NOTE: Some changes above might be already covered by regexes.~n")
end
end end
end. end.