mirror of
https://github.com/correl/rebar.git
synced 2024-12-18 11:06:20 +00:00
Parse transforms and behaviours are compiled first
The previous code in rebar that was trying to ensure that parse transforms and behaviours were compiled first doesn't work with multiple compiler workers because of the possiblity of one of the workers compiling a file that needs a parse transform or a behaviour at the same time another worker is compiling that same parse transform or behaviour. The solution this patch implements is to append any parse transforms and any behaviours (in that order) to erl_first_files to ensure that they are compiled before any regular files. This patch won't break any currently working uses of erl_first files because we only append to the list, so anything in erl_first_files is still compiled before anything else.
This commit is contained in:
parent
465af36266
commit
1bf45036dc
1 changed files with 17 additions and 7 deletions
|
@ -110,17 +110,27 @@ doterl_compile(Config, OutDir, MoreSources) ->
|
||||||
RestErls = [Source || Source <- gather_src(SrcDirs, []) ++ MoreSources,
|
RestErls = [Source || Source <- gather_src(SrcDirs, []) ++ MoreSources,
|
||||||
lists:member(Source, FirstErls) == false],
|
lists:member(Source, FirstErls) == false],
|
||||||
|
|
||||||
% Sort RestErls so that parse_transforms and behaviours are first
|
% Split RestErls so that parse_transforms and behaviours are instead added
|
||||||
|
% to erl_first_files, parse transforms first.
|
||||||
% This should probably be somewhat combined with inspect_epp
|
% This should probably be somewhat combined with inspect_epp
|
||||||
SortedRestErls = [K || {K, _V} <- lists:keysort(2,
|
[ParseTransforms, Behaviours, OtherErls] = lists:foldl(fun(F, [A, B, C]) ->
|
||||||
[{F, compile_priority(F)} || F <- RestErls ])],
|
case compile_priority(F) of
|
||||||
|
parse_transform ->
|
||||||
|
[[F | A], B, C];
|
||||||
|
behaviour ->
|
||||||
|
[A, [F | B], C];
|
||||||
|
_ ->
|
||||||
|
[A, B, [F | C]]
|
||||||
|
end
|
||||||
|
end, [[], [], []], RestErls),
|
||||||
|
|
||||||
|
NewFirstErls = FirstErls ++ ParseTransforms ++ Behaviours,
|
||||||
|
|
||||||
%% Make sure that ebin/ exists and is on the path
|
%% Make sure that ebin/ exists and is on the path
|
||||||
ok = filelib:ensure_dir(filename:join("ebin", "dummy.beam")),
|
ok = filelib:ensure_dir(filename:join("ebin", "dummy.beam")),
|
||||||
CurrPath = code:get_path(),
|
CurrPath = code:get_path(),
|
||||||
code:add_path("ebin"),
|
code:add_path("ebin"),
|
||||||
rebar_base_compiler:run(Config, FirstErls, SortedRestErls,
|
rebar_base_compiler:run(Config, NewFirstErls, OtherErls,
|
||||||
fun(S, C) -> internal_erl_compile(S, C, OutDir,
|
fun(S, C) -> internal_erl_compile(S, C, OutDir,
|
||||||
ErlOpts)
|
ErlOpts)
|
||||||
end),
|
end),
|
||||||
|
@ -297,11 +307,11 @@ compile_priority(File) ->
|
||||||
F2 = fun({tree,arity_qualifier,_,
|
F2 = fun({tree,arity_qualifier,_,
|
||||||
{arity_qualifier,{tree,atom,_,behaviour_info},
|
{arity_qualifier,{tree,atom,_,behaviour_info},
|
||||||
{tree,integer,_,1}}}, _) ->
|
{tree,integer,_,1}}}, _) ->
|
||||||
2;
|
behaviour;
|
||||||
({tree,arity_qualifier,_,
|
({tree,arity_qualifier,_,
|
||||||
{arity_qualifier,{tree,atom,_,parse_transform},
|
{arity_qualifier,{tree,atom,_,parse_transform},
|
||||||
{tree,integer,_,2}}}, _) ->
|
{tree,integer,_,2}}}, _) ->
|
||||||
1;
|
parse_transform;
|
||||||
(_, Acc) ->
|
(_, Acc) ->
|
||||||
Acc
|
Acc
|
||||||
end,
|
end,
|
||||||
|
@ -313,7 +323,7 @@ compile_priority(File) ->
|
||||||
Acc
|
Acc
|
||||||
end,
|
end,
|
||||||
|
|
||||||
lists:foldl(F, 10, Trees)
|
lists:foldl(F, normal, Trees)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
Loading…
Reference in a new issue