summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/rebar_state.erl10
-rw-r--r--test/rebar_profiles_SUITE.erl27
2 files changed, 33 insertions, 4 deletions
diff --git a/src/rebar_state.erl b/src/rebar_state.erl
index 39e0e88..8170b8d 100644
--- a/src/rebar_state.erl
+++ b/src/rebar_state.erl
@@ -15,7 +15,7 @@
command_args/1, command_args/2,
command_parsed_args/1, command_parsed_args/2,
- apply_profiles/2,
+ add_to_profile/3, apply_profiles/2,
dir/1, dir/2,
create_logic_providers/2,
@@ -97,7 +97,6 @@ new(ParentState, Config, Dir) ->
D = proplists:get_value(deps, Config, []),
dict:from_list([{{deps, default}, D} | Config])
end,
-
NewOpts = dict:merge(fun(_Key, Value1, _Value2) ->
Value1
end, LocalOpts, Opts),
@@ -188,6 +187,13 @@ apply_overrides(State=#state_t{overrides=Overrides}, AppName) ->
StateAcc
end, State2, Overrides).
+add_to_profile(State, Profile, KVs) when is_atom(Profile), is_list(KVs) ->
+ Profiles = rebar_state:get(State, profiles, []),
+ ProfileOpts = dict:from_list(proplists:get_value(Profile, Profiles, [])),
+ NewOpts = merge_opts(Profile, dict:from_list(KVs), ProfileOpts),
+ NewProfiles = [{Profile, dict:to_list(NewOpts)}|lists:keydelete(Profile, 1, Profiles)],
+ rebar_state:set(State, profiles, NewProfiles).
+
apply_profiles(State, Profile) when not is_list(Profile) ->
apply_profiles(State, [Profile]);
apply_profiles(State, [default]) ->
diff --git a/test/rebar_profiles_SUITE.erl b/test/rebar_profiles_SUITE.erl
index 03a8090..1411eb6 100644
--- a/test/rebar_profiles_SUITE.erl
+++ b/test/rebar_profiles_SUITE.erl
@@ -7,14 +7,17 @@
all/0,
profile_new_key/1,
profile_merge_keys/1,
- profile_merges/1]).
+ profile_merges/1,
+ add_to_profile/1,
+ add_to_existing_profile/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("kernel/include/file.hrl").
all() ->
- [profile_new_key, profile_merge_keys, profile_merges].
+ [profile_new_key, profile_merge_keys, profile_merges,
+ add_to_profile, add_to_existing_profile].
init_per_suite(Config) ->
application:start(meck),
@@ -106,3 +109,23 @@ profile_merges(_Config) ->
%% Check that a newvalue of []/"" doesn't override non-string oldvalues
[key3] = rebar_state:get(State1, test3),
[] = rebar_state:get(State1, test4).
+
+add_to_profile(_Config) ->
+ RebarConfig = [{foo, true}, {bar, false}],
+ State = rebar_state:new(RebarConfig),
+ State1 = rebar_state:add_to_profile(State, test, [{foo, false}]),
+ State2 = rebar_state:apply_profiles(State1, test),
+
+ Opts = rebar_state:opts(State2),
+ lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar]).
+
+add_to_existing_profile(_Config) ->
+ RebarConfig = [{foo, true}, {bar, false}, {profiles, [
+ {test, [{foo, false}]}
+ ]}],
+ State = rebar_state:new(RebarConfig),
+ State1 = rebar_state:add_to_profile(State, test, [{baz, false}]),
+ State2 = rebar_state:apply_profiles(State1, test),
+
+ Opts = rebar_state:opts(State2),
+ lists:map(fun(K) -> false = dict:fetch(K, Opts) end, [foo, bar, baz]).