Browse Source

Merge pull request #2303 from tsloughter/app-info-vsn

add vsn that is the evaluated application vsn
pull/2313/head
Tristan Sloughter 4 years ago
committed by GitHub
parent
commit
67b0c7ea19
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 15 deletions
  1. +3
    -2
      src/rebar_app_discover.erl
  2. +18
    -1
      src/rebar_app_info.erl
  3. +5
    -8
      src/rebar_otp_app.erl
  4. +4
    -3
      src/rebar_prv_compile.erl
  5. +4
    -1
      src/rebar_state.erl

+ 3
- 2
src/rebar_app_discover.erl View File

@ -364,8 +364,9 @@ create_app_info(AppInfo, AppDir, AppFile) ->
Applications = proplists:get_value(applications, AppDetails, []), Applications = proplists:get_value(applications, AppDetails, []),
IncludedApplications = proplists:get_value(included_applications, AppDetails, []), IncludedApplications = proplists:get_value(included_applications, AppDetails, []),
AppInfo1 = rebar_app_info:name( AppInfo1 = rebar_app_info:name(
rebar_app_info:original_vsn(
rebar_app_info:dir(AppInfo, AppDir), AppVsn), AppName),
rebar_app_info:vsn(
rebar_app_info:original_vsn(
rebar_app_info:dir(AppInfo, AppDir), AppVsn), AppVsn), AppName),
AppInfo2 = rebar_app_info:applications( AppInfo2 = rebar_app_info:applications(
rebar_app_info:app_details(AppInfo1, AppDetails), Applications), rebar_app_info:app_details(AppInfo1, AppDetails), Applications),
AppInfo3 = rebar_app_info:included_applications(AppInfo2, IncludedApplications), AppInfo3 = rebar_app_info:included_applications(AppInfo2, IncludedApplications),

+ 18
- 1
src/rebar_app_info.erl View File

@ -25,6 +25,8 @@
parent/2, parent/2,
original_vsn/1, original_vsn/1,
original_vsn/2, original_vsn/2,
vsn/1,
vsn/2,
priv_dir/1, priv_dir/1,
applications/1, applications/1,
applications/2, applications/2,
@ -86,6 +88,7 @@
app_file_src_script:: file:filename_all() | undefined, app_file_src_script:: file:filename_all() | undefined,
app_file :: file:filename_all() | undefined, app_file :: file:filename_all() | undefined,
original_vsn :: binary() | undefined, original_vsn :: binary() | undefined,
vsn :: binary() | undefined,
parent=root :: binary() | root, parent=root :: binary() | root,
app_details=[] :: list(), app_details=[] :: list(),
applications=[] :: list(), applications=[] :: list(),
@ -131,6 +134,7 @@ new(AppName) ->
{ok, t()}. {ok, t()}.
new(AppName, Vsn) -> new(AppName, Vsn) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName), {ok, #app_info_t{name=rebar_utils:to_binary(AppName),
vsn=Vsn,
original_vsn=Vsn}}. original_vsn=Vsn}}.
%% @doc build a complete version of the app info with all fields set. %% @doc build a complete version of the app info with all fields set.
@ -138,6 +142,7 @@ new(AppName, Vsn) ->
{ok, t()}. {ok, t()}.
new(AppName, Vsn, Dir) -> new(AppName, Vsn, Dir) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName), {ok, #app_info_t{name=rebar_utils:to_binary(AppName),
vsn=Vsn,
original_vsn=Vsn, original_vsn=Vsn,
fetch_dir=rebar_utils:to_list(Dir), fetch_dir=rebar_utils:to_list(Dir),
dir=rebar_utils:to_list(Dir), dir=rebar_utils:to_list(Dir),
@ -149,6 +154,7 @@ new(AppName, Vsn, Dir) ->
{ok, t()}. {ok, t()}.
new(AppName, Vsn, Dir, Deps) -> new(AppName, Vsn, Dir, Deps) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName), {ok, #app_info_t{name=rebar_utils:to_binary(AppName),
vsn=Vsn,
original_vsn=Vsn, original_vsn=Vsn,
fetch_dir=rebar_utils:to_list(Dir), fetch_dir=rebar_utils:to_list(Dir),
dir=rebar_utils:to_list(Dir), dir=rebar_utils:to_list(Dir),
@ -162,6 +168,7 @@ new(AppName, Vsn, Dir, Deps) ->
new(Parent, AppName, Vsn, Dir, Deps) -> new(Parent, AppName, Vsn, Dir, Deps) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName), {ok, #app_info_t{name=rebar_utils:to_binary(AppName),
parent=Parent, parent=Parent,
vsn=Vsn,
original_vsn=Vsn, original_vsn=Vsn,
fetch_dir=rebar_utils:to_list(Dir), fetch_dir=rebar_utils:to_list(Dir),
dir=rebar_utils:to_list(Dir), dir=rebar_utils:to_list(Dir),
@ -170,7 +177,7 @@ new(Parent, AppName, Vsn, Dir, Deps) ->
deps=Deps}}. deps=Deps}}.
app_to_map(#app_info_t{name=Name, app_to_map(#app_info_t{name=Name,
original_vsn=Vsn,
vsn=Vsn,
applications=Applications, applications=Applications,
included_applications=IncludedApplications, included_applications=IncludedApplications,
out_dir=OutDir, out_dir=OutDir,
@ -421,6 +428,16 @@ original_vsn(#app_info_t{original_vsn=Vsn}) ->
original_vsn(AppInfo=#app_info_t{}, Vsn) -> original_vsn(AppInfo=#app_info_t{}, Vsn) ->
AppInfo#app_info_t{original_vsn=Vsn}. AppInfo#app_info_t{original_vsn=Vsn}.
%% @doc returns the version of the app after evaluation
-spec vsn(t()) -> binary().
vsn(#app_info_t{vsn=Vsn}) ->
Vsn.
%% @doc sets the evaluated vsn of the app
-spec vsn(t(), binary() | string()) -> t().
vsn(AppInfo=#app_info_t{}, Vsn) ->
AppInfo#app_info_t{vsn=Vsn}.
%% @doc returns the list of applications the app depends on. %% @doc returns the list of applications the app depends on.
-spec applications(t()) -> list(). -spec applications(t()) -> list().
applications(#app_info_t{applications=Applications}) -> applications(#app_info_t{applications=Applications}) ->

+ 5
- 8
src/rebar_otp_app.erl View File

@ -46,12 +46,10 @@ compile(State, App) ->
undefined -> undefined ->
App; App;
AppFileSrc -> AppFileSrc ->
File = preprocess(State, App, AppFileSrc),
rebar_app_info:app_file(App, File)
preprocess(State, App, AppFileSrc)
end; end;
AppFileSrcScript -> AppFileSrcScript ->
File = preprocess(State, App, AppFileSrcScript),
rebar_app_info:app_file(App, File)
preprocess(State, App, AppFileSrcScript)
end, end,
%% Load the app file and validate it. %% Load the app file and validate it.
@ -87,17 +85,16 @@ validate_app_modules(State, App, AppData) ->
%% In general, the list of modules is an important thing to validate %% In general, the list of modules is an important thing to validate
%% for compliance with OTP guidelines and upgrade procedures. %% for compliance with OTP guidelines and upgrade procedures.
%% However, some people prefer not to validate this list. %% However, some people prefer not to validate this list.
AppVsn = proplists:get_value(vsn, AppData),
case rebar_state:get(State, validate_app_modules, true) of case rebar_state:get(State, validate_app_modules, true) of
true -> true ->
case rebar_app_utils:validate_application_info(App, AppData) of case rebar_app_utils:validate_application_info(App, AppData) of
true -> true ->
{ok, rebar_app_info:original_vsn(App, AppVsn)};
{ok, App};
Error -> Error ->
Error Error
end; end;
false -> false ->
{ok, rebar_app_info:original_vsn(App, AppVsn)}
{ok, App}
end. end.
preprocess(State, AppInfo, AppSrcFile) -> preprocess(State, AppInfo, AppSrcFile) ->
@ -130,7 +127,7 @@ preprocess(State, AppInfo, AppSrcFile) ->
AppFile = rebar_app_utils:app_src_to_app(OutDir, AppSrcFile), AppFile = rebar_app_utils:app_src_to_app(OutDir, AppSrcFile),
ok = rebar_file_utils:write_file_if_contents_differ(AppFile, Spec, utf8), ok = rebar_file_utils:write_file_if_contents_differ(AppFile, Spec, utf8),
AppFile;
rebar_app_info:app_file(rebar_app_info:vsn(AppInfo, Vsn), AppFile);
{error, Reason} -> {error, Reason} ->
throw(?PRV_ERROR({file_read, rebar_app_info:name(AppInfo), ".app.src", Reason})) throw(?PRV_ERROR({file_read, rebar_app_info:name(AppInfo), ".app.src", Reason}))
end. end.

+ 4
- 3
src/rebar_prv_compile.erl View File

@ -40,13 +40,14 @@ do(State) ->
Providers = rebar_state:providers(State), Providers = rebar_state:providers(State),
Deps = rebar_state:deps_to_build(State), Deps = rebar_state:deps_to_build(State),
copy_and_build_apps(State, Providers, Deps),
CompiledDeps = copy_and_build_apps(State, Providers, Deps),
State0 = rebar_state:merge_all_deps(State, CompiledDeps),
State1 = case IsDepsOnly of State1 = case IsDepsOnly of
true -> true ->
State;
State0;
false -> false ->
handle_project_apps(Providers, State)
handle_project_apps(Providers, State0)
end, end,
rebar_paths:set_paths([plugins], State1), rebar_paths:set_paths([plugins], State1),

+ 4
- 1
src/rebar_state.erl View File

@ -31,7 +31,7 @@
project_apps/1, project_apps/2, project_apps/1, project_apps/2,
deps_to_build/1, deps_to_build/2, deps_to_build/1, deps_to_build/2,
all_plugin_deps/1, all_plugin_deps/2, update_all_plugin_deps/2, all_plugin_deps/1, all_plugin_deps/2, update_all_plugin_deps/2,
all_deps/1, all_deps/2, update_all_deps/2,
all_deps/1, all_deps/2, update_all_deps/2, merge_all_deps/2,
namespace/1, namespace/2, namespace/1, namespace/2,
deps_names/1, deps_names/1,
@ -354,6 +354,9 @@ update_all_plugin_deps(State=#state_t{all_plugin_deps=Apps}, NewApps) ->
update_all_deps(State=#state_t{all_deps=Apps}, NewApps) -> update_all_deps(State=#state_t{all_deps=Apps}, NewApps) ->
State#state_t{all_deps=Apps++NewApps}. State#state_t{all_deps=Apps++NewApps}.
merge_all_deps(State=#state_t{all_deps=Apps}, UpdatedApps) when is_list(UpdatedApps) ->
State#state_t{all_deps=lists:ukeymerge(2, lists:keysort(2, UpdatedApps), lists:keysort(2, Apps))}.
namespace(#state_t{namespace=Namespace}) -> namespace(#state_t{namespace=Namespace}) ->
Namespace. Namespace.

Loading…
Cancel
Save