diff options
author | Jared Morrow <jared@basho.com> | 2014-03-05 13:35:11 -0700 |
---|---|---|
committer | Jared Morrow <jared@basho.com> | 2014-03-05 13:35:11 -0700 |
commit | a361719781d1a679b9c5e49a46e78a61d3a4450c (patch) | |
tree | 359f7230ca6e8462f83ea57654083e48878660c4 | |
parent | 17fe5d6f1c1d7f45141a7f81bdbbb4b7334fe99b (diff) | |
parent | ebbb927cbc5ea634dc5af02803a0a271d3312f82 (diff) |
Merge pull request #139 from rnewson/depmods
Allow specification of module dependencies for appups
-rw-r--r-- | src/rebar_appups.erl | 43 |
1 files changed, 26 insertions, 17 deletions
diff --git a/src/rebar_appups.erl b/src/rebar_appups.erl index 722f161..a51c30d 100644 --- a/src/rebar_appups.erl +++ b/src/rebar_appups.erl @@ -50,6 +50,8 @@ PrevRelPath = rebar_rel_utils:get_previous_release_path(Config), OldVerPath = filename:join([TargetParentDir, PrevRelPath]), + ModDeps = rebar_config:get(Config, module_deps, []), + %% Get the new and old release name and versions {Name, _Ver} = rebar_rel_utils:get_reltool_release_info(ReltoolConfig), NewVerPath = filename:join([TargetParentDir, Name]), @@ -77,7 +79,7 @@ UpgradeApps = genappup_which_apps(Upgraded, AppUpApps), %% Generate appup files for upgraded apps - generate_appup_files(NewVerPath, OldVerPath, UpgradeApps), + generate_appup_files(NewVerPath, OldVerPath, ModDeps, UpgradeApps), {ok, Config1}. @@ -139,9 +141,9 @@ genappup_which_apps(UpgradedApps, [First|Rest]) -> genappup_which_apps(Apps, []) -> Apps. -generate_appup_files(NewVerPath, OldVerPath, [{_App, {undefined, _}}|Rest]) -> - generate_appup_files(NewVerPath, OldVerPath, Rest); -generate_appup_files(NewVerPath, OldVerPath, [{App, {OldVer, NewVer}}|Rest]) -> +generate_appup_files(NewVerPath, OldVerPath, ModDeps, [{_App, {undefined, _}}|Rest]) -> + generate_appup_files(NewVerPath, OldVerPath, ModDeps, Rest); +generate_appup_files(NewVerPath, OldVerPath, ModDeps, [{App, {OldVer, NewVer}}|Rest]) -> OldEbinDir = filename:join([OldVerPath, "lib", atom_to_list(App) ++ "-" ++ OldVer, "ebin"]), NewEbinDir = filename:join([NewVerPath, "lib", @@ -150,9 +152,14 @@ generate_appup_files(NewVerPath, OldVerPath, [{App, {OldVer, NewVer}}|Rest]) -> {AddedFiles, DeletedFiles, ChangedFiles} = beam_lib:cmp_dirs(NewEbinDir, OldEbinDir), + ChangedNames = [list_to_atom(file_to_name(F)) || {F, _} <- ChangedFiles], + ModDeps1 = [{N, [M1 || M1 <- M, lists:member(M1, ChangedNames)]} + || {N, M} <- ModDeps], + Added = [generate_instruction(added, File) || File <- AddedFiles], Deleted = [generate_instruction(deleted, File) || File <- DeletedFiles], - Changed = [generate_instruction(changed, File) || File <- ChangedFiles], + Changed = [generate_instruction(changed, ModDeps1, File) + || File <- ChangedFiles], Inst = lists:append([Added, Deleted, Changed]), @@ -164,8 +171,8 @@ generate_appup_files(NewVerPath, OldVerPath, [{App, {OldVer, NewVer}}|Rest]) -> OldVer, Inst, OldVer])), ?CONSOLE("Generated appup for ~p~n", [App]), - generate_appup_files(NewVerPath, OldVerPath, Rest); -generate_appup_files(_, _, []) -> + generate_appup_files(NewVerPath, OldVerPath, ModDeps, Rest); +generate_appup_files(_, _, _, []) -> ?CONSOLE("Appup generation complete~n", []). generate_instruction(added, File) -> @@ -173,25 +180,27 @@ generate_instruction(added, File) -> {add_module, Name}; generate_instruction(deleted, File) -> Name = list_to_atom(file_to_name(File)), - {delete_module, Name}; -generate_instruction(changed, {File, _}) -> + {delete_module, Name}. + +generate_instruction(changed, ModDeps, {File, _}) -> {ok, {Name, List}} = beam_lib:chunks(File, [attributes, exports]), Behavior = get_behavior(List), CodeChange = is_code_change(List), - generate_instruction_advanced(Name, Behavior, CodeChange). + Deps = proplists:get_value(Name, ModDeps, []), + generate_instruction_advanced(Name, Behavior, CodeChange, Deps). -generate_instruction_advanced(Name, undefined, undefined) -> +generate_instruction_advanced(Name, undefined, undefined, Deps) -> %% Not a behavior or code change, assume purely functional - {load_module, Name}; -generate_instruction_advanced(Name, [supervisor], _) -> + {load_module, Name, Deps}; +generate_instruction_advanced(Name, [supervisor], _, _) -> %% Supervisor {update, Name, supervisor}; -generate_instruction_advanced(Name, _, code_change) -> +generate_instruction_advanced(Name, _, code_change, Deps) -> %% Includes code_change export - {update, Name, {advanced, []}}; -generate_instruction_advanced(Name, _, _) -> + {update, Name, {advanced, []}, Deps}; +generate_instruction_advanced(Name, _, _, Deps) -> %% Anything else - {load_module, Name}. + {load_module, Name, Deps}. get_behavior(List) -> Attributes = proplists:get_value(attributes, List), |