From 4a2996a7560e12c9897b4a7b333dee3e9fa66347 Mon Sep 17 00:00:00 2001 From: Tristan Sloughter Date: Wed, 4 Mar 2015 10:11:34 -0600 Subject: fix for profiles_remain_applied_with_config_present --- src/rebar_app_discover.erl | 24 +++++++++++++++--------- src/rebar_core.erl | 8 +++----- test/rebar_profiles_SUITE.erl | 28 +++++++++++++++++++++++++--- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/rebar_app_discover.erl b/src/rebar_app_discover.erl index 761c09e..553947a 100644 --- a/src/rebar_app_discover.erl +++ b/src/rebar_app_discover.erl @@ -19,13 +19,13 @@ 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) -> - StateAcc1 = merge_deps(AppInfo, StateAcc), + {AppInfo1, StateAcc1} = merge_deps(AppInfo, StateAcc), Name = rebar_app_info:name(AppInfo), 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), rebar_state:project_apps(StateAcc1 - ,rebar_app_info:deps(AppInfo1, ProjectDeps1)) + ,rebar_app_info:deps(AppInfo2, ProjectDeps1)) end, State, SortedApps). format_error({module_list, File}) -> @@ -37,15 +37,21 @@ merge_deps(AppInfo, State) -> Profiles = rebar_state:current_profiles(State), Name = rebar_app_info:name(AppInfo), C = rebar_config:consult(rebar_app_info:dir(AppInfo)), + AppState = rebar_state:apply_overrides( rebar_state:apply_profiles( 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()). all_app_dirs(LibDirs) -> diff --git a/src/rebar_core.erl b/src/rebar_core.erl index 4497825..205258a 100644 --- a/src/rebar_core.erl +++ b/src/rebar_core.erl @@ -78,14 +78,12 @@ process_command(State, Command) -> Command when Command =:= do; Command =:= as -> do(TargetProviders, State); _ -> - Profiles = providers:profiles(CommandProvider), - State1 = rebar_state:apply_profiles(State, Profiles), 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} -> - 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, io_lib:format("Invalid option ~s on task ~p", [Option, Command])} end diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index 1411eb6..8a1521e 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -9,7 +9,8 @@ profile_merge_keys/1, profile_merges/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("eunit/include/eunit.hrl"). @@ -17,7 +18,8 @@ all() -> [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) -> application:start(meck), @@ -27,7 +29,7 @@ end_per_suite(_Config) -> application:stop(meck). init_per_testcase(_, Config) -> - rebar_test_utils:init_rebar_state(Config). + rebar_test_utils:init_rebar_state(Config, "profiles_"). end_per_testcase(_, Config) -> meck:unload(), @@ -129,3 +131,23 @@ add_to_existing_profile(_Config) -> Opts = rebar_state:opts(State2), 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), [])). -- cgit v1.1