Skip to content

Commit

Permalink
Merge branch 'release/2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lrascao committed Dec 5, 2017
2 parents 89626b6 + 1b1835b commit b667b01
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 42 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]

## [2.3.0] - 05-12-2017
### Added
* [Add support for appup.src dependency overrides](https://github.com/lrascao/rebar3_appup_utils/pull/19)
### Changed
* [Bump bbmustache to 1.5.0](https://github.com/lrascao/rebar3_appup_utils/pull/18)
### Fixed
* [Fix/capital name modules](https://github.com/lrascao/rebar3_appup_utils/pull/21)
* [Properly check appup existence before generating](https://github.com/lrascao/rebar3_appup_utils/pull/25)

## [2.2.1] - 16-08-2017
### Added
* Add debug on clean operation
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ endif

.PHONY: all compile clean dialyzer test

travis: test
travis: update test

all: deps compile

# =============================================================================
Expand All @@ -45,6 +46,9 @@ compile: $(REBAR3)
clean: $(REBAR3)
- $(REBAR3) clean

update:
$(REBAR3) update

test: compile
rm -rf _build/test
$(REBAR3) ct
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
debug_info]}.

{deps, [
{bbmustache, "1.1.0"}
{bbmustache, "1.5.0"}
]}.

{cover_enabled, true}.
Expand Down
4 changes: 2 additions & 2 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{"1.1.0",
[{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.1.0">>},0}]}.
[{<<"bbmustache">>,{pkg,<<"bbmustache">>,<<"1.5.0">>},0}]}.
[
{pkg_hash,[
{<<"bbmustache">>, <<"CE45F99301C5796795EDFC0AE2ED477F81558FB59E2579CC17D7BC42F34278D1">>}]}
{<<"bbmustache">>, <<"8CFDE0602E90A4057E161BF5288ADE854B4E511E2E8924966A8438730E958381">>}]}
].
81 changes: 50 additions & 31 deletions src/rebar3_appup_compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -54,34 +54,9 @@ do(State) ->
AppInfo ->
[AppInfo]
end,
%% find all .appup.src files in all project applications
lists:foreach(fun(AppInfo) ->
Source0 = appup_file_src(AppInfo),
case filelib:is_file(Source0) of
true ->
rebar_api:info("Compiling ~s",
[filename:basename(Source0)]),
Target = appup_file_target(AppInfo),
case template(Source0, AppInfo) of
{ok, AppUpBin} ->
%% allocate a temporary file and write the templated
%% contents to it
AppUpFile = rebar3_appup_utils:tmp_filename(),
ok = file:write_file(AppUpFile, AppUpBin),
case evaluate(AppUpFile, State) of
{ok, AppupTerm} ->
compile(AppupTerm, Target);
{error, Reason} ->
rebar_api:abort("failed to evaluate ~s (template ~p): ~p",
[AppUpFile, Source0, Reason])
end,
%% leave no trash behind
ok = file:delete(AppUpFile);
{error, Reason} ->
rebar_api:abort("unable to render template due to ~p",
[Reason])
end;
false -> ok
end
process_app(AppInfo, State)
end, Apps),
{ok, State}.

Expand All @@ -93,6 +68,49 @@ format_error(Reason) ->
%% ===================================================================
%% Private API
%% ===================================================================

process_app(AppInfo, State) ->
Sources = find_appup_src_files(AppInfo),
lists:foreach(fun(Source) ->
case filelib:is_file(Source) of
true ->
%% this appup.src might pertain to some other
%% application dependency, check for that
Name = list_to_binary(filename:basename(Source, ".appup.src")),
%% fetch this app deps
AppDeps = dict:fetch({parsed_deps,default},
rebar_state:opts(State)),
SourceAppInfo = rebar3_appup_utils:find_app_info(Name,
rebar_state:all_deps(State, AppDeps)),
process_appup_src(Source, SourceAppInfo, State);
false -> ok
end
end, Sources).

process_appup_src(Source, AppInfo, State) ->
Target = appup_file_target(AppInfo),
rebar_api:info("Compiling ~s to ~s",
[filename:basename(Source), Target]),
case template(Source, AppInfo) of
{ok, AppUpBin} ->
%% allocate a temporary file and write the templated
%% contents to it
AppUpFile = rebar3_appup_utils:tmp_filename(),
ok = file:write_file(AppUpFile, AppUpBin),
case evaluate(AppUpFile, State) of
{ok, AppupTerm} ->
compile(AppupTerm, Target);
{error, Reason} ->
rebar_api:abort("failed to evaluate ~s (template ~p): ~p",
[AppUpFile, Source, Reason])
end,
%% leave no trash behind
ok = file:delete(AppUpFile);
{error, Reason} ->
rebar_api:abort("unable to render template due to ~p",
[Reason])
end.

-type bs_vars() :: [{term(), term()}].
-spec bs(bs_vars()) -> bs_vars().
%% @spec bs(bs_vars()) -> bs_vars().
Expand Down Expand Up @@ -135,11 +153,12 @@ compile(AppupTerm, Target) ->
[AppupTerm])
end.

%% @spec appup_file_src(_) -> binary() | string().
appup_file_src(AppInfo) ->
%% @spec find_appup_src_files(_) -> binary() | string().
find_appup_src_files(AppInfo) ->
Dir = rebar_app_info:dir(AppInfo),
Name = rebar_app_info:name(AppInfo),
filename:join([Dir, "src", ec_cnv:to_list(Name) ++ ".appup.src"]).
%% find all *.appup.src files in the application
%% source directory
filelib:wildcard(Dir ++ "/src/*.appup.src").

%% @spec appup_file_target(_) -> binary() | string().
appup_file_target(AppInfo) ->
Expand Down
9 changes: 5 additions & 4 deletions src/rebar3_appup_generate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ do(State) ->
[CurrentName, PreviousName]),

%% Find all the apps that have been upgraded
{AddApps, UpgradeApps0, RemoveApps} = get_apps(Name,
{AddApps0, UpgradeApps0, RemoveApps} = get_apps(Name,
PreviousRelPath, PreviousVer,
CurrentRelPath, CurrentVer,
State),
Expand All @@ -141,7 +141,8 @@ do(State) ->
[CurrentAppUpApps]),

%% Create a list of apps that don't already have appups
UpgradeApps = gen_appup_which_apps(UpgradeApps0, CurrentAppUpApps),
UpgradeApps = gen_appup_which_apps(UpgradeApps0 ++ AddApps0, CurrentAppUpApps),
AddApps = gen_appup_which_apps(AddApps0, CurrentAppUpApps),
rebar_api:debug("generating .appup for apps: ~p",
[AddApps ++ UpgradeApps ++ RemoveApps]),

Expand Down Expand Up @@ -269,7 +270,7 @@ file_to_name(File) ->

%% @spec gen_appup_which_apps([any()],[string()]) -> [any()].
gen_appup_which_apps(UpgradedApps, [First|Rest]) ->
List = proplists:delete(list_to_atom(First), UpgradedApps),
List = lists:keydelete(list_to_atom(First), 2, UpgradedApps),
gen_appup_which_apps(List, Rest);
gen_appup_which_apps(Apps, []) ->
Apps.
Expand Down Expand Up @@ -421,7 +422,7 @@ write_appup(App, OldVer, NewVer, TargetDir,
io_lib:fwrite("~.9p", [UpgradeInstructions])},
{"downgrade_instructions",
io_lib:fwrite("~.9p", [DowngradeInstructions])}],
AppUp = bbmustache:render(AppupTemplate, AppupCtx),
AppUp = bbmustache:render(AppupTemplate, AppupCtx, [{escape_fun, fun(X) -> X end}]),
rebar_api:info("Generated appup (~p <-> ~p) for ~p in ~p",
[OldVer, NewVer, App, AppUpFile]),
ok = file:write_file(AppUpFile, AppUp)
Expand Down
2 changes: 1 addition & 1 deletion src/rebar3_appup_plugin.app.src
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
%% -------------------------------------------------------------------
{application, rebar3_appup_plugin, [
{description, "A rebar3 plugin for handling .appup files"},
{vsn, "2.2.1"},
{vsn, "2.3.0"},
{registered, []},
{applications,
[
Expand Down
3 changes: 2 additions & 1 deletion src/rebar3_appup_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ tmp_filename() ->
%% @spec find_app_info(_,_) -> any().
find_app_info(Name, State) ->
Apps = rebar_state:project_apps(State),
find_app_info1(Name, Apps).
Deps = rebar_state:all_deps(State),
find_app_info1(Name, Apps ++ Deps).

%% @spec find_app_info1(_,maybe_improper_list()) -> any().
find_app_info1(_Name, []) -> undefined;
Expand Down
35 changes: 34 additions & 1 deletion test/rebar3_appup_plugin_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ groups() ->
appup_src_template_vars,
appup_src_state_var_scripting,
add_supervisor_worker, remove_supervisor_worker,
multiple_behaviours]
multiple_behaviours,
custom_application_appup,
capital_named_modules]
}].

init_per_suite(Config) ->
Expand Down Expand Up @@ -701,6 +703,37 @@ multiple_behaviours(Config) when is_list(Config) ->
Config),
ok.

custom_application_appup(doc) -> ["Use a custom appup maintained in the application for defining upgrade "
" instructions for a dependency"];
custom_application_appup(suite) -> [];
custom_application_appup(Config) when is_list(Config) ->
AfterUpgradeFun = fun(DeployDir, State) ->
{ok, "0.5.2"} = get_app_version("statsderl", DeployDir),
State
end,
AfterDowngradeFun = fun(DeployDir, State) ->
{ok, "0.3.5"} = get_app_version("statsderl", DeployDir),
State
end,
ok = upgrade_downgrade("relapp1", "1.0.24", "1.0.25",
[{after_upgrade, AfterUpgradeFun},
{after_downgrade, AfterDowngradeFun}],
{[], []},
[{delete_appup_src, true}],
Config),
ok.

capital_named_modules(doc) -> ["Generate an appup for a release containing a module with capital name"];
capital_named_modules(suite) -> [];
capital_named_modules(Config) when is_list(Config) ->
ok = upgrade_downgrade("relapp1", "1.0.27", "1.0.28",
[],
{[{add_module, 'RELAPP-CAPITAL-TEST_m2', []}],
[{delete_module, 'RELAPP-CAPITAL-TEST_m2'}]},
[{delete_appup_src, true}],
Config),
ok.

%% -------------------------------------------------------------
%% Private methods
%% -------------------------------------------------------------
Expand Down

0 comments on commit b667b01

Please sign in to comment.