瀏覽代碼

fix for profiles_remain_applied_with_config_present

pull/219/head
Tristan Sloughter 10 年之前
父節點
當前提交
4a2996a756
共有 3 個文件被更改,包括 43 次插入17 次删除
  1. +15
    -9
      src/rebar_app_discover.erl
  2. +3
    -5
      src/rebar_core.erl
  3. +25
    -3
      test/rebar_profiles_SUITE.erl

+ 15
- 9
src/rebar_app_discover.erl 查看文件

@ -19,13 +19,13 @@ do(State, LibDirs) ->
%% Sort apps so we get the same merged deps config everytime %% Sort apps so we get the same merged deps config everytime
SortedApps = rebar_utils:sort_deps(Apps), SortedApps = rebar_utils:sort_deps(Apps),
lists:foldl(fun(AppInfo, StateAcc) -> lists:foldl(fun(AppInfo, StateAcc) ->
StateAcc1 = merge_deps(AppInfo, StateAcc),
{AppInfo1, StateAcc1} = merge_deps(AppInfo, StateAcc),
Name = rebar_app_info:name(AppInfo), Name = rebar_app_info:name(AppInfo),
OutDir = filename:join(DepsDir, Name), OutDir = filename:join(DepsDir, Name),
AppInfo1 = rebar_app_info:out_dir(AppInfo, OutDir),
AppInfo2 = rebar_app_info:out_dir(AppInfo1, OutDir),
ProjectDeps1 = lists:delete(Name, ProjectDeps), ProjectDeps1 = lists:delete(Name, ProjectDeps),
rebar_state:project_apps(StateAcc1 rebar_state:project_apps(StateAcc1
,rebar_app_info:deps(AppInfo1, ProjectDeps1))
,rebar_app_info:deps(AppInfo2, ProjectDeps1))
end, State, SortedApps). end, State, SortedApps).
format_error({module_list, File}) -> format_error({module_list, File}) ->
@ -37,15 +37,21 @@ merge_deps(AppInfo, State) ->
Profiles = rebar_state:current_profiles(State), Profiles = rebar_state:current_profiles(State),
Name = rebar_app_info:name(AppInfo), Name = rebar_app_info:name(AppInfo),
C = rebar_config:consult(rebar_app_info:dir(AppInfo)), C = rebar_config:consult(rebar_app_info:dir(AppInfo)),
AppState = rebar_state:apply_overrides( AppState = rebar_state:apply_overrides(
rebar_state:apply_profiles( rebar_state:apply_profiles(
rebar_state:new(State, C, rebar_app_info:dir(AppInfo)), Profiles), Name), rebar_state:new(State, C, rebar_app_info:dir(AppInfo)), Profiles), Name),
lists:foldl(fun(Profile, StateAcc) ->
AppProfDeps = rebar_state:get(AppState, {deps, Profile}, []),
TopLevelProfDeps = rebar_state:get(StateAcc, {deps, Profile}, []),
ProfDeps2 = lists:keymerge(1, TopLevelProfDeps, AppProfDeps),
rebar_state:set(StateAcc, {deps, Profile}, ProfDeps2)
end, State, lists:reverse(Profiles)).
AppInfo1 = rebar_app_info:state(AppInfo, AppState),
State1 = lists:foldl(fun(Profile, StateAcc) ->
AppProfDeps = rebar_state:get(AppState, {deps, Profile}, []),
TopLevelProfDeps = rebar_state:get(StateAcc, {deps, Profile}, []),
ProfDeps2 = lists:keymerge(1, TopLevelProfDeps, AppProfDeps),
rebar_state:set(StateAcc, {deps, Profile}, ProfDeps2)
end, State, lists:reverse(Profiles)),
{AppInfo1, State1}.
-spec all_app_dirs(list(file:name())) -> list(file:name()). -spec all_app_dirs(list(file:name())) -> list(file:name()).
all_app_dirs(LibDirs) -> all_app_dirs(LibDirs) ->

+ 3
- 5
src/rebar_core.erl 查看文件

@ -78,14 +78,12 @@ process_command(State, Command) ->
Command when Command =:= do; Command =:= as -> Command when Command =:= do; Command =:= as ->
do(TargetProviders, State); do(TargetProviders, State);
_ -> _ ->
Profiles = providers:profiles(CommandProvider),
State1 = rebar_state:apply_profiles(State, Profiles),
Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(), Opts = providers:opts(CommandProvider)++rebar3:global_option_spec_list(),
case getopt:parse(Opts, rebar_state:command_args(State1)) of
case getopt:parse(Opts, rebar_state:command_args(State)) of
{ok, Args} -> {ok, Args} ->
State2 = rebar_state:command_parsed_args(State1, Args),
do(TargetProviders, State2);
State1 = rebar_state:command_parsed_args(State, Args),
do(TargetProviders, State1);
{error, {invalid_option, Option}} -> {error, {invalid_option, Option}} ->
{error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])} {error, io_lib:format("Invalid option ~s on task ~p", [Option, Command])}
end end

+ 25
- 3
test/rebar_profiles_SUITE.erl 查看文件

@ -9,7 +9,8 @@
profile_merge_keys/1, profile_merge_keys/1,
profile_merges/1, profile_merges/1,
add_to_profile/1, add_to_profile/1,
add_to_existing_profile/1]).
add_to_existing_profile/1,
profiles_remain_applied_with_config_present/1]).
-include_lib("common_test/include/ct.hrl"). -include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl"). -include_lib("eunit/include/eunit.hrl").
@ -17,7 +18,8 @@
all() -> all() ->
[profile_new_key, profile_merge_keys, profile_merges, [profile_new_key, profile_merge_keys, profile_merges,
add_to_profile, add_to_existing_profile].
add_to_profile, add_to_existing_profile,
profiles_remain_applied_with_config_present].
init_per_suite(Config) -> init_per_suite(Config) ->
application:start(meck), application:start(meck),
@ -27,7 +29,7 @@ end_per_suite(_Config) ->
application:stop(meck). application:stop(meck).
init_per_testcase(_, Config) -> init_per_testcase(_, Config) ->
rebar_test_utils:init_rebar_state(Config).
rebar_test_utils:init_rebar_state(Config, "profiles_").
end_per_testcase(_, Config) -> end_per_testcase(_, Config) ->
meck:unload(), meck:unload(),
@ -129,3 +131,23 @@ add_to_existing_profile(_Config) ->
Opts = rebar_state:opts(State2), Opts = rebar_state:opts(State2),
lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar, baz]). lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar, baz]).
profiles_remain_applied_with_config_present(Config) ->
AppDir = ?config(apps, Config),
Name = rebar_test_utils:create_random_name("profiles_remain_applied_"),
Vsn = rebar_test_utils:create_random_vsn(),
rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]),
RebarConfig = [{erl_opts, []}, {profiles, [
{not_ok, [{erl_opts, [{d, not_ok}]}]}
]}],
rebar_test_utils:create_config(AppDir, RebarConfig),
rebar_test_utils:run_and_check(Config, RebarConfig,
["as", "not_ok", "compile"], {ok, [{app, Name}]}),
Mod = list_to_atom("not_a_real_src_" ++ Name),
true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])).

Loading…
取消
儲存