Skip to content

Commit

Permalink
Merge branch 'release/2.4.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
lrascao committed Dec 16, 2018
2 parents ee06bf5 + 7ef5c04 commit 7244851
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 55 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
sudo: false
language: erlang
otp_release:
- 20.0
- 21.0.4
- 20.3.8.2
- 19.3
- 18.3
- 17.5
- R16B03-1
before_script:
- wget https://s3.amazonaws.com/rebar3-nightly/rebar3
- chmod u+x rebar3
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,17 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][unreleased]

## [2.4.2] - 16-12-2018
### Added
### Changed
### Fixed
- [(fix) Support relx release configs that contain opts](https://github.com/lrascao/rebar3_appup_utils/pull/53)
- [Fix/#49/appup not generated](https://github.com/lrascao/rebar3_appup_utils/pull/52)
- [read original_vsn from the app file](https://github.com/lrascao/rebar3_appup_utils/pull/36)
- [Add auxilliary vsn method for appup state scripting](https://github.com/lrascao/rebar3_appup_utils/pull/50)
- [add dialyzer test](https://github.com/lrascao/rebar3_appup_utils/pull/48)
- [Deprecate OTP R16B](https://github.com/lrascao/rebar3_appup_utils/pull/46)

## [2.4.1] - 05-03-2018
### Added
### Changed
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ endif

.PHONY: all compile clean dialyzer test

travis: update test
travis: update test dialyzer

all: deps compile

Expand Down
11 changes: 6 additions & 5 deletions src/rebar3_appup_compile.erl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ format_error(Reason) ->
%% ===================================================================

process_app(AppInfo, State) ->
Vsn = rebar_app_info:original_vsn(AppInfo),
Sources = find_appup_src_files(AppInfo),
lists:foreach(fun(Source) ->
case filelib:is_file(Source) of
Expand All @@ -78,16 +79,16 @@ process_app(AppInfo, State) ->
%% application dependency, check for that
Name = list_to_binary(filename:basename(Source, ".appup.src")),
SourceAppInfo = rebar3_appup_utils:find_app_info(Name, State),
process_appup_src(Source, SourceAppInfo, State);
process_appup_src(Source, SourceAppInfo, State, Vsn);
false -> ok
end
end, Sources).

process_appup_src(Source, AppInfo, State) ->
process_appup_src(Source, AppInfo, State, Vsn) ->
Target = appup_file_target(AppInfo),
rebar_api:info("Compiling ~s to ~s",
[filename:basename(Source), Target]),
case template(Source, AppInfo) of
case template(Source, Vsn) of
{ok, AppUpBin} ->
%% allocate a temporary file and write the templated
%% contents to it
Expand Down Expand Up @@ -119,8 +120,8 @@ bs(Vars) ->
evaluate(Source, State) ->
file:script(Source, bs([{'STATE', State}])).

template(Source, AppInfo) ->
Context = [{"vsn", rebar_app_info:original_vsn(AppInfo)}],
template(Source, Vsn) ->
Context = [{"vsn", Vsn}],
{ok, Template} = file:read_file(Source),
case catch bbmustache:render(Template, Context) of
B when is_binary(B) -> {ok, B};
Expand Down
32 changes: 23 additions & 9 deletions src/rebar3_appup_generate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ do(State) ->
filename:join([CurrentRelPath, "lib"]),
".appup"),
%% Convert the list of appup files into app names
CurrentAppUpApps = [file_to_name(File) || File <- CurrentAppUpFiles],
CurrentAppUpApps = lists:usort([appup_info(File) || File <- CurrentAppUpFiles]),
rebar_api:debug("apps that already have .appups: ~p",
[CurrentAppUpApps]),

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

Expand Down Expand Up @@ -272,11 +272,21 @@ app_list_diff(List1, List2) ->
file_to_name(File) ->
filename:rootname(filename:basename(File)).

%% @spec appup_info(string()) -> {App :: atom(),
%% ToVersion :: string()}.
appup_info(File) ->
{ok, [{ToVersion, _, _}]} = file:consult(File),
{file_to_name(File), ToVersion}.

%% @spec gen_appup_which_apps([any()],[string()]) -> [any()].
gen_appup_which_apps(UpgradedApps, [First|Rest]) ->
List = lists:keydelete(list_to_atom(First), 2, UpgradedApps),
gen_appup_which_apps(List, Rest);
gen_appup_which_apps(Apps, []) ->
gen_appup_which_apps(UpgradedApps0, CurrentVersion, [{App, Version} | Rest]) ->
UpgradedApps = case CurrentVersion =:= Version of
true ->
lists:keydelete(list_to_atom(App), 2, UpgradedApps0);
false -> UpgradedApps0
end,
gen_appup_which_apps(UpgradedApps, CurrentVersion, Rest);
gen_appup_which_apps(Apps, _CurrentVersion, []) ->
Apps.

%% @spec generate_appup_files(_,atom() | binary() | [atom() | [any()] | char()],atom() | binary() | [atom() | [any()] | char()],{'upgrade',_,{'undefined' | [any()],_}},[{'plugin_dir',_} | {'purge_opts',[any()]},...],_) -> 'ok'.
Expand Down Expand Up @@ -724,8 +734,12 @@ get_current_rel_path(State, Name) ->
Res :: string().
get_release_name(State) ->
RelxConfig = rebar_state:get(State, relx, []),
{release, {Name0, _Ver}, _} = lists:keyfind(release, 1, RelxConfig),
atom_to_list(Name0).
case lists:keyfind(release, 1, RelxConfig) of
{release, {Name0, _Ver}, _} ->
atom_to_list(Name0);
{release, {Name0, _Ver}, _, _} ->
atom_to_list(Name0)
end.

%%------------------------------------------------------------------------------
%%
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.4.1"},
{vsn, "2.4.2"},
{registered, []},
{applications,
[
Expand Down
19 changes: 14 additions & 5 deletions src/rebar3_appup_tar.erl
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,12 @@ init(State) ->
%% @spec do(rebar_state:t()) -> {'ok',rebar_state:t()} | {'error',string()}.
do(State) ->
RelxConfig = rebar_state:get(State, relx, []),
{release, {Name0, _Ver}, _} = lists:keyfind(release, 1, RelxConfig),
Name = atom_to_list(Name0),
Name = case lists:keyfind(release, 1, RelxConfig) of
{release, {Name0, _Ver}, _} ->
atom_to_list(Name0);
{release, {Name0, _Ver}, _, _} ->
atom_to_list(Name0)
end,
rebar_api:debug("release name: ~p", [Name]),

RelDir = filename:join([rebar_dir:base_dir(State),
Expand Down Expand Up @@ -423,7 +427,7 @@ match_code_change_args([_, _, _]) ->
{undefined, []}.

% TODO - upply the code change line to the call
-spec apply_code_change_line(_, erl_parse:abstract_form()) -> erl_parse:abstract_form().
-spec apply_code_change_line(_, erl_parse:abstract_form()) -> erl_parse:abstract_form() | [erl_parse:abstract_expr()].
%% @spec apply_code_change_line(_,_) -> any().
apply_code_change_line(_L, AbstConvertCall) -> AbstConvertCall.

Expand Down Expand Up @@ -456,10 +460,15 @@ inject_code_change_clause({clause, L, Args, [], Body0} = Clause, Opts) ->
{"extra_ret", ExtraRetStr}],
ConvertCall = bbmustache:render(ConvertCallTemplate, ConvertCallCtx),
AbstConvertCall = apply_code_change_line(L, to_abstract(binary_to_list(ConvertCall))),
{clause, L, NewArgs, [], AbstConvertCall ++ Body0}
case is_list(AbstConvertCall) of
true ->
{clause, L, NewArgs, [], AbstConvertCall ++ Body0};
false ->
{clause, L, NewArgs, [], [AbstConvertCall | Body0]}
end
end.

-spec to_abstract(string()) -> erl_parse:abstract_form().
-spec to_abstract(string()) -> erl_parse:abstract_form() | [erl_parse:abstract_expr()].
%% @spec to_abstract(string()) -> erl_parse:abstract_form().
to_abstract(String) ->
{ok, Tokens, _EndLocation} =
Expand Down
10 changes: 9 additions & 1 deletion src/rebar3_appup_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
beam_rel_path/2, beam_rel_path/4,
get_abstract_code/2,
tmp_filename/0,
find_app_by_name/2]).
find_app_by_name/2,
vsn/1]).

%% Helper function for checking values and aborting when needed
%% @spec prop_check(boolean(),_,_) -> any().
Expand Down Expand Up @@ -164,3 +165,10 @@ find_app_by_name(Name, Apps) ->
rebar_app_info:name(App) =:= Name
end, Apps).

-spec vsn(AppInfo :: term()) -> string().
vsn(AppInfo) ->
case rebar_app_info:original_vsn(AppInfo) of
Vsn when is_binary(Vsn) -> binary_to_list(Vsn);
Vsn when is_list(Vsn) -> Vsn
end.

0 comments on commit 7244851

Please sign in to comment.