ソースを参照

`add_to_profile/3` function added to `rebar_state`

pull/201/head
alisdair sullivan 10年前
コミット
12726111bc
2個のファイルの変更33行の追加4行の削除
  1. +8
    -2
      src/rebar_state.erl
  2. +25
    -2
      test/rebar_profiles_SUITE.erl

+ 8
- 2
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]) ->

+ 25
- 2
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]).

読み込み中…
キャンセル
保存