From e334f211e373c9f019c68d5d35cc8b6aa0a1723a Mon Sep 17 00:00:00 2001 From: James Fish Date: Mon, 11 Jul 2016 14:28:38 +0100 Subject: Handle empty PLTs --- src/rebar_prv_dialyzer.erl | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/rebar_prv_dialyzer.erl') diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index 622ee60..f7e3f21 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -353,8 +353,19 @@ update_base_plt(State, BasePlt, Output, BaseFiles) -> build_plt(State, BasePlt, Output, BaseFiles) end. +build_plt(State, Plt, _, []) -> + ?INFO("Building with no files in ~p...", [Plt]), + Opts = [{get_warnings, false}, + {output_plt, Plt}, + {apps, [erts]}], + % Create a PLT with erts files and then remove erts files to be left with an + % empty PLT. Dialyzer will crash when trying to build a PLT with an empty + % file list. + _ = dialyzer:run([{analysis_type, plt_build} | Opts]), + _ = dialyzer:run([{analysis_type, plt_remove}, {init_plt, Plt} | Opts]), + {0, State}; build_plt(State, Plt, Output, Files) -> - ?INFO("Adding ~b files to ~p...", [length(Files), Plt]), + ?INFO("Building with ~b files in ~p...", [length(Files), Plt]), GetWarnings = get_config(State, get_warnings, false), Opts = [{analysis_type, plt_build}, {get_warnings, GetWarnings}, -- cgit v1.1 From 0fa2b501f05e700a35c272f98f1ab976a5bd6170 Mon Sep 17 00:00:00 2001 From: James Fish Date: Mon, 11 Jul 2016 14:41:19 +0100 Subject: Don't error when analyzing empty app --- src/rebar_prv_dialyzer.erl | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src/rebar_prv_dialyzer.erl') diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index f7e3f21..ec9e81a 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -380,12 +380,15 @@ succ_typings(State, Plt, Output) -> {0, State}; _ -> Apps = rebar_state:project_apps(State), - succ_typings(State, Plt, Output, Apps) + ?INFO("Doing success typing analysis...", []), + Files = apps_to_files(Apps), + succ_typings(State, Plt, Output, Files) end. -succ_typings(State, Plt, Output, Apps) -> - ?INFO("Doing success typing analysis...", []), - Files = apps_to_files(Apps), +succ_typings(State, Plt, _, []) -> + ?INFO("Analyzing no files with ~p...", [Plt]), + {0, State}; +succ_typings(State, Plt, Output, Files) -> ?INFO("Analyzing ~b files with ~p...", [length(Files), Plt]), Opts = [{analysis_type, succ_typings}, {get_warnings, true}, -- cgit v1.1 From 941048dce7b0fab65ee8a07828bbc8c5e2034841 Mon Sep 17 00:00:00 2001 From: James Fish Date: Mon, 11 Jul 2016 18:01:33 +0100 Subject: Avoid PLT rebuild when files deleted on new dialyzer --- src/rebar_prv_dialyzer.erl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/rebar_prv_dialyzer.erl') diff --git a/src/rebar_prv_dialyzer.erl b/src/rebar_prv_dialyzer.erl index ec9e81a..82d2d07 100644 --- a/src/rebar_prv_dialyzer.erl +++ b/src/rebar_prv_dialyzer.erl @@ -249,10 +249,15 @@ ebin_files(EbinDir) -> File <- filelib:wildcard(Wildcard, EbinDir)]. read_plt(_State, Plt) -> - case dialyzer:plt_info(Plt) of - {ok, Info} -> - Files = proplists:get_value(files, Info, []), + Vsn = dialyzer_version(), + case plt_files(Plt) of + {ok, Files} when Vsn < {2, 9, 0} -> + % Before dialyzer-2.9 (OTP 18.3) removing a beam file from the PLT + % that no longer exists would crash. Therefore force a rebuild of + % PLT if any files no longer exist. read_plt_files(Plt, Files); + {ok, _} = Result when Vsn >= {2, 9, 0} -> + Result; {error, no_such_file} -> error; {error, read_error} -> @@ -260,6 +265,14 @@ read_plt(_State, Plt) -> throw({dialyzer_error, Error}) end. +plt_files(Plt) -> + case dialyzer:plt_info(Plt) of + {ok, Info} -> + {ok, proplists:get_value(files, Info, [])}; + {error, _} = 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 -- cgit v1.1