Stop passing useless Config into erlcinfo_file

Also pas only InclDirs into init_erlcinfo as this is the only
thing from Config/ErlOpts needed there.
This commit is contained in:
David Kubecka 2015-03-22 20:30:41 +01:00
parent b0320ce058
commit fd482b661a

View file

@ -109,7 +109,7 @@ compile(Config, _AppFile) ->
doterl_compile(Config, "ebin"). doterl_compile(Config, "ebin").
-spec clean(rebar_config:config(), file:filename()) -> 'ok'. -spec clean(rebar_config:config(), file:filename()) -> 'ok'.
clean(Config, _AppFile) -> clean(_Config, _AppFile) ->
MibFiles = rebar_utils:find_files_by_ext("mibs", ".mib"), MibFiles = rebar_utils:find_files_by_ext("mibs", ".mib"),
MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles], MIBs = [filename:rootname(filename:basename(MIB)) || MIB <- MibFiles],
rebar_file_utils:delete_each( rebar_file_utils:delete_each(
@ -123,7 +123,7 @@ clean(Config, _AppFile) ->
|| F <- YrlFiles ]), || F <- YrlFiles ]),
%% Delete the build graph, if any %% Delete the build graph, if any
rebar_file_utils:rm_rf(erlcinfo_file(Config)), rebar_file_utils:rm_rf(erlcinfo_file()),
%% Erlang compilation is recursive, so it's possible that we have a nested %% Erlang compilation is recursive, so it's possible that we have a nested
%% directory structure in ebin with .beam files within. As such, we want %% directory structure in ebin with .beam files within. As such, we want
@ -313,7 +313,7 @@ doterl_compile(Config, OutDir, MoreSources, ErlOpts) ->
CurrPath = code:get_path(), CurrPath = code:get_path(),
true = code:add_path(filename:absname("ebin")), true = code:add_path(filename:absname("ebin")),
OutDir1 = proplists:get_value(outdir, ErlOpts, OutDir), OutDir1 = proplists:get_value(outdir, ErlOpts, OutDir),
G = init_erlcinfo(Config, AllErlFiles), G = init_erlcinfo(proplists:get_all_values(i, ErlOpts), AllErlFiles),
%% Split RestErls so that files which are depended on are treated %% Split RestErls so that files which are depended on are treated
%% like erl_first_files. %% like erl_first_files.
{OtherFirstErls, OtherErls} = {OtherFirstErls, OtherErls} =
@ -387,12 +387,9 @@ u_add_element(Elem, [Elem|_]=Set) -> Set;
u_add_element(Elem, [E1|Set]) -> [E1|u_add_element(Elem, Set)]; u_add_element(Elem, [E1|Set]) -> [E1|u_add_element(Elem, Set)];
u_add_element(Elem, []) -> [Elem]. u_add_element(Elem, []) -> [Elem].
-spec include_path(file:filename(), -spec include_path(file:filename(), list()) -> [file:filename(), ...].
rebar_config:config()) -> [file:filename(), ...]. include_path(Source, InclDirs) ->
include_path(Source, Config) -> lists:usort(["include", filename:dirname(Source) |InclDirs]).
ErlOpts = rebar_config:get(Config, erl_opts, []),
lists:usort(["include", filename:dirname(Source)]
++ proplists:get_all_values(i, ErlOpts)).
-spec needs_compile(file:filename(), file:filename(), -spec needs_compile(file:filename(), file:filename(),
[string()]) -> boolean(). [string()]) -> boolean().
@ -401,20 +398,20 @@ 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(_Config, #erlcinfo{vsn=?ERLCINFO_VSN}) -> check_erlcinfo(#erlcinfo{vsn=?ERLCINFO_VSN}) ->
ok; ok;
check_erlcinfo(Config, #erlcinfo{vsn=Vsn}) -> check_erlcinfo(#erlcinfo{vsn=Vsn}) ->
?ABORT("~s file version is incompatible. expected: ~b got: ~b~n", ?ABORT("~s file version is incompatible. expected: ~b got: ~b~n",
[erlcinfo_file(Config), ?ERLCINFO_VSN, Vsn]); [erlcinfo_file(), ?ERLCINFO_VSN, Vsn]);
check_erlcinfo(Config, _) -> check_erlcinfo(_) ->
?ABORT("~s file is invalid. Please delete before next run.~n", ?ABORT("~s file is invalid. Please delete before next run.~n",
[erlcinfo_file(Config)]). [erlcinfo_file()]).
erlcinfo_file(_Config) -> erlcinfo_file() ->
filename:join([rebar_utils:get_cwd(), ".rebar", ?ERLCINFO_FILE]). filename:join([rebar_utils:get_cwd(), ".rebar", ?ERLCINFO_FILE]).
init_erlcinfo(Config, Erls) -> init_erlcinfo(InclDirs, Erls) ->
G = restore_erlcinfo(Config), G = restore_erlcinfo(),
%% 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.
@ -423,10 +420,10 @@ init_erlcinfo(Config, Erls) ->
Dir = filename:dirname(Erl), Dir = filename:dirname(Erl),
sets:add_element(Dir, Acc) sets:add_element(Dir, Acc)
end, sets:new(), Erls)), end, sets:new(), Erls)),
Updates = [update_erlcinfo(G, Erl, include_path(Erl, Config) ++ Dirs) Updates = [update_erlcinfo(G, Erl, include_path(Erl, InclDirs) ++ Dirs)
|| Erl <- Erls], || Erl <- Erls],
Modified = lists:member(modified, Updates), Modified = lists:member(modified, Updates),
ok = store_erlcinfo(G, Config, Modified), ok = store_erlcinfo(G, Modified),
G. G.
update_erlcinfo(G, Source, Dirs) -> update_erlcinfo(G, Source, Dirs) ->
@ -463,14 +460,13 @@ modify_erlcinfo(G, Source, Dirs) ->
digraph:add_edge(G, Source, Incl) digraph:add_edge(G, Source, Incl)
end, AbsIncls). end, AbsIncls).
restore_erlcinfo(Config) -> restore_erlcinfo() ->
File = erlcinfo_file(Config),
G = digraph:new(), G = digraph:new(),
case file:read_file(File) of case file:read_file(erlcinfo_file()) of
{ok, Data} -> {ok, Data} ->
try binary_to_term(Data) of try binary_to_term(Data) of
Erlcinfo -> Erlcinfo ->
ok = check_erlcinfo(Config, Erlcinfo), ok = check_erlcinfo(Erlcinfo),
#erlcinfo{info=ErlcInfo} = Erlcinfo, #erlcinfo{info=ErlcInfo} = Erlcinfo,
{Vs, Es} = ErlcInfo, {Vs, Es} = ErlcInfo,
lists:foreach( lists:foreach(
@ -493,9 +489,9 @@ restore_erlcinfo(Config) ->
end, end,
G. G.
store_erlcinfo(_G, _Config, _Modified = false) -> store_erlcinfo(_G, _Modified = false) ->
ok; ok;
store_erlcinfo(G, Config, _Modified) -> store_erlcinfo(G, _Modified) ->
Vs = lists:map( Vs = lists:map(
fun(V) -> fun(V) ->
digraph:vertex(G, V) digraph:vertex(G, V)
@ -508,7 +504,7 @@ store_erlcinfo(G, Config, _Modified) ->
{V1, V2} {V1, V2}
end, digraph:out_edges(G, V)) end, digraph:out_edges(G, V))
end, Vs), end, Vs),
File = erlcinfo_file(Config), File = erlcinfo_file(),
ok = filelib:ensure_dir(File), ok = filelib:ensure_dir(File),
Data = term_to_binary(#erlcinfo{info={Vs, Es}}, [{compressed, 9}]), Data = term_to_binary(#erlcinfo{info={Vs, Es}}, [{compressed, 9}]),
file:write_file(File, Data). file:write_file(File, Data).