mirror of
https://github.com/correl/rebar.git
synced 2024-11-15 03:00:18 +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,
|
lists:any(fun(I) -> TargetLastMod < filelib:last_modified(I) end,
|
||||||
[Source] ++ Parents).
|
[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() ->
|
erlcinfo_file() ->
|
||||||
filename:join([rebar_utils:get_cwd(), ".rebar", ?ERLCINFO_FILE]).
|
filename:join([rebar_utils:get_cwd(), ".rebar", ?ERLCINFO_FILE]).
|
||||||
|
|
||||||
init_erlcinfo(InclDirs, Erls) ->
|
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.
|
%% Get a unique list of dirs based on the source files' locations.
|
||||||
%% This is used for finding files in sub dirs of the configured
|
%% This is used for finding files in sub dirs of the configured
|
||||||
%% src_dirs. For example, src/sub_dir/foo.erl.
|
%% src_dirs. For example, src/sub_dir/foo.erl.
|
||||||
|
@ -460,34 +457,21 @@ modify_erlcinfo(G, Source, Dirs) ->
|
||||||
digraph:add_edge(G, Source, Incl)
|
digraph:add_edge(G, Source, Incl)
|
||||||
end, AbsIncls).
|
end, AbsIncls).
|
||||||
|
|
||||||
restore_erlcinfo() ->
|
restore_erlcinfo(G) ->
|
||||||
G = digraph:new(),
|
|
||||||
case file:read_file(erlcinfo_file()) of
|
case file:read_file(erlcinfo_file()) of
|
||||||
{ok, Data} ->
|
{ok, Data} ->
|
||||||
try binary_to_term(Data) of
|
#erlcinfo{vsn=?ERLCINFO_VSN, info={Vs, Es}} = binary_to_term(Data),
|
||||||
Erlcinfo ->
|
lists:foreach(
|
||||||
ok = check_erlcinfo(Erlcinfo),
|
fun({V, LastUpdated}) ->
|
||||||
#erlcinfo{info=ErlcInfo} = Erlcinfo,
|
digraph:add_vertex(G, V, LastUpdated)
|
||||||
{Vs, Es} = ErlcInfo,
|
end, Vs),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({V, LastUpdated}) ->
|
fun({V1, V2}) ->
|
||||||
digraph:add_vertex(G, V, LastUpdated)
|
digraph:add_edge(G, V1, V2)
|
||||||
end, Vs),
|
end, Es);
|
||||||
lists:foreach(
|
{error, _} ->
|
||||||
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 ->
|
|
||||||
ok
|
ok
|
||||||
end,
|
end.
|
||||||
G.
|
|
||||||
|
|
||||||
store_erlcinfo(_G, _Modified = false) ->
|
store_erlcinfo(_G, _Modified = false) ->
|
||||||
ok;
|
ok;
|
||||||
|
|
Loading…
Reference in a new issue