25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
943 B

  1. -module(rebar_hooks).
  2. -export([run_compile_hooks/4]).
  3. run_compile_hooks(Dir, Type, Command, State) ->
  4. Hooks = rebar_state:get(State, Type, []),
  5. Env = [{"REBAR_DEPS_DIR", filename:absname(rebar_dir:deps_dir(State))}],
  6. lists:foreach(fun({_, C, _}=Hook) when C =:= Command ->
  7. apply_hook(Dir, Env, Hook);
  8. ({C, _}=Hook) when C =:= Command ->
  9. apply_hook(Dir, Env, Hook);
  10. (_) ->
  11. continue
  12. end, Hooks).
  13. apply_hook(Dir, Env, {Arch, Command, Hook}) ->
  14. case rebar_utils:is_arch(Arch) of
  15. true ->
  16. apply_hook(Dir, Env, {Command, Hook});
  17. false ->
  18. ok
  19. end;
  20. apply_hook(Dir, Env, {Command, Hook}) ->
  21. Msg = lists:flatten(io_lib:format("Hook for ~p failed!~n", [Command])),
  22. rebar_utils:sh(Hook, [use_stdout, {cd, Dir}, {env, Env}, {abort_on_error, Msg}]).