mirror of
https://github.com/correl/rebar.git
synced 2024-11-14 11:09:35 +00:00
Sanitize erlcinfo checking
As erlcinfo is only an internal optimization mechanism, user should be only minimally bothered by issues with it. Especially it shouldn't ever cause a fatal error and if it cannot be restored properly, only a warning (not error) message should be emitted (if any). Also it probably doesn't make sense for this warning message to be too detailed - just state that something went wrong and silently delete the erlcinfo file.
This commit is contained in:
parent
ccdfc1a270
commit
df97a49ce7
1 changed files with 19 additions and 35 deletions
|
@ -398,20 +398,17 @@ needs_compile(Source, Target, Parents) ->
|
|||
lists:any(fun(I) -> TargetLastMod < filelib:last_modified(I) end,
|
||||
[Source] ++ Parents).
|
||||
|
||||
check_erlcinfo(#erlcinfo{vsn=?ERLCINFO_VSN}) ->
|
||||
ok;
|
||||
check_erlcinfo(#erlcinfo{vsn=Vsn}) ->
|
||||
?ABORT("~s file version is incompatible. expected: ~b got: ~b~n",
|
||||
[erlcinfo_file(), ?ERLCINFO_VSN, Vsn]);
|
||||
check_erlcinfo(_) ->
|
||||
?ABORT("~s file is invalid. Please delete before next run.~n",
|
||||
[erlcinfo_file()]).
|
||||
|
||||
erlcinfo_file() ->
|
||||
filename:join([rebar_utils:get_cwd(), ".rebar", ?ERLCINFO_FILE]).
|
||||
|
||||
init_erlcinfo(InclDirs, Erls) ->
|
||||
G = restore_erlcinfo(),
|
||||
G = digraph:new(),
|
||||
try restore_erlcinfo(G)
|
||||
catch
|
||||
_ ->
|
||||
?WARN("Failed to restore ~s file. Discarding it.~n", [erlcinfo_file()]),
|
||||
ok = file:delete(erlcinfo_file())
|
||||
end,
|
||||
%% Get a unique list of dirs based on the source files' locations.
|
||||
%% This is used for finding files in sub dirs of the configured
|
||||
%% src_dirs. For example, src/sub_dir/foo.erl.
|
||||
|
@ -460,34 +457,21 @@ modify_erlcinfo(G, Source, Dirs) ->
|
|||
digraph:add_edge(G, Source, Incl)
|
||||
end, AbsIncls).
|
||||
|
||||
restore_erlcinfo() ->
|
||||
G = digraph:new(),
|
||||
restore_erlcinfo(G) ->
|
||||
case file:read_file(erlcinfo_file()) of
|
||||
{ok, Data} ->
|
||||
try binary_to_term(Data) of
|
||||
Erlcinfo ->
|
||||
ok = check_erlcinfo(Erlcinfo),
|
||||
#erlcinfo{info=ErlcInfo} = Erlcinfo,
|
||||
{Vs, Es} = ErlcInfo,
|
||||
lists:foreach(
|
||||
fun({V, LastUpdated}) ->
|
||||
digraph:add_vertex(G, V, LastUpdated)
|
||||
end, Vs),
|
||||
lists:foreach(
|
||||
fun({V1, V2}) ->
|
||||
digraph:add_edge(G, V1, V2)
|
||||
end, Es)
|
||||
catch
|
||||
error:badarg ->
|
||||
?ERROR(
|
||||
"Failed (binary_to_term) to restore rebar info file."
|
||||
" Discard file.~n", []),
|
||||
ok
|
||||
end;
|
||||
_Err ->
|
||||
#erlcinfo{vsn=?ERLCINFO_VSN, info={Vs, Es}} = binary_to_term(Data),
|
||||
lists:foreach(
|
||||
fun({V, LastUpdated}) ->
|
||||
digraph:add_vertex(G, V, LastUpdated)
|
||||
end, Vs),
|
||||
lists:foreach(
|
||||
fun({V1, V2}) ->
|
||||
digraph:add_edge(G, V1, V2)
|
||||
end, Es);
|
||||
{error, _} ->
|
||||
ok
|
||||
end,
|
||||
G.
|
||||
end.
|
||||
|
||||
store_erlcinfo(_G, _Modified = false) ->
|
||||
ok;
|
||||
|
|
Loading…
Reference in a new issue