basho / rebar

Erlang Build Tools -- Please file bug and feature requests at http://issues.basho.com.

Clone this repository (size: 432.4 KB): HTTPS / SSH
$ hg clone http://hg.basho.com/rebar
commit 178: 6023a477f2d1
parent 175: bf0185304d32
branch: default
Compile parse transform and custom behaviours first
Vagabond
5 months ago

Changed (Δ1.2 KB):

raw changeset »

src/rebar_base_compiler.erl (33 lines added, 1 lines removed)

Up to file-list src/rebar_base_compiler.erl:

@@ -44,12 +44,15 @@ run(Config, FirstFiles, RestFiles, Compi
44
44
        [] ->
45
45
            ok;
46
46
        _ ->
47
            % Sort RestFiles so that parse_transforms and behaviours are first
48
            SortedRestFiles = [K || {K, _V} <- lists:keysort(2,
49
                    [{F, compile_priority(F)} || F <- RestFiles ])],
47
50
            Self = self(),
48
51
            F = fun() -> compile_worker(Self, Config, CompileFn) end,
49
52
            Jobs = rebar_config:get_jobs(),
50
53
            ?DEBUG("Starting ~B compile worker(s)~n", [Jobs]),
51
54
            Pids = [spawn_monitor(F) || _I <- lists:seq(1,Jobs)],
52
            compile_queue(Pids, RestFiles)
55
            compile_queue(Pids, SortedRestFiles)
53
56
    end.
54
57
55
58
run(Config, FirstFiles, SourceDir, SourceExt, TargetDir, TargetExt, Compile3Fn) ->
@@ -186,3 +189,32 @@ compile_worker(QueuePid, Config, Compile
186
189
        empty ->
187
190
            ok
188
191
    end.
192
193
compile_priority(File) ->
194
    case epp_dodger:parse_file(File) of
195
        {error, _} ->
196
            10; % couldn't parse the file, default priority
197
        {ok, Trees} ->
198
            ?DEBUG("Computing priority of ~p\n", [File]),
199
            F2 = fun({tree,arity_qualifier,_,
200
                        {arity_qualifier,{tree,atom,_,behaviour_info},
201
                            {tree,integer,_,1}}}, _) ->
202
                    2;
203
                ({tree,arity_qualifier,_,
204
                        {arity_qualifier,{tree,atom,_,parse_transform},
205
                            {tree,integer,_,2}}}, _) ->
206
                    1;
207
                (_, Acc) ->
208
                    Acc
209
            end,
210
211
            F = fun({tree, attribute, _, {attribute, {tree, atom, _, export},
212
                            [{tree, list, _, {list, List, none}}]}}, Acc) ->
213
                    lists:foldl(F2, Acc, List);
214
                (_, Acc) ->
215
                    Acc
216
            end,
217
218
            lists:foldl(F, 10, Trees)
219
    end.
220