2017-09-26 17:32:37 +02:00
|
|
|
-module(override_opts).
|
|
|
|
-export([preprocess/2]).
|
|
|
|
|
|
|
|
override_opts(override, Config, Opts) ->
|
2018-01-15 12:31:47 +01:00
|
|
|
lists:foldl(fun({Opt, Value}, Conf) ->
|
2017-09-26 17:32:37 +02:00
|
|
|
rebar_config:set(Conf, Opt, Value)
|
|
|
|
end, Config, Opts);
|
|
|
|
override_opts(add, Config, Opts) ->
|
2018-01-15 12:31:47 +01:00
|
|
|
lists:foldl(fun({Opt, Value}, Conf) ->
|
2017-09-26 17:32:37 +02:00
|
|
|
V = rebar_config:get_local(Conf, Opt, []),
|
2018-01-15 12:31:47 +01:00
|
|
|
rebar_config:set(Conf, Opt, V ++ Value)
|
2019-07-12 14:55:01 +02:00
|
|
|
end, Config, Opts);
|
|
|
|
override_opts(del, Config, Opts) ->
|
|
|
|
lists:foldl(fun({Opt, Value}, Conf) ->
|
|
|
|
V = rebar_config:get_local(Conf, Opt, []),
|
|
|
|
rebar_config:set(Conf, Opt, V -- Value)
|
2017-09-26 17:32:37 +02:00
|
|
|
end, Config, Opts).
|
|
|
|
|
|
|
|
preprocess(Config, _Dirs) ->
|
|
|
|
Overrides = rebar_config:get_local(Config, overrides, []),
|
|
|
|
TopOverrides = case rebar_config:get_xconf(Config, top_overrides, []) of
|
|
|
|
[] -> Overrides;
|
|
|
|
Val -> Val
|
|
|
|
end,
|
|
|
|
Config2 = rebar_config:set_xconf(Config, top_overrides, TopOverrides),
|
2017-11-15 09:21:05 +01:00
|
|
|
try
|
|
|
|
Config3 = case rebar_app_utils:load_app_file(Config2, _Dirs) of
|
2017-09-26 17:32:37 +02:00
|
|
|
{ok, C, AppName, _AppData} ->
|
|
|
|
lists:foldl(fun({Type, AppName2, Opts}, Conf1) when
|
|
|
|
AppName2 == AppName ->
|
|
|
|
override_opts(Type, Conf1, Opts);
|
2019-07-12 14:55:01 +02:00
|
|
|
({Type, Opts}, Conf1a) ->
|
|
|
|
override_opts(Type, Conf1a, Opts);
|
2017-09-26 17:32:37 +02:00
|
|
|
(_, Conf2) ->
|
|
|
|
Conf2
|
|
|
|
end, C, TopOverrides);
|
|
|
|
_ ->
|
|
|
|
Config2
|
2017-11-15 09:21:05 +01:00
|
|
|
end,
|
|
|
|
{ok, Config3, []}
|
|
|
|
catch
|
|
|
|
error:badarg -> {ok, Config2, []}
|
|
|
|
end.
|