From 4033e65aaa53dc6f46e9d1d7fcbfee0dcccac487 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Thu, 15 Aug 2019 16:48:25 +0100 Subject: Fix formatting of literal expression within comment --- src/rebar_dir.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index aac6210..3190425 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -45,7 +45,7 @@ profile_dir(Opts, Profiles) -> ["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 + %% 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, -- cgit v1.1 From 10974bb9d5199fdbe1340d141f9a6add95aecf90 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Thu, 15 Aug 2019 20:38:04 +0100 Subject: Support `profile_string` overlay variable in releases --- src/rebar_dir.erl | 32 +++++++++++++++++++++++--------- src/rebar_relx.erl | 10 ++++++++-- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 3190425..8cdf196 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -3,6 +3,7 @@ -export([base_dir/1, profile_dir/2, + profile_dir_name/1, deps_dir/1, deps_dir/2, root_dir/1, @@ -39,18 +40,31 @@ 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"]}; + 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 %% 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 %% given the current profile. diff --git a/src/rebar_relx.erl b/src/rebar_relx.erl index 431e1bc..996c0a3 100644 --- a/src/rebar_relx.erl +++ b/src/rebar_relx.erl @@ -27,10 +27,12 @@ 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 @@ -38,14 +40,18 @@ do(Module, Command, Provider, State) -> [] -> 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} -- cgit v1.1 From 7311fb2429c1395e40bc20d1894061fda2e3a2f2 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Sat, 31 Aug 2019 18:31:54 +0100 Subject: Add test coverage of `profile_string` overlay variable usage in releases --- test/rebar_release_SUITE.erl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/rebar_release_SUITE.erl b/test/rebar_release_SUITE.erl index 1bcc61e..1785a97 100644 --- a/test/rebar_release_SUITE.erl +++ b/test/rebar_release_SUITE.erl @@ -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), @@ -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"])). -- cgit v1.1 From 7bbc4678597b9a95156ec15bd78af2e794112e85 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Sat, 31 Aug 2019 18:33:58 +0100 Subject: Indulge in self-aggrandizement --- THANKS | 1 + 1 file changed, 1 insertion(+) diff --git a/THANKS b/THANKS index 095a48b..3cccd19 100644 --- a/THANKS +++ b/THANKS @@ -143,3 +143,4 @@ Drew Varner Niklas Johansson Bryan Paxton Justin Wood +Guilherme Andrade -- cgit v1.1 From 8412c684f9b4a33c18c234c1b4c7d50185e66971 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Sun, 1 Sep 2019 23:45:51 +0100 Subject: Don't export internal function definition --- src/rebar_dir.erl | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 8cdf196..54e910d 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -47,13 +47,16 @@ profile_dir(Opts, Profiles) -> [global | _] -> ?MODULE:global_cache_dir(Opts); [_|_] -> rebar_opts:get(Opts, base_dir, ?DEFAULT_BASE_DIR) end, - DirName = profile_dir_name(Profiles), + 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) +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" | _] -> ""; @@ -62,9 +65,7 @@ profile_dir_name(Profiles) %% drop `default' from the profile dir if it's implicit and reverse order %% of profiles to match order passed to `as` ["default"|NonDefaultNames] -> rebar_string:join(NonDefaultNames, "+") - end; -profile_dir_name(State) -> - profile_dir_name(rebar_state:current_profiles(State)). + end. %% @doc returns the directory where dependencies should be placed %% given the current profile. -- cgit v1.1 From 0cb050e93be41afcc0f063d5110a73dcf8fcb176 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Mon, 2 Sep 2019 23:30:43 +0100 Subject: Add missing function spec. --- src/rebar_dir.erl | 1 + 1 file changed, 1 insertion(+) diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 54e910d..6810640 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -52,6 +52,7 @@ profile_dir(Opts, Profiles) -> %% @doc returns the directory name for build artifacts for a given set %% of profiles. +-spec profile_dir_name(rebar_state:t()) -> file:filename_all(). profile_dir_name(State) -> profile_dir_name_(rebar_state:current_profiles(State)). -- cgit v1.1 From df808931cc72348b5375e041e9b2821f660c1ef4 Mon Sep 17 00:00:00 2001 From: Guilherme Andrade Date: Mon, 2 Sep 2019 23:53:57 +0100 Subject: Fix function overspec. --- src/rebar_dir.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 6810640..07d8a2c 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -56,7 +56,7 @@ profile_dir(Opts, Profiles) -> profile_dir_name(State) -> profile_dir_name_(rebar_state:current_profiles(State)). --spec profile_dir_name_([atom(), ...] | rebar_state:t()) -> file:filename_all(). +-spec profile_dir_name_([atom(), ...]) -> file:filename_all(). profile_dir_name_(Profiles) when is_list(Profiles) -> case [rebar_utils:to_list(P) || P <- Profiles] of -- cgit v1.1