From 044cd78b449f1db588ff7ec0129c64a84e841126 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Sat, 1 Nov 2014 22:48:53 -0500 Subject: refactoring build loop --- src/rebar_prv_compile.erl | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) (limited to 'src') diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index dde5112..b5beca9 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -45,40 +45,35 @@ do(State) -> %% Need to allow global config vars used on deps %% 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 Cwd = rebar_utils:get_cwd(), run_compile_hooks(Cwd, pre_hooks, State1), %% 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, []), + 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) -> AppDir = rebar_app_info:dir(AppInfo), C = rebar_config:consult(AppDir), - S = rebar_state:new(State2, C, AppDir), + S = rebar_state:new(State, C, AppDir), %% Legacy hook support run_compile_hooks(AppDir, pre_hooks, S), build(S, AppInfo), 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) -> ?INFO("Compiling ~s~n", [rebar_app_info:name(AppInfo)]), -- cgit v1.1