Browse Source

refactoring build loop

pull/3/head
Tristan Sloughter 10 years ago
parent
commit
044cd78b44
1 changed files with 15 additions and 20 deletions
  1. +15
    -20
      src/rebar_prv_compile.erl

+ 15
- 20
src/rebar_prv_compile.erl View File

@ -45,40 +45,35 @@ do(State) ->
%% Need to allow global config vars used on deps %% Need to allow global config vars used on deps
%% Right now no way to differeniate and just give deps a new state %% Right now no way to differeniate and just give deps a new state
lists:foreach(fun(AppInfo) ->
AppDir = rebar_app_info:dir(AppInfo),
C = rebar_config:consult(AppDir),
S = rebar_state:new(rebar_state:new(), C, AppDir),
S1 = rebar_state:set(S, jobs, Jobs),
%% Legacy hook support
run_compile_hooks(AppDir, pre_hooks, S1),
build(S1, AppInfo),
run_compile_hooks(AppDir, post_hooks, S1)
end, Deps),
EmptyState = rebar_state:new(),
EmptyState1 = rebar_state:set(EmptyState, jobs, Jobs),
build_apps(EmptyState1, Deps),
%% Use the project State for building project apps %% Use the project State for building project apps
Cwd = rebar_utils:get_cwd(), Cwd = rebar_utils:get_cwd(),
run_compile_hooks(Cwd, pre_hooks, State1), run_compile_hooks(Cwd, pre_hooks, State1),
%% Set hooks to empty so top-level hooks aren't run for each project app %% Set hooks to empty so top-level hooks aren't run for each project app
State2 = rebar_state:set(rebar_state:set(State1, post_hooks, []), pre_hooks, []), State2 = rebar_state:set(rebar_state:set(State1, post_hooks, []), pre_hooks, []),
build_apps(State2, ProjectApps),
run_compile_hooks(Cwd, post_hooks, State1),
{ok, State1}.
-spec format_error(any(), rebar_state:t()) -> {iolist(), rebar_state:t()}.
format_error(Reason, State) ->
{io_lib:format("~p", [Reason]), State}.
build_apps(State, Apps) ->
lists:foreach(fun(AppInfo) -> lists:foreach(fun(AppInfo) ->
AppDir = rebar_app_info:dir(AppInfo), AppDir = rebar_app_info:dir(AppInfo),
C = rebar_config:consult(AppDir), C = rebar_config:consult(AppDir),
S = rebar_state:new(State2, C, AppDir),
S = rebar_state:new(State, C, AppDir),
%% Legacy hook support %% Legacy hook support
run_compile_hooks(AppDir, pre_hooks, S), run_compile_hooks(AppDir, pre_hooks, S),
build(S, AppInfo), build(S, AppInfo),
run_compile_hooks(AppDir, post_hooks, S) run_compile_hooks(AppDir, post_hooks, S)
end, ProjectApps),
run_compile_hooks(Cwd, post_hooks, State1),
{ok, State1}.
-spec format_error(any(), rebar_state:t()) -> {iolist(), rebar_state:t()}.
format_error(Reason, State) ->
{io_lib:format("~p", [Reason]), State}.
end, Apps).
build(State, AppInfo) -> build(State, AppInfo) ->
?INFO("Compiling ~s~n", [rebar_app_info:name(AppInfo)]), ?INFO("Compiling ~s~n", [rebar_app_info:name(AppInfo)]),

Loading…
Cancel
Save