summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_prv_as.erl12
-rw-r--r--test/rebar_as_SUITE.erl34
2 files changed, 44 insertions, 2 deletions
diff --git a/src/rebar_prv_as.erl b/src/rebar_prv_as.erl
index ead7b01..b4f7ac4 100644
--- a/src/rebar_prv_as.erl
+++ b/src/rebar_prv_as.erl
@@ -37,6 +37,7 @@ do(State) ->
[] ->
{error, "At least one profile must be specified when using `as`"};
_ ->
+ warn_on_empty_profile(Profiles, State),
State1 = rebar_state:apply_profiles(State, [list_to_atom(X) || X <- Profiles]),
State2 = rebar_plugins:project_apps_install(State1),
{FirstTask, FirstTaskArgs} = hd(Tasks),
@@ -89,3 +90,14 @@ comma_or_end(["," ++ Profile|Rest], Acc) ->
profiles([Profile|Rest], Acc);
comma_or_end(Tasks, Acc) ->
{lists:reverse(Acc), rebar_utils:args_to_tasks(Tasks)}.
+
+%% If a profile is used by 'as' but has no entry under `profile` within
+%% the top level rebar.config or any project app's rebar.config print a warning.
+%% This is just to help developers, in case they forgot to define a profile but
+%% thought it was being used.
+warn_on_empty_profile(Profiles, State) ->
+ ProjectApps = rebar_state:project_apps(State),
+ DefinedProfiles = rebar_state:get(State, profiles, []) ++
+ lists:flatten([rebar_app_info:get(AppInfo, profiles, []) || AppInfo <- ProjectApps]),
+ [?WARN("No entry for profile ~s in config.", [Profile]) ||
+ Profile <- Profiles, not(lists:keymember(list_to_atom(Profile), 1, DefinedProfiles))].
diff --git a/test/rebar_as_SUITE.erl b/test/rebar_as_SUITE.erl
index 1d1112b..99c7e30 100644
--- a/test/rebar_as_SUITE.erl
+++ b/test/rebar_as_SUITE.erl
@@ -12,7 +12,8 @@
as_comma_placement/1,
as_comma_then_space/1,
as_dir_name/1,
- as_with_task_args/1]).
+ as_with_task_args/1,
+ warn_on_empty_profile/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
@@ -30,7 +31,8 @@ init_per_testcase(_, Config) ->
all() -> [as_basic, as_multiple_profiles, as_multiple_tasks,
as_multiple_profiles_multiple_tasks,
as_comma_placement, as_comma_then_space,
- as_dir_name, as_with_task_args].
+ as_dir_name, as_with_task_args,
+ warn_on_empty_profile].
as_basic(Config) ->
AppDir = ?config(apps, Config),
@@ -136,3 +138,31 @@ as_with_task_args(Config) ->
[],
["as", "default", "clean", "-a"],
{ok, [{app, Name, invalid}]}).
+
+
+warn_on_empty_profile(Config) ->
+ AppDir = ?config(apps, Config),
+
+ Name = rebar_test_utils:create_random_name("as_warn_empty_"),
+ Vsn = rebar_test_utils:create_random_vsn(),
+ rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
+
+ meck:new(rebar_log, [passthrough]),
+ rebar_test_utils:run_and_check(Config,
+ [],
+ ["as", "fake1,fake2", "compile"],
+ {ok, [{app, Name}]}),
+ History = meck:history(rebar_log),
+ ?assert(warn_match("fake1", History)),
+ ?assert(warn_match("fake2", History)),
+ meck:unload(rebar_log),
+ ok.
+
+warn_match(App, History) ->
+ lists:any(
+ fun({_, {rebar_log,log, [warn, "No entry for profile ~s in config.",
+ [ArgApp]]}, _}) -> ArgApp =:= App
+ ; (_) ->
+ false
+ end,
+ History).