Преглед изворни кода

Merge pull request #461 from erocci/master

Add excluded_apps rebar.config keyword
pull/477/head
Tristan Sloughter пре 10 година
родитељ
комит
fe181f950d
2 измењених фајлова са 69 додато и 7 уклоњено
  1. +20
    -7
      src/rebar_app_discover.erl
  2. +49
    -0
      test/rebar_disable_app_SUITE.erl

+ 20
- 7
src/rebar_app_discover.erl Прегледај датотеку

@ -20,13 +20,19 @@ do(State, LibDirs) ->
%% Sort apps so we get the same merged deps config everytime
SortedApps = rebar_utils:sort_deps(Apps),
lists:foldl(fun(AppInfo, StateAcc) ->
{AppInfo1, StateAcc1} = merge_deps(AppInfo, StateAcc),
Name = rebar_app_info:name(AppInfo),
OutDir = filename:join(DepsDir, Name),
AppInfo2 = rebar_app_info:out_dir(AppInfo1, OutDir),
ProjectDeps1 = lists:delete(Name, ProjectDeps),
rebar_state:project_apps(StateAcc1
,rebar_app_info:deps(AppInfo2, ProjectDeps1))
Name = rebar_app_info:name(AppInfo),
case enable(State, AppInfo) of
true ->
{AppInfo1, StateAcc1} = merge_deps(AppInfo, StateAcc),
OutDir = filename:join(DepsDir, Name),
AppInfo2 = rebar_app_info:out_dir(AppInfo1, OutDir),
ProjectDeps1 = lists:delete(Name, ProjectDeps),
rebar_state:project_apps(StateAcc1
,rebar_app_info:deps(AppInfo2, ProjectDeps1));
false ->
?INFO("Ignoring ~s", [Name]),
StateAcc
end
end, State, SortedApps).
format_error({module_list, File}) ->
@ -211,3 +217,10 @@ try_handle_app_src_file(_, AppDir, [File], Validate) when Validate =:= invalid
end;
try_handle_app_src_file(_, _AppDir, Other, _Validate) ->
throw({error, {multiple_app_files, Other}}).
enable(State, AppInfo) ->
not lists:member(to_atom(rebar_app_info:name(AppInfo)),
rebar_state:get(State, excluded_apps, [])).
to_atom(Bin) ->
list_to_atom(binary_to_list(Bin)).

+ 49
- 0
test/rebar_disable_app_SUITE.erl Прегледај датотеку

@ -0,0 +1,49 @@
-module(rebar_disable_app_SUITE).
-compile(export_all).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-define(MOD(Name),
io_lib:format("-module(~s).~n-export([x/0]).~nx() -> ok.~n", [Name])).
all() -> [disable_app].
init_per_testcase(_, Config) ->
rebar_test_utils:init_rebar_state(Config).
end_per_testcase(_, _Config) ->
ok.
disable_app(Config) ->
AppDir = ?config(apps, Config),
Name1 = create_random_app(AppDir, "app1_"),
Name2 = create_random_app(AppDir, "app2_"),
RebarConfig = [{excluded_apps, [list_to_atom(Name1)]}],
%RebarConfig = [],
rebar_test_utils:run_and_check(
Config, RebarConfig, ["compile"],
{ok, [{app, Name2}]}),
App1 = filename:join([AppDir, "_build", "default", "lib", Name1, "ebin", Name1 ++ ".app"]),
?assertEqual(filelib:is_file(App1), false),
App2 = filename:join([AppDir, "_build", "default", "lib", Name2, "ebin", Name2 ++ ".app"]),
?assertEqual(filelib:is_file(App2), true).
%%
%% Utils
%%
create_random_app(AppDir, Prefix) ->
Name = rebar_test_utils:create_random_name(Prefix),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_empty_app(filename:join([AppDir, "apps", Name]), Name, Vsn, [kernel, stdlib]),
ModName = rebar_test_utils:create_random_name("mod1_"),
Mod = filename:join([AppDir, "apps", Name, "src", ModName ++ ".erl"]),
ok = filelib:ensure_dir(Mod),
Src = ?MOD(ModName),
ok = ec_file:write(Mod, Src),
Name.

Loading…
Откажи
Сачувај