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

Support profile_string overlay var in releases #2155

Merged
merged 7 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from 5 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
1 change: 1 addition & 0 deletions THANKS
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,4 @@ Drew Varner
Niklas Johansson
Bryan Paxton
Justin Wood
Guilherme Andrade
35 changes: 25 additions & 10 deletions src/rebar_dir.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

-export([base_dir/1,
profile_dir/2,
profile_dir_name/1,
deps_dir/1,
deps_dir/2,
root_dir/1,
Expand Down Expand Up @@ -39,18 +40,32 @@ base_dir(State) ->

%% @doc returns the directory root for build artifacts for a given set
%% of profiles.
-spec profile_dir(rebar_dict(), [atom()]) -> file:filename_all().
-spec profile_dir(rebar_dict(), [atom(), ...]) -> file:filename_all().
profile_dir(Opts, Profiles) ->
{BaseDir, ProfilesStrings} = case [rebar_utils:to_list(P) || P <- Profiles] of
["global" | _] -> {?MODULE:global_cache_dir(Opts), [""]};
["bootstrap", "default"] -> {rebar_opts:get(Opts, base_dir, ?DEFAULT_BASE_DIR), ["default"]};
["default"] -> {rebar_opts:get(Opts, base_dir, ?DEFAULT_BASE_DIR), ["default"]};
%% drop `default` from the profile dir if it's implicit and reverse order
BasePath =
case Profiles of
[global | _] -> ?MODULE:global_cache_dir(Opts);
[_|_] -> rebar_opts:get(Opts, base_dir, ?DEFAULT_BASE_DIR)
end,
DirName = profile_dir_name_(Profiles),
filename:join(BasePath, DirName).

%% @doc returns the directory name for build artifacts for a given set
%% of profiles.
profile_dir_name(State) ->
profile_dir_name_(rebar_state:current_profiles(State)).

-spec profile_dir_name_([atom(), ...] | rebar_state:t()) -> file:filename_all().
profile_dir_name_(Profiles)
when is_list(Profiles) ->
case [rebar_utils:to_list(P) || P <- Profiles] of
["global" | _] -> "";
["bootstrap", "default"] -> "default";
["default"] -> "default";
%% drop `default' from the profile dir if it's implicit and reverse order
%% of profiles to match order passed to `as`
["default"|Rest] -> {rebar_opts:get(Opts, base_dir, ?DEFAULT_BASE_DIR), Rest}
end,
ProfilesDir = rebar_string:join(ProfilesStrings, "+"),
filename:join(BaseDir, ProfilesDir).
["default"|NonDefaultNames] -> rebar_string:join(NonDefaultNames, "+")
end.

%% @doc returns the directory where dependencies should be placed
%% given the current profile.
Expand Down
10 changes: 8 additions & 2 deletions src/rebar_relx.erl
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,31 @@ do(Module, Command, Provider, State) ->
LibDirs = rebar_utils:filtermap(fun ec_file:exists/1,
[rebar_dir:checkouts_dir(State), DepsDir | ProjectAppDirs]),
OutputDir = filename:join(rebar_dir:base_dir(State), ?DEFAULT_RELEASE_DIR),
ProfileString = rebar_dir:profile_dir_name(State),
AllOptions = rebar_string:join([Command | Options], " "),
Cwd = rebar_state:dir(State),
Providers = rebar_state:providers(State),
RebarOpts = rebar_state:opts(State),
ExtraOverlays = [{profile_string, ProfileString}],
ErlOpts = rebar_opts:erl_opts(RebarOpts),
rebar_hooks:run_project_and_app_hooks(Cwd, pre, Provider, Providers, State),
try
case rebar_state:get(State, relx, []) of
[] ->
relx:main([{lib_dirs, LibDirs}
,{caller, api}
,{log_level, LogLevel} | output_dir(OutputDir, Options)] ++ ErlOpts, AllOptions);
,{log_level, LogLevel}
,{api_caller_overlays, ExtraOverlays}
| output_dir(OutputDir, Options)] ++ ErlOpts, AllOptions);
Config ->
Config1 = [{overlay_vars, [{base_dir, rebar_dir:base_dir(State)}]}
| merge_overlays(Config)],
relx:main([{lib_dirs, LibDirs}
,{config, Config1}
,{caller, api}
,{log_level, LogLevel} | output_dir(OutputDir, Options)] ++ ErlOpts, AllOptions)
,{log_level, LogLevel}
,{api_caller_overlays, ExtraOverlays}
| output_dir(OutputDir, Options)] ++ ErlOpts, AllOptions)
end,
rebar_hooks:run_project_and_app_hooks(Cwd, post, Provider, Providers, State),
{ok, State}
Expand Down
6 changes: 4 additions & 2 deletions test/rebar_release_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ overlay_vars(Config) ->
{var_bin_string, {{{var_bin_string}}}},
{var_tuple, {{{var_tuple}}}},
{var_list, {{{var_list}}}},
{var_bin, {{{var_bin}}}}]],
{var_bin, {{{var_bin}}}},
{var_profile_string, {{profile_string}}}]], % this comes from `rebar3'
rebar_test_utils:create_config(AppDir,
filename:join([AppDir, "config", "app.config"]),
AppConfig),
Expand All @@ -318,6 +319,7 @@ overlay_vars(Config) ->
{var_bin_string, <<"test">>},
{var_tuple, {t, ['atom']}},
{var_list, [a, b, c, 'd']},
{var_bin, <<23, 24, 25>>}],
{var_bin, <<23, 24, 25>>},
{var_profile_string, 'default'}],
{ok, [ExpectedSysconfig]} = file:consult(filename:join([AppDir, "_build/default/rel",
Name, "releases", Vsn, "sys.config"])).