Move the .erl sorting to the right place

This commit is contained in:
Vagabond 2010-03-02 17:58:05 -05:00
parent c4d3f0ea65
commit a3f8489340
2 changed files with 37 additions and 34 deletions

View file

@ -44,15 +44,12 @@ run(Config, FirstFiles, RestFiles, CompileFn) ->
[] -> [] ->
ok; ok;
_ -> _ ->
% Sort RestFiles so that parse_transforms and behaviours are first
SortedRestFiles = [K || {K, _V} <- lists:keysort(2,
[{F, compile_priority(F)} || F <- RestFiles ])],
Self = self(), Self = self(),
F = fun() -> compile_worker(Self, Config, CompileFn) end, F = fun() -> compile_worker(Self, Config, CompileFn) end,
Jobs = rebar_config:get_jobs(), Jobs = rebar_config:get_jobs(),
?DEBUG("Starting ~B compile worker(s)~n", [Jobs]), ?DEBUG("Starting ~B compile worker(s)~n", [Jobs]),
Pids = [spawn_monitor(F) || _I <- lists:seq(1,Jobs)], Pids = [spawn_monitor(F) || _I <- lists:seq(1,Jobs)],
compile_queue(Pids, SortedRestFiles) compile_queue(Pids, RestFiles)
end. end.
run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt, Compile3Fn) -> run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt, Compile3Fn) ->
@ -189,32 +186,3 @@ compile_worker(QueuePid, Config, CompileFn) ->
empty -> empty ->
ok ok
end. end.
compile_priority(File) ->
case epp_dodger:parse_file(File) of
{error, _} ->
10; % couldn't parse the file, default priority
{ok, Trees} ->
?DEBUG("Computing priority of ~p\n", [File]),
F2 = fun({tree,arity_qualifier,_,
{arity_qualifier,{tree,atom,_,behaviour_info},
{tree,integer,_,1}}}, _) ->
2;
({tree,arity_qualifier,_,
{arity_qualifier,{tree,atom,_,parse_transform},
{tree,integer,_,2}}}, _) ->
1;
(_, Acc) ->
Acc
end,
F = fun({tree, attribute, _, {attribute, {tree, atom, _, export},
[{tree, list, _, {list, List, none}}]}}, Acc) ->
lists:foldl(F2, Acc, List);
(_, Acc) ->
Acc
end,
lists:foldl(F, 10, Trees)
end.

View file

@ -80,10 +80,16 @@ 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
% This should probably be somewhat combined with inspect_epp
SortedRestErls = [K || {K, _V} <- lists:keysort(2,
[{F, compile_priority(F)} || F <- RestErls ])],
%% Make sure that ebin/ is on the path %% Make sure that ebin/ is on the path
CurrPath = code:get_path(), CurrPath = code:get_path(),
code:add_path("ebin"), code:add_path("ebin"),
rebar_base_compiler:run(Config, FirstErls, RestErls, rebar_base_compiler:run(Config, FirstErls, SortedRestErls,
fun(S, C) -> internal_erl_compile(S, C, OutDir) end), fun(S, C) -> internal_erl_compile(S, C, OutDir) end),
code:set_path(CurrPath), code:set_path(CurrPath),
ok. ok.
@ -211,3 +217,32 @@ delete_dir(Dir, []) ->
delete_dir(Dir, Subdirs) -> delete_dir(Dir, Subdirs) ->
lists:foreach(fun(D) -> delete_dir(D, dirs(D)) end, Subdirs), lists:foreach(fun(D) -> delete_dir(D, dirs(D)) end, Subdirs),
file:del_dir(Dir). file:del_dir(Dir).
-spec compile_priority(File::string()) -> pos_integer().
compile_priority(File) ->
case epp_dodger:parse_file(File) of
{error, _} ->
10; % couldn't parse the file, default priority
{ok, Trees} ->
?DEBUG("Computing priority of ~p\n", [File]),
F2 = fun({tree,arity_qualifier,_,
{arity_qualifier,{tree,atom,_,behaviour_info},
{tree,integer,_,1}}}, _) ->
2;
({tree,arity_qualifier,_,
{arity_qualifier,{tree,atom,_,parse_transform},
{tree,integer,_,2}}}, _) ->
1;
(_, Acc) ->
Acc
end,
F = fun({tree, attribute, _, {attribute, {tree, atom, _, export},
[{tree, list, _, {list, List, none}}]}}, Acc) ->
lists:foldl(F2, Acc, List);
(_, Acc) ->
Acc
end,
lists:foldl(F, 10, Trees)
end.