浏览代码

Merge pull request #852 from tsloughter/no_profile

print a warning if a profile in 'as' has no config entry
pull/856/head
Fred Hebert 9 年前
父节点
当前提交
a74eb69a83
共有 2 个文件被更改,包括 44 次插入2 次删除
  1. +12
    -0
      src/rebar_prv_as.erl
  2. +32
    -2
      test/rebar_as_SUITE.erl

+ 12
- 0
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))].

+ 32
- 2
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).

正在加载...
取消
保存