summaryrefslogtreecommitdiff
path: root/src/rebar_prv_compile.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/rebar_prv_compile.erl')
-rw-r--r--src/rebar_prv_compile.erl34
1 files changed, 27 insertions, 7 deletions
diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl
index 30611cd..d80586d 100644
--- a/src/rebar_prv_compile.erl
+++ b/src/rebar_prv_compile.erl
@@ -31,23 +31,31 @@ init(State) ->
{short_desc, "Compile apps .app.src and .erl files."},
{desc, ""},
{opts, [
- {jobs, $j, "jobs", integer, JobsHelp}
+ {jobs, $j, "jobs", integer, JobsHelp}
]}])),
{ok, State1}.
-spec do(rebar_state:t()) -> {ok, rebar_state:t()} | {error, string()}.
do(State) ->
{ok, State1} = handle_args(State),
+ Jobs = rebar_state:get(State1, jobs),
ProjectApps = rebar_state:project_apps(State1),
Deps = rebar_state:get(State1, deps_to_build, []),
- lists:foreach(fun(AppInfo) ->
- AppDir = rebar_app_info:dir(AppInfo),
- C = rebar_config:consult(AppDir),
- S = rebar_state:new(State1, C, AppDir),
- build(S, AppInfo)
- end, Deps++ProjectApps),
+ %% Need to allow global config vars used on deps
+ %% Right now no way to differeniate and just give deps a new state
+ 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(),
+ rebar_hooks:run_compile_hooks(Cwd, pre_hooks, compile, 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),
+ rebar_hooks:run_compile_hooks(Cwd, post_hooks, compile, State1),
{ok, State1}.
@@ -55,6 +63,18 @@ do(State) ->
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(State, C, AppDir),
+
+ %% Legacy hook support
+ rebar_hooks:run_compile_hooks(AppDir, pre_hooks, compile, S),
+ build(S, AppInfo),
+ rebar_hooks:run_compile_hooks(AppDir, post_hooks, compile, S)
+ end, Apps).
+
build(State, AppInfo) ->
?INFO("Compiling ~s~n", [rebar_app_info:name(AppInfo)]),
rebar_erlc_compiler:compile(State, ec_cnv:to_list(rebar_app_info:dir(AppInfo))),