feat(update_appup): Create stubs

This commit is contained in:
k32 2021-10-01 18:35:17 +02:00
parent 4020db8fc1
commit aca6367561
1 changed files with 47 additions and 13 deletions

View File

@ -23,25 +23,47 @@ parse_args(["--check"|Rest], State) ->
parse_args(["--skip-build"|Rest], State) -> parse_args(["--skip-build"|Rest], State) ->
parse_args(Rest, State#{prepare => false}); parse_args(Rest, State#{prepare => false});
parse_args([], _) -> parse_args([], _) ->
fail("Usage:~n update_appup.escript [--check] [--skip-build] <current_release_tag> fail("A script that creates stubs for appup files
Usage:~n update_appup.escript [--check] [--skip-build] <current_release_tag>
--check Don't update the appup files, just check that they are complete --check Don't update the appup files, just check that they are complete
--skip-build Don't rebuild the releases. May produce wrong appup files. --skip-build Don't rebuild the releases. May produce wrong appup files.
"). ").
process_app(_, _, App, {[], [], []}) ->
%% No changes, just check the appup file if present:
case locate(App, ".appup.src") of
{ok, AppupFile} ->
_ = read_appup(AppupFile),
ok;
undefined ->
ok
end;
process_app(PredVersion, _Check, App, Changes) -> process_app(PredVersion, _Check, App, Changes) ->
AppupFiles = filelib:wildcard(lists:concat(["{src,apps,lib-*}/**/", App, ".appup.src"])), case locate(App, ".appup.src") of
case AppupFiles of {ok, AppupFile} ->
[AppupFile] ->
update_appup(PredVersion, AppupFile, Changes); update_appup(PredVersion, AppupFile, Changes);
[] -> undefined ->
io:format("~nWARNING: Please create an stub appup src file for ~p~n", [App]) case create_stub(App) of
false ->
%% External dependency, skip
ok;
AppupFile ->
update_appup(PredVersion, AppupFile, Changes)
end
end. end.
group_modules(L) -> create_stub(App) ->
lists:foldl(fun({App, Mod}, Acc) -> case locate(App, ".app.src") of
maps:update_with(App, fun(Tl) -> [Mod|Tl] end, [Mod], Acc) {ok, AppSrc} ->
end, #{}, L). AppupFile = filename:basename(AppSrc) ++ ".appup.src",
Default = {<<".*">>, []},
render_appfile(AppupFile, [Default], [Default]),
AppupFile;
undefined ->
false
end.
update_appup(_, File, {[], [], []}) -> update_appup(_, File, {[], [], []}) ->
%% No changes in the app. Just check syntax of the existing appup: %% No changes in the app. Just check syntax of the existing appup:
@ -51,12 +73,14 @@ update_appup(PredVersion, File, Changes) ->
{_, Upgrade0, Downgrade0} = read_appup(File), {_, Upgrade0, Downgrade0} = read_appup(File),
Upgrade = update_actions(PredVersion, Changes, Upgrade0), Upgrade = update_actions(PredVersion, Changes, Upgrade0),
Downgrade = update_actions(PredVersion, Changes, Downgrade0), Downgrade = update_actions(PredVersion, Changes, Downgrade0),
IOList = io_lib:format("%% -*- mode: erlang -*- render_appfile(File, Upgrade, Downgrade),
{VSN,~n ~p,~n ~p}.~n", [Upgrade, Downgrade]),
ok = file:write_file(File, IOList),
%% Check appup syntax: %% Check appup syntax:
_ = read_appup(File). _ = read_appup(File).
render_appfile(File, Upgrade, Downgrade) ->
IOList = io_lib:format("%% -*- mode: erlang -*-\n{VSN,~n ~p,~n ~p}.~n", [Upgrade, Downgrade]),
ok = file:write_file(File, IOList).
update_actions(PredVersion, Changes, Versions) -> update_actions(PredVersion, Changes, Versions) ->
lists:map(fun(L) -> do_update_actions(Changes, L) end, ensure_pred_version(PredVersion, Versions)). lists:map(fun(L) -> do_update_actions(Changes, L) end, ensure_pred_version(PredVersion, Versions)).
@ -183,6 +207,16 @@ hashsums([File|Rest], Acc0) ->
), ),
hashsums(Rest, Acc). hashsums(Rest, Acc).
%% Locate a file in a specified application
locate(App, Suffix) ->
AppStr = atom_to_list(App),
case filelib:wildcard("{src,apps,lib-*}/**/" ++ AppStr ++ Suffix) of
[File] ->
{ok, File};
[] ->
undefined
end.
%% Spawn an executable and return the exit status %% Spawn an executable and return the exit status
cmd(Exec, Params) -> cmd(Exec, Params) ->
case os:find_executable(Exec) of case os:find_executable(Exec) of