summaryrefslogtreecommitdiff
path: root/src/rebar_hooks.erl
diff options
context:
space:
mode:
authorStuart Thackray <stuart.thackray@gmail.com>2018-12-11 08:53:29 +0200
committerStuart Thackray <stuart.thackray@gmail.com>2018-12-11 08:53:29 +0200
commitebfa797c1f5d038b99beaf658757d974412a15c7 (patch)
tree9765880a7f0119c265d85f8bac7afea8d9542080 /src/rebar_hooks.erl
parent71187514dabdd94aa333495d92df84a2e750099f (diff)
parent8e28561d4e14ea85d42d17ab5a0f17f5f1c696d2 (diff)
Update from Upstream
Diffstat (limited to 'src/rebar_hooks.erl')
-rw-r--r--src/rebar_hooks.erl67
1 files changed, 5 insertions, 62 deletions
diff --git a/src/rebar_hooks.erl b/src/rebar_hooks.erl
index d6a0e2b..358458e 100644
--- a/src/rebar_hooks.erl
+++ b/src/rebar_hooks.erl
@@ -42,8 +42,7 @@ run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) ->
[] ->
State;
HookProviders ->
- PluginDepsPaths = lists:usort(rebar_state:code_paths(State, all_plugin_deps)),
- code:add_pathsa(PluginDepsPaths),
+ rebar_paths:set_paths([plugins], State),
Providers1 = rebar_state:providers(State),
State1 = rebar_state:providers(rebar_state:dir(State, Dir), Providers++Providers1),
case rebar_core:do(HookProviders, State1) of
@@ -51,39 +50,16 @@ run_provider_hooks_(Dir, Type, Command, Providers, TypeHooks, State) ->
?DEBUG(format_error({bad_provider, Type, Command, ProviderName}), []),
throw(?PRV_ERROR({bad_provider, Type, Command, ProviderName}));
{ok, State2} ->
- rebar_utils:remove_from_code_path(PluginDepsPaths),
+ rebar_paths:set_paths([deps], State2),
State2
end
end.
format_error({bad_provider, Type, Command, {Name, Namespace}}) ->
- io_lib:format("Unable to run ~s hooks for '~p', command '~p' in namespace '~p' not found.", [Type, Command, Namespace, Name]);
+ io_lib:format("Unable to run ~ts hooks for '~p', command '~p' in namespace '~p' not found.", [Type, Command, Namespace, Name]);
format_error({bad_provider, Type, Command, Name}) ->
- io_lib:format("Unable to run ~s hooks for '~p', command '~p' not found.", [Type, Command, Name]).
+ io_lib:format("Unable to run ~ts hooks for '~p', command '~p' not found.", [Type, Command, Name]).
-%% @doc The following environment variables are exported when running
-%% a hook (absolute paths):
-%%
-%% REBAR_DEPS_DIR = rebar_dir:deps_dir/1
-%% REBAR_BUILD_DIR = rebar_dir:base_dir/1
-%% REBAR_ROOT_DIR = rebar_dir:root_dir/1
-%% REBAR_CHECKOUTS_DIR = rebar_dir:checkouts_dir/1
-%% REBAR_PLUGINS_DIR = rebar_dir:plugins_dir/1
-%% REBAR_GLOBAL_CONFIG_DIR = rebar_dir:global_config_dir/1
-%% REBAR_GLOBAL_CACHE_DIR = rebar_dir:global_cache_dir/1
-%% REBAR_TEMPLATE_DIR = rebar_dir:template_dir/1
-%% REBAR_APP_DIRS = rebar_dir:lib_dirs/1
-%% REBAR_SRC_DIRS = rebar_dir:src_dirs/1
-%%
-%% autoconf compatible variables
-%% (see: http://www.gnu.org/software/autoconf/manual/autoconf.html#Erlang-Libraries):
-%% ERLANG_ERTS_VER = erlang:system_info(version)
-%% ERLANG_ROOT_DIR = code:root_dir/0
-%% ERLANG_LIB_DIR_erl_interface = code:lib_dir(erl_interface)
-%% ERLANG_LIB_VER_erl_interface = version part of path returned by code:lib_dir(erl_interface)
-%% ERL = ERLANG_ROOT_DIR/bin/erl
-%% ERLC = ERLANG_ROOT_DIR/bin/erl
-%%
run_hooks(Dir, pre, Command, Opts, State) ->
run_hooks(Dir, pre_hooks, Command, Opts, State);
run_hooks(Dir, post, Command, Opts, State) ->
@@ -94,7 +70,7 @@ run_hooks(Dir, Type, Command, Opts, State) ->
?DEBUG("run_hooks(~p, ~p, ~p) -> no hooks defined\n", [Dir, Type, Command]),
ok;
Hooks ->
- Env = create_env(State, Opts),
+ Env = rebar_env:create_env(State, Opts),
lists:foreach(fun({_, C, _}=Hook) when C =:= Command ->
apply_hook(Dir, Env, Hook);
({C, _}=Hook) when C =:= Command ->
@@ -114,36 +90,3 @@ apply_hook(Dir, Env, {Arch, Command, Hook}) ->
apply_hook(Dir, Env, {Command, Hook}) ->
Msg = lists:flatten(io_lib:format("Hook for ~p failed!~n", [Command])),
rebar_utils:sh(Hook, [use_stdout, {cd, Dir}, {env, Env}, {abort_on_error, Msg}]).
-
-create_env(State, Opts) ->
- BaseDir = rebar_dir:base_dir(State),
- [
- {"REBAR_DEPS_DIR", filename:absname(rebar_dir:deps_dir(State))},
- {"REBAR_BUILD_DIR", filename:absname(rebar_dir:base_dir(State))},
- {"REBAR_ROOT_DIR", filename:absname(rebar_dir:root_dir(State))},
- {"REBAR_CHECKOUTS_DIR", filename:absname(rebar_dir:checkouts_dir(State))},
- {"REBAR_PLUGINS_DIR", filename:absname(rebar_dir:plugins_dir(State))},
- {"REBAR_GLOBAL_CONFIG_DIR", filename:absname(rebar_dir:global_config_dir(State))},
- {"REBAR_GLOBAL_CACHE_DIR", filename:absname(rebar_dir:global_cache_dir(Opts))},
- {"REBAR_TEMPLATE_DIR", filename:absname(rebar_dir:template_dir(State))},
- {"REBAR_APP_DIRS", join_dirs(BaseDir, rebar_dir:lib_dirs(State))},
- {"REBAR_SRC_DIRS", join_dirs(BaseDir, rebar_dir:all_src_dirs(Opts))},
- {"ERLANG_ERTS_VER", erlang:system_info(version)},
- {"ERLANG_ROOT_DIR", code:root_dir()},
- {"ERLANG_LIB_DIR_erl_interface", code:lib_dir(erl_interface)},
- {"ERLANG_LIB_VER_erl_interface", re_version(code:lib_dir(erl_interface))},
- {"ERL", filename:join([code:root_dir(), "bin", "erl"])},
- {"ERLC", filename:join([code:root_dir(), "bin", "erlc"])},
- {"ERLANG_ARCH" , rebar_api:wordsize()},
- {"ERLANG_TARGET", rebar_api:get_arch()}
-
- ].
-
-join_dirs(BaseDir, Dirs) ->
- string:join([ filename:join(BaseDir, Dir) || Dir <- Dirs ], ":").
-
-re_version(Path) ->
- case re:run(Path, "^.*-(?<VER>[^/-]*)$", [{capture, [1], list}]) of
- nomatch -> "";
- {match, [Ver]} -> Ver
- end.