diff options
author | Tristan Sloughter <t@crashfast.com> | 2014-11-30 21:12:02 -0600 |
---|---|---|
committer | Tristan Sloughter <t@crashfast.com> | 2014-11-30 21:12:02 -0600 |
commit | 5673fe035da48d48d0824bf7260bfda28c55c9d5 (patch) | |
tree | 1562523264f5da72ccee6eb4624afca8aa69f7cb | |
parent | c4ee53c8bc8170a9340c540c341ad403c91c0218 (diff) |
fixes for dialyzer findings
-rw-r--r-- | src/rebar_core.erl | 2 | ||||
-rw-r--r-- | src/rebar_fetch.erl | 43 | ||||
-rw-r--r-- | src/rebar_git_resource.erl | 7 | ||||
-rw-r--r-- | src/rebar_plugins.erl | 1 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 15 | ||||
-rw-r--r-- | src/rebar_prv_upgrade.erl | 10 | ||||
-rw-r--r-- | src/rebar_resource.erl | 2 | ||||
-rw-r--r-- | src/rebar_utils.erl | 26 |
8 files changed, 43 insertions, 63 deletions
diff --git a/src/rebar_core.erl b/src/rebar_core.erl index a79414a..2396294 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -57,7 +57,7 @@ process_command(State, Command) -> end end. --spec do([atom()], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. +-spec do([{atom(), atom()}], rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}. do([], State) -> {ok, State}; do([{ProviderName, Profile} | Rest], State) -> diff --git a/src/rebar_fetch.erl b/src/rebar_fetch.erl index 933b626..2df892c 100644 --- a/src/rebar_fetch.erl +++ b/src/rebar_fetch.erl @@ -24,25 +24,30 @@ lock_source(AppDir, Source) -> -spec download_source(file:filename_all(), rebar_resource:resource()) -> true | {error, any()}. download_source(AppDir, Source) -> - Module = get_resource_type(Source), - TmpDir = ec_file:insecure_mkdtemp(), - AppDir1 = ec_cnv:to_list(AppDir), - ec_file:mkdir_p(AppDir1), - case Module:download(TmpDir, Source) of - {ok, _} -> - code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), - ec_file:remove(filename:absname(AppDir1), [recursive]), - ok = ec_file:copy(TmpDir, filename:absname(AppDir1), [recursive]), - true; - {tarball, File} -> - ok = erl_tar:extract(File, [{cwd, TmpDir} - ,compressed]), - BaseName = filename:basename(AppDir1), - [FromDir] = filelib:wildcard(filename:join(TmpDir, BaseName++"-*")), - code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), - ec_file:remove(filename:absname(AppDir1), [recursive]), - ok = ec_file:copy(FromDir, filename:absname(AppDir1), [recursive]), - true + try + Module = get_resource_type(Source), + TmpDir = ec_file:insecure_mkdtemp(), + AppDir1 = ec_cnv:to_list(AppDir), + ec_file:mkdir_p(AppDir1), + case Module:download(TmpDir, Source) of + {ok, _} -> + code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), + ec_file:remove(filename:absname(AppDir1), [recursive]), + ok = ec_file:copy(TmpDir, filename:absname(AppDir1), [recursive]), + true; + {tarball, File} -> + ok = erl_tar:extract(File, [{cwd, TmpDir} + ,compressed]), + BaseName = filename:basename(AppDir1), + [FromDir] = filelib:wildcard(filename:join(TmpDir, BaseName++"-*")), + code:del_path(filename:absname(filename:join(AppDir1, "ebin"))), + ec_file:remove(filename:absname(AppDir1), [recursive]), + ok = ec_file:copy(FromDir, filename:absname(AppDir1), [recursive]), + true + end + catch + _:E -> + {error, E} end. -spec needs_update(file:filename_all(), rebar_resource:resource()) -> boolean() | {error, string()}. diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index bcd2374..4edaa48 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -126,12 +126,7 @@ collect_default_refcount() -> build_vsn_string(Vsn, RawRef, RawCount) -> %% Cleanup the tag and the Ref information. Basically leading 'v's and %% whitespace needs to go away. - RefTag = case RawRef of - undefined -> - ""; - RawRef -> - [".ref", re:replace(RawRef, "\\s", "", [global])] - end, + RefTag = [".ref", re:replace(RawRef, "\\s", "", [global])], Count = erlang:iolist_to_binary(re:replace(RawCount, "\\s", "", [global])), %% Create the valid [semver](http://semver.org) version from the tag diff --git a/src/rebar_plugins.erl b/src/rebar_plugins.erl index b6bf39b..990170d 100644 --- a/src/rebar_plugins.erl +++ b/src/rebar_plugins.erl @@ -25,6 +25,7 @@ install(State) -> State2 = rebar_state:set(State1, deps_dir, OldDepsDir), {ok, PluginProviders, State2}. +-spec handle_plugin(rebar_prv_install_deps:dep(), rebar_state:t()) -> {true, any()} | false. handle_plugin(Plugin, State) -> try {ok, _, State1} = rebar_prv_install_deps:handle_deps(State, [Plugin]), diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index d87a893..d5f4b69 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -37,6 +37,8 @@ -export([handle_deps/2, handle_deps/3]). +-export_type([dep/0]). + -define(PROVIDER, install_deps). -define(DEPS, [app_discovery]). @@ -91,12 +93,12 @@ do(State) -> format_error(Reason) -> io_lib:format("~p", [Reason]). --spec handle_deps(rebar_state:t(), [dep()]) -> +-spec handle_deps(rebar_state:t(), list()) -> {ok, [rebar_app_info:t()], rebar_state:t()} | {error, string()}. handle_deps(State, Deps) -> handle_deps(State, Deps, false). --spec handle_deps(rebar_state:t(), [dep()], boolean() | {true, binary(), integer()}) +-spec handle_deps(rebar_state:t(), list(), boolean() | {true, binary(), integer()}) -> {ok, [rebar_app_info:t()], rebar_state:t()} | {error, string()}. handle_deps(State, [], _) -> {ok, [], State}; @@ -121,9 +123,7 @@ handle_deps(State, Deps, Update) -> {ok, []} -> throw({rebar_digraph, no_solution}); {ok, Solution} -> - Solution; - [] -> - throw({rebar_digraph, no_solution}) + Solution end, update_pkg_deps(S, Packages, Update, Seen, State1) @@ -182,8 +182,7 @@ package_to_app(DepsDir, Packages, {Name, Vsn}) -> rebar_app_info:source(AppInfo2, {pkg, Name, Vsn, Link}) end. --spec update_src_deps(integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary())) -> - {rebar_state:t(), [binary()]}. +-spec update_src_deps(non_neg_integer(), list(), list(), list(), rebar_state:t(), boolean(), sets:set(binary())) -> {rebar_state:t(), list(), list(), sets:set(binary())}. update_src_deps(Level, SrcDeps, PkgDeps, SrcApps, State, Update, Seen) -> case lists:foldl(fun(AppInfo, {SrcDepsAcc, PkgDepsAcc, SrcAppsAcc, StateAcc, SeenAcc}) -> %% If not seen, add to list of locks to write out @@ -323,7 +322,7 @@ maybe_fetch(State, AppInfo, Update, Seen) -> end end. --spec parse_deps(rebar_state:t(), binary(), [dep()]) -> {[rebar_app_info:t()], [pkg_dep()]}. +-spec parse_deps(rebar_state:t(), binary(), list()) -> {[rebar_app_info:t()], [pkg_dep()]}. parse_deps(State, DepsDir, Deps) -> lists:foldl(fun({Name, Vsn}, {SrcDepsAcc, PkgDepsAcc}) -> {SrcDepsAcc, [parse_goal(ec_cnv:to_binary(Name) diff --git a/src/rebar_prv_upgrade.erl b/src/rebar_prv_upgrade.erl index 8b18f5e..c0a56c3 100644 --- a/src/rebar_prv_upgrade.erl +++ b/src/rebar_prv_upgrade.erl @@ -42,9 +42,13 @@ do(State) -> case lists:keyfind(Name, 1, Locks) of {_, _, _, Level} -> Deps = rebar_state:get(State, deps), - Dep = lists:keyfind(binary_to_atom(Name, utf8), 1, Deps), - rebar_prv_install_deps:handle_deps(State, [Dep], {true, Name, Level}), - {ok, State}; + case lists:keyfind(binary_to_atom(Name, utf8), 1, Deps) of + false -> + {error, io_lib:format("No such dependency ~s~n", [Name])}; + Dep -> + rebar_prv_install_deps:handle_deps(State, [Dep], {true, Name, Level}), + {ok, State} + end; _ -> {error, io_lib:format("No such dependency ~s~n", [Name])} end. diff --git a/src/rebar_resource.erl b/src/rebar_resource.erl index ee7d2d3..2bc28e2 100644 --- a/src/rebar_resource.erl +++ b/src/rebar_resource.erl @@ -36,7 +36,7 @@ behaviour_info(_) -> -callback download(file:filename_all(), tuple()) -> {tarball, file:filename_all()} | {ok, any()} | {error, any()}. -callback needs_update(file:filename_all(), tuple()) -> - {tarball, file:filename_all()} | {ok, any()} | {error, any()}. + boolean(). -callback make_vsn(file:filename_all()) -> {plain, string()} | {error, string()}. diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index c84dcf2..a6c9162 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -528,31 +528,7 @@ vcs_vsn_1(Vcs, Dir) -> unknown -> ?ABORT("vcs_vsn: Unknown vsn format: ~p\n", [Vcs]); {error, Reason} -> - ?ABORT("vcs_vsn: ~s\n", [Reason]); - Cmd -> - %% If there is a valid VCS directory in the application directory, - %% use that version info - Extension = lists:concat([".", Vcs]), - case filelib:is_dir(filename:join(Dir, Extension)) of - true -> - ?DEBUG("vcs_vsn: Primary vcs used for ~s\n", [Dir]), - vcs_vsn_invoke(Cmd, Dir); - false -> - %% No VCS directory found for the app. Depending on source - %% tree structure, there may be one higher up, but that can - %% yield unexpected results when used with deps. So, we - %% fallback to searching for a priv/vsn.Vcs file. - VsnFile = filename:join([Dir, "priv", "vsn" ++ Extension]), - case file:read_file(VsnFile) of - {ok, VsnBin} -> - ?DEBUG("vcs_vsn: Read ~s from priv/vsn.~p\n", - [VsnBin, Vcs]), - string:strip(binary_to_list(VsnBin), right, $\n); - {error, enoent} -> - ?DEBUG("vcs_vsn: Fallback to vcs for ~s\n", [Dir]), - vcs_vsn_invoke(Cmd, Dir) - end - end + ?ABORT("vcs_vsn: ~s\n", [Reason]) end. %% Temp work around for repos like relx that use "semver" |