From cb14a33fdd9eb7e4bf0cacde52c3027910de34b3 Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Sun, 19 Apr 2015 16:24:43 +0300 Subject: Do not duplicate profile when applying. --- src/rebar_state.erl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/rebar_state.erl b/src/rebar_state.erl index f922977..7d872ee 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -213,8 +213,12 @@ apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Prof lists:foldl(fun(default, {ProfilesAcc, OptsAcc}) -> {ProfilesAcc, OptsAcc}; (Profile, {ProfilesAcc, OptsAcc}) -> + NewProfilesAcc = case lists:member(Profile, CurrentProfiles) of + false -> [Profile]++ProfilesAcc; + true -> ProfilesAcc + end, ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), - {[Profile]++ProfilesAcc, merge_opts(Profile, ProfileOpts, OptsAcc)} + {NewProfilesAcc, merge_opts(Profile, ProfileOpts, OptsAcc)} end, {[], Opts}, Profiles), State#state_t{current_profiles=CurrentProfiles++Profiles1, opts=NewOpts}. -- cgit v1.1 From 381c6f4779a93b50308f2cc86de8a19b23ebcee5 Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Tue, 21 Apr 2015 01:22:28 +0300 Subject: Correctly deduplicate profiles when applying Conflicts: src/rebar_state.erl --- src/rebar_dir.erl | 2 +- src/rebar_state.erl | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/rebar_dir.erl b/src/rebar_dir.erl index 7903ed5..1885e9a 100644 --- a/src/rebar_dir.erl +++ b/src/rebar_dir.erl @@ -29,7 +29,7 @@ base_dir(State) -> ["default"] -> ["default"]; %% drop `default` from the profile dir if it's implicit and reverse order %% of profiles to match order passed to `as` - ["default"|Rest] -> lists:reverse(Rest) + ["default"|Rest] -> Rest end, ProfilesDir = string:join(ProfilesStrings, "+"), filename:join(rebar_state:get(State, base_dir, ?DEFAULT_BASE_DIR), ProfilesDir). diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 7d872ee..22e5497 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -209,18 +209,25 @@ apply_profiles(State, [default]) -> State; apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Profiles) -> ConfigProfiles = rebar_state:get(State, profiles, []), - {Profiles1, NewOpts} = - lists:foldl(fun(default, {ProfilesAcc, OptsAcc}) -> - {ProfilesAcc, OptsAcc}; - (Profile, {ProfilesAcc, OptsAcc}) -> - NewProfilesAcc = case lists:member(Profile, CurrentProfiles) of - false -> [Profile]++ProfilesAcc; - true -> ProfilesAcc - end, + NewOpts = + lists:foldl(fun(default, OptsAcc) -> + OptsAcc; + (Profile, OptsAcc) -> ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), - {NewProfilesAcc, merge_opts(Profile, ProfileOpts, OptsAcc)} - end, {[], Opts}, Profiles), - State#state_t{current_profiles=CurrentProfiles++Profiles1, opts=NewOpts}. + merge_opts(Profile, ProfileOpts, OptsAcc) + end, Opts, Profiles), + State#state_t{current_profiles = deduplicate(CurrentProfiles ++ Profiles), opts=NewOpts}. + +deduplicate(Profiles) -> + do_deduplicate(lists:reverse(Profiles), []). + +do_deduplicate([], Acc) -> + Acc; +do_deduplicate([Head | Rest], Acc) -> + case lists:member(Head, Acc) of + true -> do_deduplicate(Rest, Acc); + false -> do_deduplicate(Rest, [Head | Acc]) + end. merge_opts(Profile, NewOpts, OldOpts) -> Opts = merge_opts(NewOpts, OldOpts), -- cgit v1.1 From b725711d638bef39aa6a2685c3dabd57c80a8024 Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Tue, 21 Apr 2015 22:26:20 +0300 Subject: Implement some test on profiles deduplication --- test/rebar_profiles_SUITE.erl | 65 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index 6288053..e5d0b20 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -7,7 +7,10 @@ all/0, profile_new_key/1, profile_merge_keys/1, + explicit_profile_deduplicate_deps/1, + implicit_profile_deduplicate_deps/1, profile_merges/1, + same_profile_deduplication/1, add_to_profile/1, add_to_existing_profile/1, profiles_remain_applied_with_config_present/1, @@ -22,6 +25,7 @@ all() -> [profile_new_key, profile_merge_keys, profile_merges, + explicit_profile_deduplicate_deps, implitit_profilededuplicate_deps, add_to_profile, add_to_existing_profile, profiles_remain_applied_with_config_present, test_profile_applied_at_completion, @@ -95,6 +99,67 @@ profile_merge_keys(Config) -> ,{dep, "a", "1.0.0"} ,{dep, "b", "2.0.0"}]}). +explicit_profile_deduplicate_deps(Config) -> + AppDir = ?config(apps, Config), + + AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"a", "2.0.0", []} + ,{"b", "1.0.0", []} + ,{"b", "2.0.0", []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]), + + Name = rebar_test_utils:create_random_name("explicit_profile_deduplicate_deps_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + FooDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}, + {"b", "2.0.0", []}])), + BarDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])), + + RebarConfig = [{profiles, + [{foo, + [{deps, FooDeps}]}, + {bar, + [{deps, BarDeps}]}]}], + + rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "bar,foo,bar", "compile"], {ok, [{app, Name} + ,{dep, "a", "1.0.0"} + ,{dep, "b", "1.0.0"}]}). + +implicit_profile_deduplicate_deps(Config) -> + AppDir = ?config(apps, Config), + + AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"a", "2.0.0", []} + ,{"b", "1.0.0", []} + ,{"b", "2.0.0", []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]), + + Name = rebar_test_utils:create_random_name("implicit_profile_deduplicate_deps_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + TestDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}, + {"b", "2.0.0", []}])), + ProfileDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])), + + RebarConfig = [{profiles, + [{test, + [{deps, TestDeps}]}, + {bar, + [{deps, ProfileDeps}]}]}], + + rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "test,bar", "eunit"], {ok, [{app, Name} + ,{dep, "a", "1.0.0"} + ,{dep, "b", "2.0.0"}]}). + + profile_merges(_Config) -> RebarConfig = [{test1, [{key1, 1, 2}, key2]}, {test2, "hello"}, -- cgit v1.1 From 83d738a829fae4547776c87c3c4689cf17e69541 Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Tue, 21 Apr 2015 22:26:20 +0300 Subject: Implement some test on profiles deduplication --- test/rebar_profiles_SUITE.erl | 91 +++++++++++++++++++++++++++++++++++++++++++ test/rebar_utils_SUITE.erl | 24 +++++++++++- 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index 6288053..d1d10c6 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -7,7 +7,10 @@ all/0, profile_new_key/1, profile_merge_keys/1, + explicit_profile_deduplicate_deps/1, + implicit_profile_deduplicate_deps/1, profile_merges/1, + same_profile_deduplication/1, add_to_profile/1, add_to_existing_profile/1, profiles_remain_applied_with_config_present/1, @@ -22,6 +25,8 @@ all() -> [profile_new_key, profile_merge_keys, profile_merges, + explicit_profile_deduplicate_deps, implicit_profile_deduplicate_deps, + same_profile_deduplication, add_to_profile, add_to_existing_profile, profiles_remain_applied_with_config_present, test_profile_applied_at_completion, @@ -95,6 +100,67 @@ profile_merge_keys(Config) -> ,{dep, "a", "1.0.0"} ,{dep, "b", "2.0.0"}]}). +explicit_profile_deduplicate_deps(Config) -> + AppDir = ?config(apps, Config), + + AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"a", "2.0.0", []} + ,{"b", "1.0.0", []} + ,{"b", "2.0.0", []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]), + + Name = rebar_test_utils:create_random_name("explicit_profile_deduplicate_deps_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + FooDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}, + {"b", "2.0.0", []}])), + BarDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])), + + RebarConfig = [{profiles, + [{foo, + [{deps, FooDeps}]}, + {bar, + [{deps, BarDeps}]}]}], + + rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "bar,foo,bar", "compile"], {ok, [{app, Name} + ,{dep, "a", "1.0.0"} + ,{dep, "b", "1.0.0"}]}). + +implicit_profile_deduplicate_deps(Config) -> + AppDir = ?config(apps, Config), + + AllDeps = rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []} + ,{"a", "2.0.0", []} + ,{"b", "1.0.0", []} + ,{"b", "2.0.0", []}]), + mock_git_resource:mock([{deps, rebar_test_utils:flat_deps(AllDeps)}]), + + Name = rebar_test_utils:create_random_name("implicit_profile_deduplicate_deps_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + TestDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"a", "1.0.0", []}, + {"b", "2.0.0", []}])), + ProfileDeps = rebar_test_utils:top_level_deps( + rebar_test_utils:expand_deps(git, [{"b", "1.0.0", []}])), + + RebarConfig = [{profiles, + [{test, + [{deps, TestDeps}]}, + {bar, + [{deps, ProfileDeps}]}]}], + + rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "test,bar", "eunit"], {ok, [{app, Name} + ,{dep, "a", "1.0.0"} + ,{dep, "b", "2.0.0"}]}). + + profile_merges(_Config) -> RebarConfig = [{test1, [{key1, 1, 2}, key2]}, {test2, "hello"}, @@ -127,6 +193,31 @@ profile_merges(_Config) -> [{key5, false}, {key5, true}] = rebar_state:get(State1, test5), [{key6, true}, {key6, false}] = rebar_state:get(State1, test6). +same_profile_deduplication(_Config) -> + RebarConfig = [{test1, [{key1, 1, 2}, key2]}, + {test2, [foo]}, + {test3, [key3]}, + {profiles, + [{profile1, + [{test1, [{key3, 5}, key1]}, + {test2, [bar]}, + {test3, []} + ]}] + }], + State = rebar_state:new(RebarConfig), + State1 = rebar_state:apply_profiles(State, [profile1, profile1, profile1]), + + ?assertEqual([default, profile1], rebar_state:current_profiles(State1)), + %% Combine lists + ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]), + lists:sort(rebar_state:get(State1, test1))), + + + %% Check that a newvalue of []/"" doesn't override non-string oldvalues + ?assertEqual([key3], rebar_state:get(State1, test3)), + ?assertEqual([foo, bar], rebar_state:get(State1, test2)). + + add_to_profile(_Config) -> RebarConfig = [{foo, true}, {bar, false}], State = rebar_state:new(RebarConfig), diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index e9b32e2..9b7bca1 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -21,7 +21,9 @@ task_with_flag_with_trailing_comma/1, task_with_flag_with_commas/1, task_with_multiple_flags/1, - special_task_do/1]). + special_task_do/1, + trivial_umerge/1, + three_tuple_umerge/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -29,7 +31,10 @@ all() -> - [{group, args_to_tasks}]. + [{group, args_to_tasks}, + trivial_umerge, + three_tuple_umerge + ]. groups() -> [{args_to_tasks, [], [empty_arglist, @@ -118,3 +123,18 @@ special_task_do(_Config) -> "do", "bar,", "baz"]). + +trivial_umerge(_Config) -> + New = [{key, foo}], + Old = [{key, bar}], + Result = rebar_utils:tup_umerge(New, Old), + ?assertEqual([{key, foo}], Result). + +three_tuple_umerge(_Config) -> + New = rebar_utils:tup_sort([{d, foo, true}, {d, bar, true}]), + Old = rebar_utils:tup_sort([{d, foo, false}, {d, bar, true}]), + Result = rebar_utils:tup_umerge(New, Old), + ?assertEqual( + rebar_utils:tup_sort([{do, foo, true}, {d, bar, true}]), + Result + ). -- cgit v1.1 From 82b0d4b7b29fe5d33148022be28eab55320f47a9 Mon Sep 17 00:00:00 2001 From: Viacheslav Kovalev Date: Wed, 22 Apr 2015 14:41:39 +0300 Subject: Implement opts umerge deduplication --- src/rebar_state.erl | 1 - src/rebar_utils.erl | 15 +++++++++++- test/rebar_profiles_SUITE.erl | 54 ++++++++++++++++++++++++++++++++++++++----- test/rebar_utils_SUITE.erl | 23 ++++++------------ 4 files changed, 69 insertions(+), 24 deletions(-) diff --git a/src/rebar_state.erl b/src/rebar_state.erl index 22e5497..f73370b 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -231,7 +231,6 @@ do_deduplicate([Head | Rest], Acc) -> merge_opts(Profile, NewOpts, OldOpts) -> Opts = merge_opts(NewOpts, OldOpts), - case dict:find(deps, NewOpts) of {ok, Value} -> dict:store({deps, Profile}, Value, Opts); diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index bc2e4ac..76be9a8 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -257,7 +257,20 @@ tup_sort(List) -> tup_umerge([], Olds) -> Olds; tup_umerge([New|News], Olds) -> - lists:reverse(umerge(News, Olds, [], New)). + reverse_deduplicate( umerge(News, Olds, [], New) ). + +reverse_deduplicate(List) -> + lists:reverse( do_deduplicate(lists:reverse(List), []) ). + +do_deduplicate([], Acc) -> + Acc; +do_deduplicate([Value | Rest], Acc) -> + case lists:member(Value, Acc) of + true -> + do_deduplicate(Rest, Acc); + false -> + do_deduplicate(Rest, [Value | Acc]) + end. %% This is equivalent to umerge2_2 in the stdlib, except we use the expanded %% value/key only to compare diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index d1d10c6..f812793 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -11,6 +11,7 @@ implicit_profile_deduplicate_deps/1, profile_merges/1, same_profile_deduplication/1, + stack_deduplication/1, add_to_profile/1, add_to_existing_profile/1, profiles_remain_applied_with_config_present/1, @@ -26,7 +27,7 @@ all() -> [profile_new_key, profile_merge_keys, profile_merges, explicit_profile_deduplicate_deps, implicit_profile_deduplicate_deps, - same_profile_deduplication, + same_profile_deduplication, stack_deduplication, add_to_profile, add_to_existing_profile, profiles_remain_applied_with_config_present, test_profile_applied_at_completion, @@ -199,7 +200,7 @@ same_profile_deduplication(_Config) -> {test3, [key3]}, {profiles, [{profile1, - [{test1, [{key3, 5}, key1]}, + [{test1, [{key3, 5}, {key2, "hello"}]}, {test2, [bar]}, {test3, []} ]}] @@ -208,15 +209,56 @@ same_profile_deduplication(_Config) -> State1 = rebar_state:apply_profiles(State, [profile1, profile1, profile1]), ?assertEqual([default, profile1], rebar_state:current_profiles(State1)), + Test1 = rebar_state:get(State1, test1), + %% Combine lists - ?assertEqual(lists:sort([key1, key2, {key1, 1, 2}, {key3, 5}]), - lists:sort(rebar_state:get(State1, test1))), + ?assertEqual(lists:sort([key2, {key1, 1, 2}, {key3, 5}, {key2, "hello"}]), + lists:sort(Test1)), + %% Key2 from profile1 overrides key2 from default profile + ?assertEqual("hello", proplists:get_value(key2, Test1)), %% Check that a newvalue of []/"" doesn't override non-string oldvalues ?assertEqual([key3], rebar_state:get(State1, test3)), - ?assertEqual([foo, bar], rebar_state:get(State1, test2)). - + ?assertEqual([bar, foo], rebar_state:get(State1, test2)). + +stack_deduplication(_Config) -> + RebarConfig = [ + {test_key, default}, + {test_list, [ {foo, default} ]}, + {profiles, [ + {a, [ + {test_key, a}, + {test_list, [ {foo, a} ]} + ]}, + {b, [ + {test_key, b}, + {test_list, [ {foo, b} ]} + ]}, + {c, [ + {test_key, c}, + {test_list, [ {foo, c} ]} + ]}, + {d, [ + {test_key, d}, + {test_list, [ {foo, d} ]} + ]}, + {e, [ + {test_key, e}, + {test_list, [ {foo, e} ]} + ]} + ]} + ], + State = rebar_state:new(RebarConfig), + State1 = rebar_state:apply_profiles(State, [a, b, c, d, e, a, e, b]), + ?assertEqual(b, rebar_state:get(State1, test_key)), + + TestList = rebar_state:get(State1, test_list), + ?assertEqual( + [{foo, b}, {foo, e}, {foo, a}, {foo, d}, {foo, c}, {foo, default} ], + TestList + ), + ?assertEqual(b, proplists:get_value(foo, TestList)). add_to_profile(_Config) -> RebarConfig = [{foo, true}, {bar, false}], diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index 9b7bca1..98e7e58 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -22,8 +22,7 @@ task_with_flag_with_commas/1, task_with_multiple_flags/1, special_task_do/1, - trivial_umerge/1, - three_tuple_umerge/1]). + tup_umerge_deduplication/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -32,8 +31,7 @@ all() -> [{group, args_to_tasks}, - trivial_umerge, - three_tuple_umerge + tup_umerge_deduplication ]. groups() -> @@ -124,17 +122,10 @@ special_task_do(_Config) -> "bar,", "baz"]). -trivial_umerge(_Config) -> - New = [{key, foo}], - Old = [{key, bar}], - Result = rebar_utils:tup_umerge(New, Old), - ?assertEqual([{key, foo}], Result). - -three_tuple_umerge(_Config) -> - New = rebar_utils:tup_sort([{d, foo, true}, {d, bar, true}]), - Old = rebar_utils:tup_sort([{d, foo, false}, {d, bar, true}]), - Result = rebar_utils:tup_umerge(New, Old), +tup_umerge_deduplication(_Config) -> + Old = [{key,c},{key,b},{key,a}], + New = [{key, a}], ?assertEqual( - rebar_utils:tup_sort([{do, foo, true}, {d, bar, true}]), - Result + [{key, a}, {key, c}, {key, b}], + rebar_utils:tup_umerge(New, Old) ). -- cgit v1.1 From e255529da5c2366f1a9c4eb823d3c3d02c237eae Mon Sep 17 00:00:00 2001 From: Viacheslav Kovalev Date: Wed, 22 Apr 2015 18:56:09 +0300 Subject: Get rid of rebar_utils:tup_umerge/2 patching --- src/rebar_state.erl | 7 ++++--- src/rebar_utils.erl | 15 +-------------- test/rebar_utils_SUITE.erl | 16 +++------------- 3 files changed, 8 insertions(+), 30 deletions(-) diff --git a/src/rebar_state.erl b/src/rebar_state.erl index f73370b..c2e479d 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -207,7 +207,8 @@ apply_profiles(State, Profile) when not is_list(Profile) -> apply_profiles(State, [Profile]); apply_profiles(State, [default]) -> State; -apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Profiles) -> +apply_profiles(State=#state_t{default = Defaults, current_profiles=CurrentProfiles}, Profiles) -> + AppliedProfiles = deduplicate(CurrentProfiles ++ Profiles), ConfigProfiles = rebar_state:get(State, profiles, []), NewOpts = lists:foldl(fun(default, OptsAcc) -> @@ -215,8 +216,8 @@ apply_profiles(State=#state_t{opts=Opts, current_profiles=CurrentProfiles}, Prof (Profile, OptsAcc) -> ProfileOpts = dict:from_list(proplists:get_value(Profile, ConfigProfiles, [])), merge_opts(Profile, ProfileOpts, OptsAcc) - end, Opts, Profiles), - State#state_t{current_profiles = deduplicate(CurrentProfiles ++ Profiles), opts=NewOpts}. + end, Defaults, AppliedProfiles), + State#state_t{current_profiles = AppliedProfiles, opts=NewOpts}. deduplicate(Profiles) -> do_deduplicate(lists:reverse(Profiles), []). diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 76be9a8..004ed35 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -257,20 +257,7 @@ tup_sort(List) -> tup_umerge([], Olds) -> Olds; tup_umerge([New|News], Olds) -> - reverse_deduplicate( umerge(News, Olds, [], New) ). - -reverse_deduplicate(List) -> - lists:reverse( do_deduplicate(lists:reverse(List), []) ). - -do_deduplicate([], Acc) -> - Acc; -do_deduplicate([Value | Rest], Acc) -> - case lists:member(Value, Acc) of - true -> - do_deduplicate(Rest, Acc); - false -> - do_deduplicate(Rest, [Value | Acc]) - end. + lists:reverse( umerge(News, Olds, [], New) ). %% This is equivalent to umerge2_2 in the stdlib, except we use the expanded %% value/key only to compare diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index 98e7e58..ce26bbc 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -21,8 +21,7 @@ task_with_flag_with_trailing_comma/1, task_with_flag_with_commas/1, task_with_multiple_flags/1, - special_task_do/1, - tup_umerge_deduplication/1]). + special_task_do/1]). -include_lib("common_test/include/ct.hrl"). -include_lib("eunit/include/eunit.hrl"). @@ -30,8 +29,7 @@ all() -> - [{group, args_to_tasks}, - tup_umerge_deduplication + [{group, args_to_tasks} ]. groups() -> @@ -120,12 +118,4 @@ special_task_do(_Config) -> [{"foo", []}, {"do", ["bar,", "baz"]}] = rebar_utils:args_to_tasks(["foo,", "do", "bar,", - "baz"]). - -tup_umerge_deduplication(_Config) -> - Old = [{key,c},{key,b},{key,a}], - New = [{key, a}], - ?assertEqual( - [{key, a}, {key, c}, {key, b}], - rebar_utils:tup_umerge(New, Old) - ). + "baz"]). \ No newline at end of file -- cgit v1.1 From 29a855d31c7fe7fd7504f5d0ec95c9a55e27276f Mon Sep 17 00:00:00 2001 From: "Viacheslav V. Kovalev" Date: Wed, 22 Apr 2015 21:44:23 +0300 Subject: Revert accidentially changed formatting --- src/rebar_state.erl | 1 + src/rebar_utils.erl | 2 +- test/rebar_utils_SUITE.erl | 5 ++--- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/rebar_state.erl b/src/rebar_state.erl index c2e479d..9b8d261 100644 --- a/src/rebar_state.erl +++ b/src/rebar_state.erl @@ -232,6 +232,7 @@ do_deduplicate([Head | Rest], Acc) -> merge_opts(Profile, NewOpts, OldOpts) -> Opts = merge_opts(NewOpts, OldOpts), + case dict:find(deps, NewOpts) of {ok, Value} -> dict:store({deps, Profile}, Value, Opts); diff --git a/src/rebar_utils.erl b/src/rebar_utils.erl index 004ed35..bc2e4ac 100644 --- a/src/rebar_utils.erl +++ b/src/rebar_utils.erl @@ -257,7 +257,7 @@ tup_sort(List) -> tup_umerge([], Olds) -> Olds; tup_umerge([New|News], Olds) -> - lists:reverse( umerge(News, Olds, [], New) ). + lists:reverse(umerge(News, Olds, [], New)). %% This is equivalent to umerge2_2 in the stdlib, except we use the expanded %% value/key only to compare diff --git a/test/rebar_utils_SUITE.erl b/test/rebar_utils_SUITE.erl index ce26bbc..e9b32e2 100644 --- a/test/rebar_utils_SUITE.erl +++ b/test/rebar_utils_SUITE.erl @@ -29,8 +29,7 @@ all() -> - [{group, args_to_tasks} - ]. + [{group, args_to_tasks}]. groups() -> [{args_to_tasks, [], [empty_arglist, @@ -118,4 +117,4 @@ special_task_do(_Config) -> [{"foo", []}, {"do", ["bar,", "baz"]}] = rebar_utils:args_to_tasks(["foo,", "do", "bar,", - "baz"]). \ No newline at end of file + "baz"]). -- cgit v1.1 From 681c8f718971307c267216547ccf859e784a673b Mon Sep 17 00:00:00 2001 From: Fred Hebert Date: Mon, 4 May 2015 00:47:53 +0000 Subject: Adding directory path test for deduplication --- test/rebar_profiles_SUITE.erl | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl index 4154661..b42df39 100644 --- a/test/rebar_profiles_SUITE.erl +++ b/test/rebar_profiles_SUITE.erl @@ -16,6 +16,7 @@ add_to_profile/1, add_to_existing_profile/1, profiles_remain_applied_with_config_present/1, + deduplicated_paths/1, test_profile_applied_at_completion/1, test_profile_applied_before_compile/1, test_profile_applied_before_eunit/1, @@ -31,6 +32,7 @@ all() -> same_profile_deduplication, stack_deduplication, add_to_profile, add_to_existing_profile, profiles_remain_applied_with_config_present, + deduplicated_paths, test_profile_applied_at_completion, test_profile_applied_before_compile, test_profile_applied_before_eunit, @@ -337,6 +339,22 @@ profiles_remain_applied_with_config_present(Config) -> true = lists:member({d, not_ok}, proplists:get_value(options, Mod:module_info(compile), [])). +deduplicated_paths(Config) -> + AppDir = ?config(apps, Config), + + Name = rebar_test_utils:create_random_name("deduplicated_paths_"), + Vsn = rebar_test_utils:create_random_vsn(), + rebar_test_utils:create_app(AppDir, Name, Vsn, [kernel, stdlib]), + + RebarConfig = [], + rebar_test_utils:create_config(AppDir, RebarConfig), + rebar_test_utils:run_and_check(Config, RebarConfig, + ["as", "a,b,c,d,e,a,e,b", "compile"], + {ok, [{app, Name}]}), + + Path = filename:join([AppDir, "_build", "c+d+a+e+b", "lib", Name, "ebin"]), + ?assert(filelib:is_dir(Path)). + test_profile_applied_at_completion(Config) -> AppDir = ?config(apps, Config), -- cgit v1.1