Browse Source

Support `profile_string` overlay variable in releases

pull/2155/head
Guilherme Andrade 5 years ago
parent
commit
10974bb9d5
2 changed files with 31 additions and 11 deletions
  1. +23
    -9
      src/rebar_dir.erl
  2. +8
    -2
      src/rebar_relx.erl

+ 23
- 9
src/rebar_dir.erl View File

@ -3,6 +3,7 @@
-export([base_dir/1, -export([base_dir/1,
profile_dir/2, profile_dir/2,
profile_dir_name/1,
deps_dir/1, deps_dir/1,
deps_dir/2, deps_dir/2,
root_dir/1, root_dir/1,
@ -39,18 +40,31 @@ base_dir(State) ->
%% @doc returns the directory root for build artifacts for a given set %% @doc returns the directory root for build artifacts for a given set
%% of profiles. %% of profiles.
-spec profile_dir(rebar_dict(), [atom()]) -> file:filename_all().
-spec profile_dir(rebar_dict(), [atom(), ...]) -> file:filename_all().
profile_dir(Opts, Profiles) -> 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"]};
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.
-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 %% drop `default' from the profile dir if it's implicit and reverse order
%% of profiles to match order passed to `as` %% 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;
profile_dir_name(State) ->
profile_dir_name(rebar_state:current_profiles(State)).
%% @doc returns the directory where dependencies should be placed %% @doc returns the directory where dependencies should be placed
%% given the current profile. %% given the current profile.

+ 8
- 2
src/rebar_relx.erl View File

@ -27,10 +27,12 @@ do(Module, Command, Provider, State) ->
LibDirs = rebar_utils:filtermap(fun ec_file:exists/1, LibDirs = rebar_utils:filtermap(fun ec_file:exists/1,
[rebar_dir:checkouts_dir(State), DepsDir | ProjectAppDirs]), [rebar_dir:checkouts_dir(State), DepsDir | ProjectAppDirs]),
OutputDir = filename:join(rebar_dir:base_dir(State), ?DEFAULT_RELEASE_DIR), OutputDir = filename:join(rebar_dir:base_dir(State), ?DEFAULT_RELEASE_DIR),
ProfileString = rebar_dir:profile_dir_name(State),
AllOptions = rebar_string:join([Command | Options], " "), AllOptions = rebar_string:join([Command | Options], " "),
Cwd = rebar_state:dir(State), Cwd = rebar_state:dir(State),
Providers = rebar_state:providers(State), Providers = rebar_state:providers(State),
RebarOpts = rebar_state:opts(State), RebarOpts = rebar_state:opts(State),
ExtraOverlays = [{profile_string, ProfileString}],
ErlOpts = rebar_opts:erl_opts(RebarOpts), ErlOpts = rebar_opts:erl_opts(RebarOpts),
rebar_hooks:run_project_and_app_hooks(Cwd, pre, Provider, Providers, State), rebar_hooks:run_project_and_app_hooks(Cwd, pre, Provider, Providers, State),
try try
@ -38,14 +40,18 @@ do(Module, Command, Provider, State) ->
[] -> [] ->
relx:main([{lib_dirs, LibDirs} relx:main([{lib_dirs, LibDirs}
,{caller, api} ,{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 -> Config ->
Config1 = [{overlay_vars, [{base_dir, rebar_dir:base_dir(State)}]} Config1 = [{overlay_vars, [{base_dir, rebar_dir:base_dir(State)}]}
| merge_overlays(Config)], | merge_overlays(Config)],
relx:main([{lib_dirs, LibDirs} relx:main([{lib_dirs, LibDirs}
,{config, Config1} ,{config, Config1}
,{caller, api} ,{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, end,
rebar_hooks:run_project_and_app_hooks(Cwd, post, Provider, Providers, State), rebar_hooks:run_project_and_app_hooks(Cwd, post, Provider, Providers, State),
{ok, State} {ok, State}

Loading…
Cancel
Save