summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--priv/templates/otp_app.app.src20
-rw-r--r--priv/templates/otp_lib.app.src16
-rw-r--r--rebar.config.sample31
-rw-r--r--src/rebar3.erl54
-rw-r--r--src/rebar_base_compiler.erl33
-rw-r--r--src/rebar_prv_dialyzer.erl250
-rw-r--r--src/rebar_prv_install_deps.erl13
-rw-r--r--src/rebar_prv_xref.erl10
9 files changed, 244 insertions, 184 deletions
diff --git a/.gitignore b/.gitignore
index c84f451..bd0314f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@ logs
/.rebar
priv/templates/*.dtl.erl
ebin
+.edts
diff --git a/priv/templates/otp_app.app.src b/priv/templates/otp_app.app.src
index 5188f56..d5ea3d2 100644
--- a/priv/templates/otp_app.app.src
+++ b/priv/templates/otp_app.app.src
@@ -1,12 +1,12 @@
{application, {{name}},
- [{description, "{{desc}}"}
- ,{vsn, "0.1.0"}
- ,{registered, []}
- ,{mod, {'{{name}}_app', []}}
- ,{applications,
- [kernel
- ,stdlib
- ]}
- ,{env,[]}
- ,{modules, []}
+ [{description, "{{desc}}"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {mod, {'{{name}}_app', []}},
+ {applications,
+ [kernel,
+ stdlib
+ ]},
+ {env,[]},
+ {modules, []}
]}.
diff --git a/priv/templates/otp_lib.app.src b/priv/templates/otp_lib.app.src
index 3adefeb..6af7640 100644
--- a/priv/templates/otp_lib.app.src
+++ b/priv/templates/otp_lib.app.src
@@ -1,9 +1,11 @@
{application, {{name}},
- [{description, "{{desc}}"}
- ,{vsn, "0.1.0"}
- ,{registered, []}
- ,{applications,
- [kernel,stdlib]}
- ,{env,[]}
- ,{modules, []}
+ [{description, "{{desc}}"},
+ {vsn, "0.1.0"},
+ {registered, []},
+ {applications,
+ [kernel,
+ stdlib
+ ]},
+ {env,[]},
+ {modules, []}
]}.
diff --git a/rebar.config.sample b/rebar.config.sample
index aae692b..10d277e 100644
--- a/rebar.config.sample
+++ b/rebar.config.sample
@@ -62,9 +62,20 @@
%% Additional compile options for eunit. erl_opts is also used
{eunit_compile_opts, []}.
-%% Same as erl_first_files, but used only when running 'eunit'
+%% Files to compile first when compiling eunit test suites
{eunit_first_files, []}.
+%% == Common Test ==
+
+%% Options to pass to ct:run_test/1
+{ct_opts, [{logdir, "logs"}, {dir, "test"}]}.
+
+%% Additional compile options for ct. erl_opts is also used
+{ct_compile_opts, []}.
+
+%% Files to compile first when compiling ct test suites
+{ct_first_files, []}.
+
%% == Cover ==
%% Whether to enable coverage reporting. Default is `false'
@@ -73,22 +84,8 @@
%% Whether to print coverage report to console. Default is `false'
{cover_print_enabled, false}.
-%% Whether to export coverage report to file. Default is `false'
-{cover_export_enabled, false}.
-
-%% == Common Test ==
-
-%% Override the default "test" directory in which SUITEs are located
-{ct_dir, "itest"}.
-
-%% Override the default "logs" directory in which SUITEs are logged
-{ct_log_dir, "test/logs"}.
-
-%% Option to pass extra parameters when launching Common Test
-{ct_extra_params, "-boot start_sasl -s myapp"}.
-
-%% Option to use short names (i.e., -sname test) when starting ct
-{ct_use_short_names, true}.
+%% Directory to store collected cover data
+{cover_data_dir, "cover"}.
%% What dependencies we have, dependencies can be of 3 forms, an application
%% name as an atom, eg. mochiweb, a name and a version (from the .app file), or
diff --git a/src/rebar3.erl b/src/rebar3.erl
index 92803c5..1a02407 100644
--- a/src/rebar3.erl
+++ b/src/rebar3.erl
@@ -44,33 +44,14 @@
%% escript Entry point
main(Args) ->
- case catch(run(Args)) of
+ try run(Args) of
{ok, _State} ->
erlang:halt(0);
- rebar_abort ->
- erlang:halt(1);
- {error, rebar_abort} ->
- erlang:halt(1);
- {error, {Module, Reason}} ->
- case code:which(Module) of
- non_existing ->
- ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
- ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]),
- ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []);
- _ ->
- ?ERROR(Module:format_error(Reason), [])
- end,
- erlang:halt(1);
- {error, Error} when is_list(Error) ->
- ?ERROR(Error, []),
- erlang:halt(1);
Error ->
- %% Nothing should percolate up from rebar_core;
- %% Dump this error to console
- ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
- ?DEBUG("Uncaught error: ~p", [Error]),
- ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []),
- erlang:halt(1)
+ handle_error(Error)
+ catch
+ _:Error ->
+ handle_error(Error)
end.
%% Erlang-API entry point
@@ -251,3 +232,28 @@ global_option_spec_list() ->
%{config, $C, "config", string, "Rebar config file to use."},
{task, undefined, undefined, string, "Task to run."}
].
+
+handle_error(rebar_abort) ->
+ erlang:halt(1);
+handle_error({error, rebar_abort}) ->
+ erlang:halt(1);
+handle_error({error, {Module, Reason}}) ->
+ case code:which(Module) of
+ non_existing ->
+ ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
+ ?DEBUG("Uncaught error: ~p ~p", [Module, Reason]),
+ ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []);
+ _ ->
+ ?ERROR(Module:format_error(Reason), [])
+ end,
+ erlang:halt(1);
+handle_error({error, Error}) when is_list(Error) ->
+ ?ERROR(Error, []),
+ erlang:halt(1);
+handle_error(Error) ->
+ %% Nothing should percolate up from rebar_core;
+ %% Dump this error to console
+ ?ERROR("Uncaught error in rebar_core. Run with DEBUG=1 to see stacktrace", []),
+ ?DEBUG("Uncaught error: ~p", [Error]),
+ ?INFO("When submitting a bug report, please include the output of `rebar3 report \"your command\"`", []),
+ erlang:halt(1).
diff --git a/src/rebar_base_compiler.erl b/src/rebar_base_compiler.erl
index 0101218..7193003 100644
--- a/src/rebar_base_compiler.erl
+++ b/src/rebar_base_compiler.erl
@@ -69,12 +69,12 @@ run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt,
simple_compile_wrapper(S, Target, Compile3Fn, C, CheckLastMod)
end).
-ok_tuple(Config, Source, Ws) ->
- {ok, format_warnings(Config, Source, Ws)}.
+ok_tuple(_Config, Source, Ws) ->
+ {ok, format_warnings(Source, Ws)}.
-error_tuple(Config, Source, Es, Ws, Opts) ->
- {error, format_errors(Config, Source, Es),
- format_warnings(Config, Source, Ws, Opts)}.
+error_tuple(_Config, Source, Es, Ws, Opts) ->
+ {error, format_errors(Source, Es),
+ format_warnings(Source, Ws, Opts)}.
%% ===================================================================
%% Internal functions
@@ -114,26 +114,25 @@ compile_each([Source | Rest], Config, CompileFn) ->
skipped ->
?DEBUG("~sSkipped ~s", [rebar_utils:indent(1), filename:basename(Source)]);
Error ->
- ?ERROR("Compiling ~s failed",
- [maybe_absname(Config, Source)]),
+ ?ERROR("Compiling ~s failed", [Source]),
maybe_report(Error),
?DEBUG("Compilation failed: ~p", [Error]),
?FAIL
end,
compile_each(Rest, Config, CompileFn).
-format_errors(Config, Source, Errors) ->
- format_errors(Config, Source, "", Errors).
+format_errors(Source, Errors) ->
+ format_errors(Source, "", Errors).
-format_warnings(Config, Source, Warnings) ->
- format_warnings(Config, Source, Warnings, []).
+format_warnings(Source, Warnings) ->
+ format_warnings(Source, Warnings, []).
-format_warnings(Config, Source, Warnings, Opts) ->
+format_warnings(Source, Warnings, Opts) ->
Prefix = case lists:member(warnings_as_errors, Opts) of
true -> "";
false -> "Warning: "
end,
- format_errors(Config, Source, Prefix, Warnings).
+ format_errors(Source, Prefix, Warnings).
maybe_report({{error, {error, _Es, _Ws}=ErrorsAndWarnings}, {source, _}}) ->
maybe_report(ErrorsAndWarnings);
@@ -148,10 +147,9 @@ maybe_report(_) ->
report(Messages) ->
lists:foreach(fun(Msg) -> io:format("~s~n", [Msg]) end, Messages).
-format_errors(Config, _MainSource, Extra, Errors) ->
+format_errors(_MainSource, Extra, Errors) ->
[begin
- AbsSource = maybe_absname(Config, Source),
- [format_error(AbsSource, Extra, Desc) || Desc <- Descs]
+ [format_error(Source, Extra, Desc) || Desc <- Descs]
end
|| {Source, Descs} <- Errors].
@@ -164,6 +162,3 @@ format_error(AbsSource, Extra, {Line, Mod, Desc}) ->
format_error(AbsSource, Extra, {Mod, Desc}) ->
ErrorDesc = Mod:format_error(Desc),
?FMT("~s: ~s~s~n", [AbsSource, Extra, ErrorDesc]).
-
-maybe_absname(_Config, Filename) ->
- Filename.
diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl
index 67cf4b9..96e2277 100644
--- a/src/rebar_prv_dialyzer.erl
+++ b/src/rebar_prv_dialyzer.erl
@@ -66,15 +66,16 @@ do(State) ->
?INFO("Dialyzer starting, this may take a while...", []),
code:add_pathsa(rebar_state:code_paths(State, all_deps)),
Plt = get_plt_location(State),
- Apps = rebar_state:project_apps(State),
try
- do(State, Plt, Apps)
+ do(State, Plt)
catch
throw:{dialyzer_error, Error} ->
?PRV_ERROR({error_processing_apps, Error});
throw:{dialyzer_warnings, Warnings} ->
- ?PRV_ERROR({dialyzer_warnings, Warnings})
+ ?PRV_ERROR({dialyzer_warnings, Warnings});
+ throw:{output_file_error, _, _} = Error ->
+ ?PRV_ERROR(Error)
after
rebar_utils:cleanup_code_path(rebar_state:code_paths(State, default))
end.
@@ -84,6 +85,9 @@ format_error({error_processing_apps, Error}) ->
io_lib:format("Error in dialyzing apps: ~s", [Error]);
format_error({dialyzer_warnings, Warnings}) ->
io_lib:format("Warnings occured running dialyzer: ~b", [Warnings]);
+format_error({output_file_error, File, Error}) ->
+ Error1 = file:format_error(Error),
+ io_lib:format("Failed to write to ~s: ~s", [File, Error1]);
format_error(Reason) ->
io_lib:format("~p", [Reason]).
@@ -97,41 +101,61 @@ get_plt_location(State) ->
default_plt() ->
rebar_utils:otp_release() ++ ".plt".
-do(State, Plt, Apps) ->
- {PltWarnings, State1} = update_proj_plt(State, Plt, Apps),
- {Warnings, State2} = succ_typings(State1, Plt, Apps),
+do(State, Plt) ->
+ Output = get_output_file(State),
+ {PltWarnings, State1} = update_proj_plt(State, Plt, Output),
+ {Warnings, State2} = succ_typings(State1, Plt, Output),
case PltWarnings + Warnings of
0 ->
{ok, State2};
TotalWarnings ->
+ ?INFO("Warnings written to ~s", [Output]),
throw({dialyzer_warnings, TotalWarnings})
end.
-update_proj_plt(State, Plt, Apps) ->
+get_output_file(State) ->
+ BaseDir = rebar_dir:base_dir(State),
+ Output = filename:join(BaseDir, default_output_file()),
+ case file:open(Output, [write]) of
+ {ok, File} ->
+ ok = file:close(File),
+ Output;
+ {error, Reason} ->
+ throw({output_file_error, Output, Reason})
+ end.
+
+default_output_file() ->
+ rebar_utils:otp_release() ++ ".dialyzer_warnings".
+
+update_proj_plt(State, Plt, Output) ->
{Args, _} = rebar_state:command_parsed_args(State),
case proplists:get_value(update_plt, Args) of
false ->
{0, State};
_ ->
- do_update_proj_plt(State, Plt, Apps)
+ do_update_proj_plt(State, Plt, Output)
end.
-do_update_proj_plt(State, Plt, Apps) ->
+do_update_proj_plt(State, Plt, Output) ->
?INFO("Updating plt...", []),
- Files = get_plt_files(State, Apps),
- case read_plt(State, Plt) of
- {ok, OldFiles} ->
- check_plt(State, Plt, OldFiles, Files);
- {error, no_such_file} ->
- build_proj_plt(State, Plt, Files)
- end.
-
-get_plt_files(State, Apps) ->
+ {Files, Warnings} = proj_plt_files(State),
+ Warnings2 = format_warnings(Output, Warnings),
+ {Warnings3, State2} = case read_plt(State, Plt) of
+ {ok, OldFiles} ->
+ check_plt(State, Plt, Output, OldFiles,
+ Files);
+ {error, no_such_file} ->
+ build_proj_plt(State, Plt, Output, Files)
+ end,
+ {Warnings2 + Warnings3, State2}.
+
+proj_plt_files(State) ->
BasePltApps = rebar_state:get(State, dialyzer_base_plt_apps,
default_plt_apps()),
PltApps = rebar_state:get(State, dialyzer_plt_apps, []),
+ Apps = rebar_state:project_apps(State),
DepApps = lists:flatmap(fun rebar_app_info:applications/1, Apps),
- get_plt_files(BasePltApps ++ PltApps ++ DepApps, Apps, [], []).
+ get_plt_files(BasePltApps ++ PltApps ++ DepApps, Apps).
default_plt_apps() ->
[erts,
@@ -139,19 +163,25 @@ default_plt_apps() ->
kernel,
stdlib].
-get_plt_files([], _, _, Files) ->
- Files;
-get_plt_files([AppName | DepApps], Apps, PltApps, Files) ->
+get_plt_files(DepApps, Apps) ->
+ ?INFO("Resolving files...", []),
+ get_plt_files(DepApps, Apps, [], [], []).
+
+get_plt_files([], _, _, Files, Warnings) ->
+ {Files, Warnings};
+get_plt_files([AppName | DepApps], Apps, PltApps, Files, Warnings) ->
case lists:member(AppName, PltApps) orelse app_member(AppName, Apps) of
true ->
- get_plt_files(DepApps, Apps, PltApps, Files);
+ get_plt_files(DepApps, Apps, PltApps, Files, Warnings);
false ->
- {DepApps2, Files2} = app_name_to_info(AppName),
+ {DepApps2, Files2, Warnings2} = app_name_to_info(AppName),
?DEBUG("~s dependencies: ~p", [AppName, DepApps2]),
?DEBUG("~s files: ~p", [AppName, Files2]),
DepApps3 = DepApps2 ++ DepApps,
+ PltApps2 = [AppName | PltApps],
Files3 = Files2 ++ Files,
- get_plt_files(DepApps3, Apps, [AppName | PltApps], Files3)
+ Warnings3 = Warnings2 ++ Warnings,
+ get_plt_files(DepApps3, Apps, PltApps2, Files3, Warnings3)
end.
app_member(AppName, Apps) ->
@@ -165,8 +195,7 @@ app_member(AppName, Apps) ->
app_name_to_info(AppName) ->
case app_name_to_ebin(AppName) of
{error, _} ->
- ?CONSOLE("Unknown application ~s", [AppName]),
- {[], []};
+ {[], [], [{unknown_application, {"", 0}, [AppName]}]};
EbinDir ->
ebin_to_info(EbinDir, AppName)
end.
@@ -204,10 +233,10 @@ ebin_to_info(EbinDir, AppName) ->
IncApps = proplists:get_value(included_applications, AppDetails,
[]),
Modules = proplists:get_value(modules, AppDetails, []),
- Files = modules_to_files(Modules, EbinDir),
- {IncApps ++ DepApps, Files};
+ {Files, Warnings} = modules_to_files(Modules, EbinDir),
+ {IncApps ++ DepApps, Files, Warnings};
{error, enoent} when AppName =:= erts ->
- {[], ebin_files(EbinDir)};
+ {[], ebin_files(EbinDir), []};
_ ->
Error = io_lib:format("Could not parse ~p", [AppFile]),
throw({dialyzer_error, Error})
@@ -215,17 +244,19 @@ ebin_to_info(EbinDir, AppName) ->
modules_to_files(Modules, EbinDir) ->
Ext = code:objfile_extension(),
- Mod2File = fun(Module) -> module_to_file(Module, EbinDir, Ext) end,
- rebar_utils:filtermap(Mod2File, Modules).
+ Result = [module_to_file(Module, EbinDir, Ext) || Module <- Modules],
+ Files = [File || {_, File} <- Result, File =/= unknown],
+ Warnings = [{unknown_module, {"", 0}, [Module]} ||
+ {Module, unknown} <- Result],
+ {Files, Warnings}.
module_to_file(Module, EbinDir, Ext) ->
File = filename:join(EbinDir, atom_to_list(Module) ++ Ext),
case filelib:is_file(File) of
true ->
- {true, File};
+ {Module, File};
false ->
- ?CONSOLE("Unknown module ~s", [Module]),
- false
+ {Module, unknown}
end.
ebin_files(EbinDir) ->
@@ -245,54 +276,58 @@ read_plt(_State, Plt) ->
throw({dialyzer_error, Error})
end.
-check_plt(State, Plt, OldList, FilesList) ->
+check_plt(State, Plt, Output, OldList, FilesList) ->
Old = sets:from_list(OldList),
Files = sets:from_list(FilesList),
- Remove = sets:subtract(Old, Files),
- {RemWarnings, State1} = remove_plt(State, Plt, sets:to_list(Remove)),
- Check = sets:intersection(Files, Old),
- {CheckWarnings, State2} = check_plt(State1, Plt, sets:to_list(Check)),
- Add = sets:subtract(Files, Old),
- {AddWarnings, State3} = add_plt(State2, Plt, sets:to_list(Add)),
+ Remove = sets:to_list(sets:subtract(Old, Files)),
+ {RemWarnings, State1} = remove_plt(State, Plt, Output, Remove),
+ Check = sets:to_list(sets:intersection(Files, Old)),
+ {CheckWarnings, State2} = check_plt(State1, Plt, Output, Check),
+ Add = sets:to_list(sets:subtract(Files, Old)),
+ {AddWarnings, State3} = add_plt(State2, Plt, Output, Add),
{RemWarnings + CheckWarnings + AddWarnings, State3}.
-remove_plt(State, _Plt, []) ->
+remove_plt(State, _Plt, _Output, []) ->
{0, State};
-remove_plt(State, Plt, Files) ->
+remove_plt(State, Plt, Output, Files) ->
?INFO("Removing ~b files from ~p...", [length(Files), Plt]),
- run_plt(State, Plt, plt_remove, Files).
+ run_plt(State, Plt, Output, plt_remove, Files).
-check_plt(State, _Plt, []) ->
+check_plt(State, _Plt, _Output, []) ->
{0, State};
-check_plt(State, Plt, Files) ->
+check_plt(State, Plt, Output, Files) ->
?INFO("Checking ~b files in ~p...", [length(Files), Plt]),
- run_plt(State, Plt, plt_check, Files).
+ run_plt(State, Plt, Output, plt_check, Files).
-add_plt(State, _Plt, []) ->
+add_plt(State, _Plt, _Output, []) ->
{0, State};
-add_plt(State, Plt, Files) ->
+add_plt(State, Plt, Output, Files) ->
?INFO("Adding ~b files to ~p...", [length(Files), Plt]),
- run_plt(State, Plt, plt_add, Files).
+ run_plt(State, Plt, Output, plt_add, Files).
-run_plt(State, Plt, Analysis, Files) ->
+run_plt(State, Plt, Output, Analysis, Files) ->
GetWarnings = rebar_state:get(State, dialyzer_plt_warnings, false),
Opts = [{analysis_type, Analysis},
{get_warnings, GetWarnings},
{init_plt, Plt},
{from, byte_code},
{files, Files}],
- run_dialyzer(State, Opts).
+ run_dialyzer(State, Opts, Output).
-build_proj_plt(State, Plt, Files) ->
+build_proj_plt(State, Plt, Output, Files) ->
BasePlt = get_base_plt_location(State),
- BaseFiles = get_base_plt_files(State),
- {BaseWarnings, State1} = update_base_plt(State, BasePlt, BaseFiles),
+ ?INFO("Updating base plt...", []),
+ {BaseFiles, BaseWarnings} = base_plt_files(State),
+ BaseWarnings2 = format_warnings(Output, BaseWarnings),
+ {BaseWarnings3, State1} = update_base_plt(State, BasePlt, Output,
+ BaseFiles),
?INFO("Copying ~p to ~p...", [BasePlt, Plt]),
_ = filelib:ensure_dir(Plt),
case file:copy(BasePlt, Plt) of
{ok, _} ->
- {CheckWarnings, State2} = check_plt(State1, Plt, BaseFiles, Files),
- {BaseWarnings + CheckWarnings, State2};
+ {CheckWarnings, State2} = check_plt(State1, Plt, Output, BaseFiles,
+ Files),
+ {BaseWarnings2 + BaseWarnings3 + CheckWarnings, State2};
{error, Reason} ->
Error = io_lib:format("Could not copy PLT from ~p to ~p: ~p",
[BasePlt, Plt, file:format_error(Reason)]),
@@ -305,66 +340,68 @@ get_base_plt_location(State) ->
BasePlt = rebar_state:get(State, dialyzer_base_plt, default_plt()),
filename:join(BaseDir, BasePlt).
-get_base_plt_files(State) ->
+base_plt_files(State) ->
BasePltApps = rebar_state:get(State, dialyzer_base_plt_apps,
default_plt_apps()),
- app_names_to_files(BasePltApps).
-
-app_names_to_files(AppNames) ->
- ToFiles = fun(AppName) ->
- {_, Files} = app_name_to_info(AppName),
- Files
- end,
- lists:flatmap(ToFiles, AppNames).
+ Apps = rebar_state:project_apps(State),
+ get_plt_files(BasePltApps, Apps).
-update_base_plt(State, BasePlt, BaseFiles) ->
- ?INFO("Updating base plt...", []),
+update_base_plt(State, BasePlt, Output, BaseFiles) ->
case read_plt(State, BasePlt) of
{ok, OldBaseFiles} ->
- check_plt(State, BasePlt, OldBaseFiles, BaseFiles);
+ check_plt(State, BasePlt, Output, OldBaseFiles, BaseFiles);
{error, no_such_file} ->
_ = filelib:ensure_dir(BasePlt),
- build_plt(State, BasePlt, BaseFiles)
+ build_plt(State, BasePlt, Output, BaseFiles)
end.
-build_plt(State, Plt, Files) ->
+build_plt(State, Plt, Output, Files) ->
?INFO("Adding ~b files to ~p...", [length(Files), Plt]),
GetWarnings = rebar_state:get(State, dialyzer_plt_warnings, false),
Opts = [{analysis_type, plt_build},
{get_warnings, GetWarnings},
{output_plt, Plt},
{files, Files}],
- run_dialyzer(State, Opts).
+ run_dialyzer(State, Opts, Output).
-succ_typings(State, Plt, Apps) ->
+succ_typings(State, Plt, Output) ->
{Args, _} = rebar_state:command_parsed_args(State),
case proplists:get_value(succ_typings, Args) of
false ->
{0, State};
_ ->
- do_succ_typings(State, Plt, Apps)
+ Apps = rebar_state:project_apps(State),
+ succ_typings(State, Plt, Output, Apps)
end.
-do_succ_typings(State, Plt, Apps) ->
+succ_typings(State, Plt, Output, Apps) ->
?INFO("Doing success typing analysis...", []),
- Files = apps_to_files(Apps),
+ {Files, Warnings} = apps_to_files(Apps),
+ Warnings2 = format_warnings(Output, Warnings),
?INFO("Analyzing ~b files with ~p...", [length(Files), Plt]),
Opts = [{analysis_type, succ_typings},
{get_warnings, true},
{from, byte_code},
{files, Files},
{init_plt, Plt}],
- run_dialyzer(State, Opts).
+ {Warnings3, State2} = run_dialyzer(State, Opts, Output),
+ {Warnings2 + Warnings3, State2}.
apps_to_files(Apps) ->
- lists:flatmap(fun app_to_files/1, Apps).
+ ?INFO("Resolving files...", []),
+ Result = [{Files, Warnings} ||
+ App <- Apps,
+ {Files, Warnings} <- [app_to_files(App)]],
+ Files = [File || {Files, _} <- Result, File <- Files],
+ Warnings = [Warning || {_, Warnings} <- Result, Warning <- Warnings],
+ {Files, Warnings}.
app_to_files(App) ->
AppName = ec_cnv:to_atom(rebar_app_info:name(App)),
- {_, Files} = app_name_to_info(AppName),
- Files.
+ {_, Files, Warnings} = app_name_to_info(AppName),
+ {Files, Warnings}.
-run_dialyzer(State, Opts) ->
+run_dialyzer(State, Opts, Output) ->
%% dialyzer may return callgraph warnings when get_warnings is false
case proplists:get_bool(get_warnings, Opts) of
true ->
@@ -373,10 +410,8 @@ run_dialyzer(State, Opts) ->
{check_plt, false} |
Opts],
?DEBUG("Running dialyzer with options: ~p~n", [Opts2]),
- {Unknowns, Warnings} = format_warnings(dialyzer:run(Opts2)),
- _ = [?CONSOLE("~s", [Unknown]) || Unknown <- Unknowns],
- _ = [?CONSOLE("~s", [Warning]) || Warning <- Warnings],
- {length(Warnings), State};
+ Warnings = format_warnings(Output, dialyzer:run(Opts2)),
+ {Warnings, State};
false ->
Opts2 = [{warnings, no_warnings()},
{check_plt, false} |
@@ -386,18 +421,41 @@ run_dialyzer(State, Opts) ->
{0, State}
end.
-format_warnings(Warnings) ->
- format_warnings(Warnings, [], []).
+format_warnings(Output, Warnings) ->
+ Warnings1 = format_warnings(Warnings),
+ console_warnings(Warnings1),
+ file_warnings(Output, Warnings1),
+ length(Warnings1).
-format_warnings([Warning | Rest], Unknowns, Warnings) ->
- case dialyzer:format_warning(Warning, fullpath) of
+format_warnings(Warnings) ->
+ [format_warning(Warning) || Warning <- Warnings].
+
+format_warning({unknown_application, _, [AppName]}) ->
+ io_lib:format("Unknown application: ~s", [AppName]);
+format_warning({unknown_module, _, [Module]}) ->
+ io_lib:format("Unknown module: ~s", [Module]);
+format_warning(Warning) ->
+ case strip(dialyzer:format_warning(Warning, fullpath)) of
":0: " ++ Unknown ->
- format_warnings(Rest, [strip(Unknown) | Unknowns], Warnings);
- Warning2 ->
- format_warnings(Rest, Unknowns, [strip(Warning2) | Warnings])
- end;
-format_warnings([], Unknowns, Warnings) ->
- {Unknowns, Warnings}.
+ Unknown;
+ Warning1 ->
+ Warning1
+ end.
+
+console_warnings(Warnings) ->
+ _ = [?CONSOLE("~s", [Warning]) || Warning <- Warnings],
+ ok.
+
+file_warnings(_, []) ->
+ ok;
+file_warnings(Output, Warnings) ->
+ Warnings1 = [[Warning, $\n] || Warning <- Warnings],
+ case file:write_file(Output, Warnings1, [append]) of
+ ok ->
+ ok;
+ {error, Reason} ->
+ throw({output_file_error, Output, Reason})
+ end.
strip(Warning) ->
string:strip(Warning, right, $\n).
diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl
index 3fb2d71..bc0a113 100644
--- a/src/rebar_prv_install_deps.erl
+++ b/src/rebar_prv_install_deps.erl
@@ -302,12 +302,12 @@ profile_dep_dir(State, Profile) ->
update_seen_src_dep(AppInfo, Profile, Level, SrcDeps, PkgDeps, SrcApps, State, Upgrade, Seen, BaseLocks, Locks) ->
Name = rebar_app_info:name(AppInfo),
- %% If seen from lock file don't print warning about skipping
+ %% If seen from lock file or user requested an upgrade
+ %% don't print warning about skipping
case lists:keymember(Name, 1, BaseLocks) of
- false ->
- warn_skip_deps(AppInfo, State);
- true ->
- ok
+ false when Upgrade -> ok;
+ false when not Upgrade -> warn_skip_deps(AppInfo, State);
+ true -> ok
end,
%% scan for app children here if upgrading
case Upgrade of
@@ -585,7 +585,7 @@ maybe_upgrade(AppInfo, AppDir, true, State) ->
Source = rebar_app_info:source(AppInfo),
case rebar_fetch:needs_update(AppDir, Source, State) of
true ->
- ?INFO("Updating ~s", [rebar_app_info:name(AppInfo)]),
+ ?INFO("Upgrading ~s", [rebar_app_info:name(AppInfo)]),
case rebar_fetch:download_source(AppDir, Source, State) of
{error, Reason} ->
throw(Reason);
@@ -593,6 +593,7 @@ maybe_upgrade(AppInfo, AppDir, true, State) ->
Result
end;
false ->
+ ?INFO("No upgrade needed for ~s", [rebar_app_info:name(AppInfo)]),
false
end.
diff --git a/src/rebar_prv_xref.erl b/src/rebar_prv_xref.erl
index 1d1afa0..ed53da6 100644
--- a/src/rebar_prv_xref.erl
+++ b/src/rebar_prv_xref.erl
@@ -248,11 +248,11 @@ format_mfa_source(MFA) ->
%% Extract an element from a tuple, or undefined if N > tuple size
%%
safe_element(N, Tuple) ->
- case catch(element(N, Tuple)) of
- {'EXIT', {badarg, _}} ->
- undefined;
- Value ->
- Value
+ try
+ element(N, Tuple)
+ catch
+ error:badarg ->
+ undefined
end.
%%