Browse Source

Broaden expected typespec

pull/2412/head
Paulo F. Oliveira 4 years ago
parent
commit
61f7e4784f
2 changed files with 35 additions and 12 deletions
  1. +12
    -11
      src/rebar_app_info.erl
  2. +23
    -1
      src/rebar_git_resource.erl

+ 12
- 11
src/rebar_app_info.erl View File

@ -82,13 +82,14 @@
project_type/0]).
-type project_type() :: rebar3 | mix | undefined.
-type app_vsn() :: binary() | string() | {git, short} | {git, long}.
-record(app_info_t, {name :: binary() | undefined,
app_file_src :: file:filename_all() | undefined,
app_file_src_script:: file:filename_all() | undefined,
app_file :: file:filename_all() | undefined,
original_vsn :: binary() | string() | undefined,
vsn :: binary() | string() | undefined,
original_vsn :: app_vsn() | undefined,
vsn :: app_vsn() | undefined,
parent=root :: binary() | root | string(),
app_details=[] :: list(),
applications=[] :: list(),
@ -130,7 +131,7 @@ new(AppName) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName)}}.
%% @doc Build a new app info value with only the name and version set.
-spec new(atom() | binary() | string(), binary() | string()) ->
-spec new(atom() | binary() | string(), app_vsn()) ->
{ok, t()}.
new(AppName, Vsn) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
@ -138,7 +139,7 @@ new(AppName, Vsn) ->
original_vsn=Vsn}}.
%% @doc build a complete version of the app info with all fields set.
-spec new(atom() | binary() | string(), binary() | string(), file:name()) ->
-spec new(atom() | binary() | string(), app_vsn(), file:name()) ->
{ok, t()}.
new(AppName, Vsn, Dir) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
@ -150,7 +151,7 @@ new(AppName, Vsn, Dir) ->
ebin_dir=filename:join(rebar_utils:to_list(Dir), "ebin")}}.
%% @doc build a complete version of the app info with all fields set.
-spec new(atom() | binary() | string(), binary() | string(), file:name(), list()) ->
-spec new(atom() | binary() | string(), app_vsn(), file:name(), list()) ->
{ok, t()}.
new(AppName, Vsn, Dir, Deps) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
@ -163,7 +164,7 @@ new(AppName, Vsn, Dir, Deps) ->
deps=Deps}}.
%% @doc build a complete version of the app info with all fields set.
-spec new(atom() | binary(), atom() | binary() | string(), binary() | string(), file:name(), list()) ->
-spec new(atom() | binary(), atom() | binary() | string(), app_vsn(), file:name(), list()) ->
{ok, t()}.
new(Parent, AppName, Vsn, Dir, Deps) ->
{ok, #app_info_t{name=rebar_utils:to_binary(AppName),
@ -177,7 +178,7 @@ new(Parent, AppName, Vsn, Dir, Deps) ->
deps=Deps}}.
-spec app_to_map(t()) -> #{name := atom(),
vsn := binary() | string(),
vsn := app_vsn(),
applications := [atom()],
included_applications := [atom()],
dir := file:name(),
@ -425,23 +426,23 @@ parent(AppInfo=#app_info_t{}, Parent) ->
%% @doc returns the original version of the app (unevaluated if
%% asking for a semver)
-spec original_vsn(t()) -> binary() | string().
-spec original_vsn(t()) -> app_vsn().
original_vsn(#app_info_t{original_vsn=Vsn}) ->
Vsn.
%% @doc stores the original version of the app (unevaluated if
%% asking for a semver)
-spec original_vsn(t(), binary() | string()) -> t().
-spec original_vsn(t(), app_vsn()) -> t().
original_vsn(AppInfo=#app_info_t{}, Vsn) ->
AppInfo#app_info_t{original_vsn=Vsn}.
%% @doc returns the version of the app after evaluation
-spec vsn(t()) -> binary() | string().
-spec vsn(t()) -> app_vsn().
vsn(#app_info_t{vsn=Vsn}) ->
Vsn.
%% @doc sets the evaluated vsn of the app
-spec vsn(t(), binary() | string()) -> t().
-spec vsn(t(), app_vsn()) -> t().
vsn(AppInfo=#app_info_t{}, Vsn) ->
AppInfo#app_info_t{vsn=Vsn}.

+ 23
- 1
src/rebar_git_resource.erl View File

@ -253,7 +253,16 @@ git_vsn_fetch() ->
make_vsn(AppInfo, _) ->
Dir = rebar_app_info:dir(AppInfo),
make_vsn_(Dir).
case rebar_app_info:original_vsn(AppInfo) of
{git, short} ->
git_ref(Dir, "--short");
{git, long} ->
git_ref(Dir, "");
_ ->
%% already parsed in rebar_utils to get here so we know it
%% is either for git or "git"
make_vsn_(Dir)
end.
make_vsn_(Dir) ->
case collect_default_refcount(Dir) of
@ -265,6 +274,19 @@ make_vsn_(Dir) ->
%% Internal functions
git_ref(Dir, Arg) ->
case rebar_utils:sh("git rev-parse " ++ Arg ++ " HEAD",
[{use_stdout, false},
return_on_error,
{cd, Dir}]) of
{error, _} ->
?WARN("Getting ref of git repo failed in ~ts. "
"Falling back to version 0", [Dir]),
{plain, "0"};
{ok, String} ->
{plain, rebar_string:trim(String, both, "\n")}
end.
collect_default_refcount(Dir) ->
%% Get the tag timestamp and minimal ref from the system. The
%% timestamp is really important from an ordering perspective.

Loading…
Cancel
Save