summaryrefslogtreecommitdiff
path: root/src/rebar_appups.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_appups.erl')
-rw-r--r--src/rebar_appups.erl66
1 files changed, 40 insertions, 26 deletions
diff --git a/src/rebar_appups.erl b/src/rebar_appups.erl
index 079d596..871c426 100644
--- a/src/rebar_appups.erl
+++ b/src/rebar_appups.erl
@@ -56,22 +56,20 @@
"Reltool and .rel release names do not match~n", []),
%% Find all the apps that have been upgraded
- UpgradedApps = get_upgraded_apps(Name, OldVerPath, NewVerPath),
+ {_Added, _Removed, Upgraded} = get_apps(Name, OldVerPath, NewVerPath),
%% Get a list of any appup files that exist in the new release
NewAppUpFiles = rebar_utils:find_files(
filename:join([NewName, "lib"]), "^.*.appup$"),
%% Convert the list of appup files into app names
- AppUpApps = lists:map(fun(File) ->
- file_to_name(File)
- end, NewAppUpFiles),
+ AppUpApps = [file_to_name(File) || File <- NewAppUpFiles],
%% Create a list of apps that don't already have appups
- Apps = genappup_which_apps(UpgradedApps, AppUpApps),
+ UpgradeApps = genappup_which_apps(Upgraded, AppUpApps),
- %% Generate appup files
- generate_appup_files(Name, OldVerPath, Apps),
+ %% Generate appup files for upgraded apps
+ generate_appup_files(Name, OldVerPath, UpgradeApps),
ok.
@@ -79,24 +77,43 @@
%% Internal functions
%% ===================================================================
-get_upgraded_apps(Name, OldVerPath, NewVerPath) ->
+get_apps(Name, OldVerPath, NewVerPath) ->
OldApps = rebar_rel_utils:get_rel_apps(Name, OldVerPath),
+ ?DEBUG("Old Version Apps: ~p~n", [OldApps]),
+
NewApps = rebar_rel_utils:get_rel_apps(Name, NewVerPath),
+ ?DEBUG("New Version Apps: ~p~n", [NewApps]),
+
+ Added = app_list_diff(NewApps, OldApps),
+ ?DEBUG("Added: ~p~n", [Added]),
+
+ Removed = app_list_diff(OldApps, NewApps),
+ ?DEBUG("Removed: ~p~n", [Removed]),
+
+ PossiblyUpgraded = proplists:get_keys(NewApps),
- Sorted = lists:umerge(lists:sort(NewApps), lists:sort(OldApps)),
- AddedorChanged = lists:subtract(Sorted, OldApps),
- DeletedorChanged = lists:subtract(Sorted, NewApps),
- ?DEBUG("Added or Changed: ~p~n", [AddedorChanged]),
- ?DEBUG("Deleted or Changed: ~p~n", [DeletedorChanged]),
+ UpgradedApps = [upgraded_app(AppName,
+ proplists:get_value(AppName, OldApps),
+ proplists:get_value(AppName, NewApps))
+ || AppName <- PossiblyUpgraded],
- AddedDeletedChanged = lists:ukeysort(1, lists:append(DeletedorChanged,
- AddedorChanged)),
- UpgradedApps = lists:subtract(AddedorChanged, AddedDeletedChanged),
- ?DEBUG("Upgraded Apps:~p~n", [UpgradedApps]),
+ Upgraded = lists:dropwhile(fun(Elem) ->
+ Elem == false
+ end, lists:sort(UpgradedApps)),
- [{AppName, {proplists:get_value(AppName, OldApps), NewVer}}
- || {AppName, NewVer} <- UpgradedApps].
+ ?DEBUG("Upgraded: ~p~n", [Upgraded]),
+ {Added, Removed, Upgraded}.
+
+upgraded_app(AppName, OldAppVer, NewAppVer) when OldAppVer /= NewAppVer ->
+ {AppName, {OldAppVer, NewAppVer}};
+upgraded_app(_, _, _) ->
+ false.
+
+app_list_diff(List1, List2) ->
+ List3 = lists:umerge(lists:sort(proplists:get_keys(List1)),
+ lists:sort(proplists:get_keys(List2))),
+ List3 -- proplists:get_keys(List2).
file_to_name(File) ->
filename:rootname(filename:basename(File)).
@@ -161,13 +178,10 @@ generate_instruction_advanced(Name, _, _) ->
get_behavior(List) ->
Attributes = proplists:get_value(attributes, List),
- Behavior = case proplists:get_value(behavior, Attributes) of
- undefined ->
- proplists:get_value(behaviour, Attributes);
- Else ->
- Else
- end,
- Behavior.
+ case proplists:get_value(behavior, Attributes) of
+ undefined -> proplists:get_value(behaviour, Attributes);
+ Else -> Else
+ end.
is_code_change(List) ->
Exports = proplists:get_value(exports, List),