summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_prv_dialyzer.erl21
-rw-r--r--test/rebar_dialyzer_SUITE.erl34
2 files changed, 48 insertions, 7 deletions
diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl
index 487e9d1..2e5728a 100644
--- a/src/rebar_prv_dialyzer.erl
+++ b/src/rebar_prv_dialyzer.erl
@@ -173,7 +173,7 @@ do_update_proj_plt(State, Plt, Output) ->
case read_plt(State, Plt) of
{ok, OldFiles} ->
check_plt(State, Plt, Output, OldFiles, Files);
- {error, no_such_file} ->
+ error ->
build_proj_plt(State, Plt, Output, Files)
end.
@@ -252,14 +252,25 @@ read_plt(_State, Plt) ->
case dialyzer:plt_info(Plt) of
{ok, Info} ->
Files = proplists:get_value(files, Info, []),
- {ok, Files};
- {error, no_such_file} = Error ->
- Error;
+ read_plt_files(Plt, Files);
+ {error, no_such_file} ->
+ error;
{error, read_error} ->
Error = io_lib:format("Could not read the PLT file ~p", [Plt]),
throw({dialyzer_error, Error})
end.
+%% If any file no longer exists dialyzer will fail when updating the PLT.
+read_plt_files(Plt, Files) ->
+ case [File || File <- Files, not filelib:is_file(File)] of
+ [] ->
+ {ok, Files};
+ Missing ->
+ ?INFO("Could not find ~p files in ~p...", [length(Missing), Plt]),
+ ?DEBUG("Could not find files: ~p", [Missing]),
+ error
+ end.
+
check_plt(State, Plt, Output, OldList, FilesList) ->
Old = sets:from_list(OldList),
Files = sets:from_list(FilesList),
@@ -337,7 +348,7 @@ update_base_plt(State, BasePlt, Output, BaseFiles) ->
case read_plt(State, BasePlt) of
{ok, OldBaseFiles} ->
check_plt(State, BasePlt, Output, OldBaseFiles, BaseFiles);
- {error, no_such_file} ->
+ error ->
_ = filelib:ensure_dir(BasePlt),
build_plt(State, BasePlt, Output, BaseFiles)
end.
diff --git a/test/rebar_dialyzer_SUITE.erl b/test/rebar_dialyzer_SUITE.erl
index 31e02d9..22a4894 100644
--- a/test/rebar_dialyzer_SUITE.erl
+++ b/test/rebar_dialyzer_SUITE.erl
@@ -69,7 +69,16 @@ update_base_plt(Config) ->
?assertEqual(ErtsFiles, BasePltFiles2),
{ok, PltFiles} = plt_files(Plt),
- ?assertEqual(ErtsFiles, PltFiles).
+ ?assertEqual(ErtsFiles, PltFiles),
+
+ add_missing_file(BasePlt),
+ ok = file:delete(Plt),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"],
+ {ok, [{app, Name}]}),
+
+ {ok, BasePltFiles3} = plt_files(BasePlt),
+ ?assertEqual(ErtsFiles, BasePltFiles3).
update_app_plt(Config) ->
@@ -103,7 +112,15 @@ update_app_plt(Config) ->
{ok, [{app, Name}]}),
{ok, PltFiles3} = plt_files(Plt),
- ?assertEqual(ErtsFiles, PltFiles3).
+ ?assertEqual(ErtsFiles, PltFiles3),
+
+ add_missing_file(Plt),
+
+ rebar_test_utils:run_and_check(Config, RebarConfig, ["dialyzer"],
+ {ok, [{app, Name}]}),
+
+ {ok, PltFiles4} = plt_files(Plt),
+ ?assertEqual(ErtsFiles, PltFiles4).
build_release_plt(Config) ->
AppDir = ?config(apps, Config),
@@ -211,6 +228,19 @@ alter_plt(Plt) ->
{files, [code:which(dialyzer)]}]),
ok.
+add_missing_file(Plt) ->
+ Source = code:which(dialyzer),
+ Dest = filename:join(filename:dirname(Plt), "dialyzer.beam"),
+ {ok, _} = file:copy(Source, Dest),
+ _ = try
+ dialyzer:run([{analysis_type, plt_add},
+ {init_plt, Plt},
+ {files, [Dest]}])
+ after
+ ok = file:delete(Dest)
+ end,
+ ok.
+
-spec merge_config(Config, Config) -> Config when
Config :: [{term(), term()}].
merge_config(NewConfig, OldConfig) ->