Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new 'shell_hooks_env' config to extend shell hooks' OS env vars #2830

Merged
merged 2 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/rebar/src/rebar_env.erl
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ create_env(State, Opts) ->
{"ERLANG_TARGET", rebar_api:get_arch()}
],
EInterfaceVars = create_erl_interface_env(),
lists:append([EnvVars, EInterfaceVars]).
ConfigVars = rebar_state:get(State, shell_hooks_env, []),
lists:append([EnvVars, EInterfaceVars, ConfigVars]).

-spec create_erl_interface_env() -> list().
create_erl_interface_env() ->
Expand Down
19 changes: 18 additions & 1 deletion apps/rebar/test/rebar_hooks_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ all() ->
[build_and_clean_app, run_hooks_once, run_hooks_once_profiles,
escriptize_artifacts, run_hooks_for_plugins, deps_hook_namespace,
bare_compile_hooks_default_ns, deps_clean_hook_namespace, eunit_app_hooks,
sub_app_hooks, root_hooks, drop_hook_args].
sub_app_hooks, root_hooks, drop_hook_args, env_vars_in_hooks].

%% Test post provider hook cleans compiled project app, leaving it invalid
build_and_clean_app(Config) ->
Expand Down Expand Up @@ -265,3 +265,20 @@ drop_hook_args(Config) ->
Config, RebarConfig, ["eunit", "--cover=false"],
{ok, []}
).

% Test that env vars are accessible from the hooks
env_vars_in_hooks(Config) ->
AppDir = ?config(apps, Config),

Name = rebar_test_utils:create_random_name("app1_"),
Vsn = rebar_test_utils:create_random_vsn(),

HookFile = filename:join([?config(priv_dir, Config), "my-hook.txt"]),
RebarConfig = [
{shell_hooks_env, [{"VAR", HookFile}]},
{pre_hooks, [{compile, "echo test > $VAR"}]}
],
rebar_test_utils:create_config(AppDir, RebarConfig),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
rebar_test_utils:run_and_check(Config, RebarConfig, ["compile"],
{ok, [{app, Name, valid}, {file, HookFile}]}).