Parcourir la source

fix dialyzer warnings, except 'no local return' warnings

pull/696/head
Tristan Sloughter il y a 9 ans
Parent
révision
6fde1748b9
11 fichiers modifiés avec 36 ajouts et 51 suppressions
  1. +1
    -1
      src/rebar_agent.erl
  2. +5
    -10
      src/rebar_app_discover.erl
  3. +2
    -2
      src/rebar_core.erl
  4. +1
    -1
      src/rebar_prv_deps.erl
  5. +9
    -23
      src/rebar_prv_install_deps.erl
  6. +3
    -7
      src/rebar_prv_packages.erl
  7. +1
    -1
      src/rebar_prv_shell.erl
  8. +5
    -0
      src/rebar_prv_update.erl
  9. +1
    -1
      src/rebar_prv_xref.erl
  10. +7
    -4
      src/rebar_state.erl
  11. +1
    -1
      src/rebar_utils.erl

+ 1
- 1
src/rebar_agent.erl Voir le fichier

@ -104,7 +104,7 @@ refresh_paths(RState) ->
ok; ok;
{ok, _} -> {ok, _} ->
?DEBUG("reloading ~p from ~s", [Modules, Path]), ?DEBUG("reloading ~p from ~s", [Modules, Path]),
code:replace_path(Name, Path),
code:replace_path(App, Path),
[begin code:purge(M), code:delete(M), code:load_file(M) end [begin code:purge(M), code:delete(M), code:load_file(M) end
|| M <- Modules] || M <- Modules]
end end

+ 5
- 10
src/rebar_app_discover.erl Voir le fichier

@ -138,7 +138,7 @@ find_app(AppDir, Validate) ->
app_dir(AppFile) -> app_dir(AppFile) ->
filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))). filename:join(rebar_utils:droplast(filename:split(filename:dirname(AppFile)))).
-spec create_app_info(file:name(), file:name()) -> rebar_app_info:t() | {error, term()}.
-spec create_app_info(file:name(), file:name()) -> rebar_app_info:t().
create_app_info(AppDir, AppFile) -> create_app_info(AppDir, AppFile) ->
[{application, AppName, AppDetails}] = rebar_config:consult_app_file(AppFile), [{application, AppName, AppDetails}] = rebar_config:consult_app_file(AppFile),
AppVsn = proplists:get_value(vsn, AppDetails), AppVsn = proplists:get_value(vsn, AppDetails),
@ -208,16 +208,11 @@ try_handle_app_src_file(_, _AppDir, _AppSrcFile, valid) ->
try_handle_app_src_file(_, AppDir, [File], Validate) when Validate =:= invalid try_handle_app_src_file(_, AppDir, [File], Validate) when Validate =:= invalid
; Validate =:= all -> ; Validate =:= all ->
AppInfo = create_app_info(AppDir, File), AppInfo = create_app_info(AppDir, File),
case AppInfo of
{error, Reason} ->
throw({error, {invalid_app_file, File, Reason}});
case filename:extension(File) of
".script" ->
{true, rebar_app_info:app_file_src_script(AppInfo, File)};
_ -> _ ->
case filename:extension(File) of
".script" ->
{true, rebar_app_info:app_file_src_script(AppInfo, File)};
_ ->
{true, rebar_app_info:app_file_src(AppInfo, File)}
end
{true, rebar_app_info:app_file_src(AppInfo, File)}
end; end;
try_handle_app_src_file(_, _AppDir, Other, _Validate) -> try_handle_app_src_file(_, _AppDir, Other, _Validate) ->
throw({error, {multiple_app_files, Other}}). throw({error, {multiple_app_files, Other}}).

+ 2
- 2
src/rebar_core.erl Voir le fichier

@ -61,7 +61,7 @@ process_namespace(State, Command) ->
{ok, rebar_state:namespace(State, default), Command} {ok, rebar_state:namespace(State, default), Command}
end. end.
-spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()}.
-spec process_command(rebar_state:t(), atom()) -> {ok, rebar_state:t()} | {error, string()} | {error, {module(), any()}}.
process_command(State, Command) -> process_command(State, Command) ->
%% ? rebar_prv_install_deps:setup_env(State), %% ? rebar_prv_install_deps:setup_env(State),
Providers = rebar_state:providers(State), Providers = rebar_state:providers(State),
@ -103,7 +103,7 @@ process_command(State, Command) ->
end end
end. end.
-spec do([{atom(), atom()}], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
-spec do([{atom(), atom()}], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()} | {error, {module(), any()}}.
do([], State) -> do([], State) ->
{ok, State}; {ok, State};
do([ProviderName | Rest], State) -> do([ProviderName | Rest], State) ->

+ 1
- 1
src/rebar_prv_deps.erl Voir le fichier

@ -33,7 +33,7 @@ do(State) ->
true -> true ->
{_Packages, Graph} = rebar_state:packages(State), {_Packages, Graph} = rebar_state:packages(State),
List = merge_deps_per_profile(State), List = merge_deps_per_profile(State),
{_SrcDeps, PkgDeps} = rebar_prv_install_deps:parse_deps("", List, State, [], 0),
{_SrcDeps, PkgDeps} = rebar_prv_install_deps:parse_deps(<<"";>>;, List, State, [], 0),
rebar_digraph:print_solution(Graph, PkgDeps), rebar_digraph:print_solution(Graph, PkgDeps),
{ok, State}; {ok, State};
false -> false ->

+ 9
- 23
src/rebar_prv_install_deps.erl Voir le fichier

@ -289,7 +289,7 @@ package_to_app(DepsDir, Packages, {Name, Vsn, Level}, IsLock, State) ->
rebar_app_info:state(AppInfo1, AppState1) rebar_app_info:state(AppInfo1, AppState1)
end. end.
-spec update_src_deps(atom(), non_neg_integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary()), list()) -> {rebar_state:t(), list(), list(), sets:set(binary())}.
-spec update_src_deps(atom(), non_neg_integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary()), list()) -> {list(), list(), list(), rebar_state:t(), sets:set(binary()), list()}.
update_src_deps(Profile, Level, SrcDeps, PkgDeps, SrcApps, State, Upgrade, Seen, Locks) -> update_src_deps(Profile, Level, SrcDeps, PkgDeps, SrcApps, State, Upgrade, Seen, Locks) ->
lists:foldl( lists:foldl(
fun(AppInfo, {SrcDepsAcc, PkgDepsAcc, SrcAppsAcc, StateAcc, SeenAcc, LocksAcc}) -> fun(AppInfo, {SrcDepsAcc, PkgDepsAcc, SrcAppsAcc, StateAcc, SeenAcc, LocksAcc}) ->
@ -371,7 +371,7 @@ handle_dep(AppInfo, Profile, SrcDeps, PkgDeps, SrcApps, Level, State, Locks) ->
,NewLocks}. ,NewLocks}.
-spec handle_dep(rebar_state:t(), atom(), file:filename_all(), rebar_app_info:t(), list(), integer()) -> -spec handle_dep(rebar_state:t(), atom(), file:filename_all(), rebar_app_info:t(), list(), integer()) ->
{rebar_app_info:t(), [rebar_app_info:t()], [pkg_dep()], [integer()]}.
{rebar_app_info:t(), [rebar_app_info:t()], [pkg_dep()], [integer()], rebar_state:t()}.
handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) -> handle_dep(State, Profile, DepsDir, AppInfo, Locks, Level) ->
Profiles = rebar_state:current_profiles(State), Profiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo), Name = rebar_app_info:name(AppInfo),
@ -413,13 +413,9 @@ maybe_fetch(AppInfo, Profile, Upgrade, Seen, State) ->
false -> false ->
case rebar_app_discover:find_app(AppDir, all) of case rebar_app_discover:find_app(AppDir, all) of
false -> false ->
case fetch_app(AppInfo, AppDir, State) of
true ->
maybe_symlink_default(State, Profile, AppDir, AppInfo),
{true, update_app_info(AppDir, AppInfo)};
Other ->
{Other, AppInfo}
end;
true = fetch_app(AppInfo, AppDir, State),
maybe_symlink_default(State, Profile, AppDir, AppInfo),
{true, update_app_info(AppDir, AppInfo)};
{true, AppInfo1} -> {true, AppInfo1} ->
%% Preserve the state we created with overrides %% Preserve the state we created with overrides
AppState = rebar_app_info:state(AppInfo), AppState = rebar_app_info:state(AppInfo),
@ -477,7 +473,7 @@ make_relative_to_root(State, Path) when is_list(Path) ->
Root = rebar_dir:root_dir(State), Root = rebar_dir:root_dir(State),
rebar_dir:make_relative_path(Path, Root). rebar_dir:make_relative_path(Path, Root).
-spec parse_deps(binary(), list(), rebar_state:t(), list(), integer()) -> {[rebar_app_info:t()], [pkg_dep()]}.
-spec parse_deps(binary(), list(), rebar_state:t(), list(), integer()) -> {[rebar_app_info:t()], [tuple()]}.
parse_deps(DepsDir, Deps, State, Locks, Level) -> parse_deps(DepsDir, Deps, State, Locks, Level) ->
lists:foldl(fun(Dep, Acc) -> lists:foldl(fun(Dep, Acc) ->
Name = case Dep of Name = case Dep of
@ -575,12 +571,7 @@ new_dep(DepsDir, Name, Vsn, Source, IsLock, State) ->
fetch_app(AppInfo, AppDir, State) -> fetch_app(AppInfo, AppDir, State) ->
?INFO("Fetching ~s (~p)", [rebar_app_info:name(AppInfo), rebar_app_info:source(AppInfo)]), ?INFO("Fetching ~s (~p)", [rebar_app_info:name(AppInfo), rebar_app_info:source(AppInfo)]),
Source = rebar_app_info:source(AppInfo), Source = rebar_app_info:source(AppInfo),
case rebar_fetch:download_source(AppDir, Source, State) of
true ->
true;
Error ->
throw(Error)
end.
true = rebar_fetch:download_source(AppDir, Source, State).
%% This is called after the dep has been downloaded and unpacked, if it hadn't been already. %% This is called after the dep has been downloaded and unpacked, if it hadn't been already.
%% So this is the first time for newly downloaded apps that its .app/.app.src data can %% So this is the first time for newly downloaded apps that its .app/.app.src data can
@ -602,12 +593,7 @@ maybe_upgrade(AppInfo, AppDir, Upgrade, State) ->
case rebar_fetch:needs_update(AppDir, Source, State) of case rebar_fetch:needs_update(AppDir, Source, State) of
true -> true ->
?INFO("Upgrading ~s", [rebar_app_info:name(AppInfo)]), ?INFO("Upgrading ~s", [rebar_app_info:name(AppInfo)]),
case rebar_fetch:download_source(AppDir, Source, State) of
true ->
true;
Error ->
throw(Error)
end;
true = rebar_fetch:download_source(AppDir, Source, State);
false -> false ->
case Upgrade of case Upgrade of
true -> true ->
@ -621,7 +607,7 @@ maybe_upgrade(AppInfo, AppDir, Upgrade, State) ->
false false
end. end.
-spec parse_goal(binary(), binary()) -> pkg_dep().
-spec parse_goal(binary(), binary()) -> {binary(), binary()} | {binary(), binary(), binary()}.
parse_goal(Name, Constraint) -> parse_goal(Name, Constraint) ->
case re:run(Constraint, "([^\\d]*)(\\d.*)", [{capture, [1,2], binary}]) of case re:run(Constraint, "([^\\d]*)(\\d.*)", [{capture, [1,2], binary}]) of
{match, [<<>>, Vsn]} -> {match, [<<>>, Vsn]} ->

+ 3
- 7
src/rebar_prv_packages.erl Voir le fichier

@ -27,13 +27,9 @@ init(State) ->
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. -spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) -> do(State) ->
case rebar_packages:get_packages(State) of
{Dict, _} ->
print_packages(Dict),
{ok, State};
error ->
?PRV_ERROR(load_registry_fail)
end.
{Dict, _} = rebar_packages:get_packages(State),
print_packages(Dict),
{ok, State}.
-spec format_error(any()) -> iolist(). -spec format_error(any()) -> iolist().
format_error(load_registry_fail) -> format_error(load_registry_fail) ->

+ 1
- 1
src/rebar_prv_shell.erl Voir le fichier

@ -274,7 +274,7 @@ find_config_relx(State) ->
consult_config(State, Filename) consult_config(State, Filename)
end. end.
-spec consult_config(rebar_state:t(), string()) -> {ok, [tuple()]}|{error, tuple()}.
-spec consult_config(rebar_state:t(), string()) -> [tuple()].
consult_config(State, Filename) -> consult_config(State, Filename) ->
Fullpath = filename:join(rebar_dir:root_dir(State), Filename), Fullpath = filename:join(rebar_dir:root_dir(State), Filename),
?DEBUG("Loading configuration from ~p", [Fullpath]), ?DEBUG("Loading configuration from ~p", [Fullpath]),

+ 5
- 0
src/rebar_prv_update.erl Voir le fichier

@ -15,6 +15,10 @@
-define(PROVIDER, update). -define(PROVIDER, update).
-define(DEPS, []). -define(DEPS, []).
%% Ignore warning of digraph opqaque type when running dialyzer
-dialyzer({no_opaque, do/1}).
-dialyzer({no_opaque, write_registry/3}).
%% =================================================================== %% ===================================================================
%% Public API %% Public API
%% =================================================================== %% ===================================================================
@ -63,6 +67,7 @@ do(State) ->
format_error(package_index_write) -> format_error(package_index_write) ->
"Failed to write package index.". "Failed to write package index.".
-spec write_registry(rebar_dict(), {digraph, ets:tid(), ets:tid(), ets:tid(), any()}, rebar_state:t()) -> ok | {error, atom()}.
write_registry(Dict, {digraph, Edges, Vertices, Neighbors, _}, State) -> write_registry(Dict, {digraph, Edges, Vertices, Neighbors, _}, State) ->
RegistryDir = rebar_packages:package_dir(State), RegistryDir = rebar_packages:package_dir(State),
filelib:ensure_dir(filename:join(RegistryDir, "dummy")), filelib:ensure_dir(filename:join(RegistryDir, "dummy")),

+ 1
- 1
src/rebar_prv_xref.erl Voir le fichier

@ -88,7 +88,7 @@ desc() ->
" - (\"mod\":\".*foo\"/\"4\"))",[]}]} " - (\"mod\":\".*foo\"/\"4\"))",[]}]}
]). ]).
-spec prepare(rebar_state:t()) -> {[file:filename()], [atom()]}.
-spec prepare(rebar_state:t()) -> [atom()].
prepare(State) -> prepare(State) ->
{ok, _} = xref:start(xref), {ok, _} = xref:start(xref),
ok = xref:set_library_path(xref, code_path(State)), ok = xref:set_library_path(xref, code_path(State)),

+ 7
- 4
src/rebar_state.erl Voir le fichier

@ -171,7 +171,7 @@ default(State, Opts) ->
format_error({profile_not_list, Profile, Other}) -> format_error({profile_not_list, Profile, Other}) ->
io_lib:format("Profile config must be a list but for profile '~p' config given as:~n~p", [Profile, Other]). io_lib:format("Profile config must be a list but for profile '~p' config given as:~n~p", [Profile, Other]).
-spec has_all_artifacts(rebar_app_info:t()) -> true | providers:error().
-spec has_all_artifacts(#state_t{}) -> true | {false, file:filename()}.
has_all_artifacts(State) -> has_all_artifacts(State) ->
Artifacts = rebar_state:get(State, artifacts, []), Artifacts = rebar_state:get(State, artifacts, []),
Dir = rebar_dir:base_dir(State), Dir = rebar_dir:base_dir(State),
@ -188,6 +188,7 @@ all(Dir, [File|Artifacts]) ->
all(Dir, Artifacts) all(Dir, Artifacts)
end. end.
-spec code_paths(#state_t{}, atom()) -> [file:filename()].
code_paths(#state_t{code_paths=CodePaths}, Key) -> code_paths(#state_t{code_paths=CodePaths}, Key) ->
case dict:find(Key, CodePaths) of case dict:find(Key, CodePaths) of
{ok, CodePath} -> {ok, CodePath} ->
@ -196,9 +197,11 @@ code_paths(#state_t{code_paths=CodePaths}, Key) ->
[] []
end. end.
-spec code_paths(#state_t{}, atom(), [file:filename()]) -> #state_t{}.
code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) -> code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) ->
State#state_t{code_paths=dict:store(Key, CodePath, CodePaths)}. State#state_t{code_paths=dict:store(Key, CodePath, CodePaths)}.
-spec update_code_paths(#state_t{}, atom(), [file:filename()]) -> #state_t{}.
update_code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) -> update_code_paths(State=#state_t{code_paths=CodePaths}, Key, CodePath) ->
case dict:is_key(Key, CodePaths) of case dict:is_key(Key, CodePaths) of
true -> true ->
@ -451,15 +454,15 @@ registry(#state_t{registry=Registry}) ->
registry(State, Registry) -> registry(State, Registry) ->
State#state_t{registry=Registry}. State#state_t{registry=Registry}.
-spec resources(t()) -> rebar_resource:resource().
-spec resources(t()) -> [{rebar_resource:type(), module()}].
resources(#state_t{resources=Resources}) -> resources(#state_t{resources=Resources}) ->
Resources. Resources.
-spec resources(t(), [rebar_resource:resource()]) -> t().
-spec resources(t(), [{rebar_resource:type(), module()}]) -> t().
resources(State, NewResources) -> resources(State, NewResources) ->
State#state_t{resources=NewResources}. State#state_t{resources=NewResources}.
-spec add_resource(t(), rebar_resource:resource()) -> t().
-spec add_resource(t(), {rebar_resource:type(), module()}) -> t().
add_resource(State=#state_t{resources=Resources}, Resource) -> add_resource(State=#state_t{resources=Resources}, Resource) ->
State#state_t{resources=[Resource | Resources]}. State#state_t{resources=[Resource | Resources]}.

+ 1
- 1
src/rebar_utils.erl Voir le fichier

@ -683,7 +683,7 @@ update_code(Paths) ->
code:add_patha(Path), code:add_patha(Path),
ok; ok;
{ok, Modules} -> {ok, Modules} ->
code:replace_path(Name, Path),
code:replace_path(App, Path),
[begin code:purge(M), code:delete(M) end || M <- Modules] [begin code:purge(M), code:delete(M) end || M <- Modules]
end end
end, Paths). end, Paths).

Chargement…
Annuler
Enregistrer