diff options
-rw-r--r-- | src/rebar_git_resource.erl | 2 | ||||
-rw-r--r-- | src/rebar_prv_compile.erl | 34 | ||||
-rw-r--r-- | src/rebar_prv_install_deps.erl | 1 |
3 files changed, 35 insertions, 2 deletions
diff --git a/src/rebar_git_resource.erl b/src/rebar_git_resource.erl index 1dfa1bf..444163e 100644 --- a/src/rebar_git_resource.erl +++ b/src/rebar_git_resource.erl @@ -16,6 +16,8 @@ lock(AppDir, {git, Url, _}) -> ,both, $\n), {git, Url, {ref, Ref}}. +%% Return true if either the git url or tag/branch/ref is not the same as the currently +%% checked out git repo for the dep needs_update(Dir, {git, Url, {tag, Tag}}) -> {ok, CurrentUrl} = rebar_utils:sh(?FMT("git config --get remote.origin.url", []), [{cd, Dir}]), diff --git a/src/rebar_prv_compile.erl b/src/rebar_prv_compile.erl index c87d5d8..7c73545 100644 --- a/src/rebar_prv_compile.erl +++ b/src/rebar_prv_compile.erl @@ -50,7 +50,11 @@ do(State) -> C = rebar_config:consult(AppDir), S = rebar_state:new(rebar_state:new(), C, AppDir), S1 = rebar_state:set(S, jobs, Jobs), - build(S1, AppInfo) + + %% Legacy hook support + run_compile_hooks(AppDir, pre_hooks, S1), + build(S1, AppInfo), + run_compile_hooks(AppDir, post_hooks, S1) end, Deps), %% Use the project State for building project apps @@ -58,7 +62,12 @@ do(State) -> AppDir = rebar_app_info:dir(AppInfo), C = rebar_config:consult(AppDir), S = rebar_state:new(State1, C, AppDir), - build(S, AppInfo) + + %% Legacy hook support + %% TODO: for multi-app projects run top-level hooks only once + run_compile_hooks(AppDir, pre_hooks, S), + build(S, AppInfo), + run_compile_hooks(AppDir, pre_hooks, S) end, ProjectApps), {ok, State1}. @@ -81,3 +90,24 @@ handle_args(State) -> {Args, _} = rebar_state:command_parsed_args(State), Jobs = proplists:get_value(jobs, Args, ?DEFAULT_JOBS), {ok, rebar_state:set(State, jobs, Jobs)}. + +run_compile_hooks(Dir, Type, State) -> + Hooks = rebar_state:get(State, Type, []), + lists:foreach(fun({_, compile, _}=Hook) -> + apply_hook(Dir, [], Hook); + ({compile, _}=Hook)-> + apply_hook(Dir, [], Hook); + (_) -> + continue + end, Hooks). + +apply_hook(Dir, Env, {Arch, Command, Hook}) -> + case rebar_utils:is_arch(Arch) of + true -> + apply_hook(Dir, Env, {Command, Hook}); + false -> + ok + end; +apply_hook(Dir, Env, {Command, Hook}) -> + Msg = lists:flatten(io_lib:format("Hook for ~p failed!~n", [Command])), + rebar_utils:sh(Hook, [{cd, Dir}, {env, Env}, {abort_on_error, Msg}]). diff --git a/src/rebar_prv_install_deps.erl b/src/rebar_prv_install_deps.erl index 6ae3042..1baa9db 100644 --- a/src/rebar_prv_install_deps.erl +++ b/src/rebar_prv_install_deps.erl @@ -85,6 +85,7 @@ do(State) -> {error, Error} end catch + %% maybe_fetch will maybe_throw an exception to break out of some loops _:Reason -> {error, Reason} end. |