-
Notifications
You must be signed in to change notification settings - Fork 16
/
rebar.config.script
73 lines (64 loc) · 2.44 KB
/
rebar.config.script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
%% -*- mode: erlang -*-
%% based on https://github.com/basho/webmachine/commit/a907e90086b39dcddf602e09a9ea1dc57ba675e4
%% Merge the list values in `ToAdd' into the list found at key `Key'
%% in proplist `C'. Don't duplicate items. New Items are added to the
%% front of existing items. It is an error if the value at `Key' is
%% not a list in `C'.
MergeConfig = fun({Key, ToAdd}, C) ->
case lists:keyfind(Key, 1, C) of
false ->
lists:keystore(Key, 1, C, {Key, ToAdd});
{Key, List} when is_list(List) ->
%% remove items in ToAdd already in List
ToAdd1 = [ I || I <- ToAdd, not lists:member(I, List) ],
lists:keystore(Key, 1, C, {Key, ToAdd1 ++ List })
end
end.
FileMarker = fun(RelPath) ->
ConfigPath = filename:dirname(SCRIPT),
Path = filename:join([ConfigPath] ++ RelPath),
filelib:is_file(Path)
end.
EnvMarker = fun(Var) ->
os:getenv(Var) =/= false
end.
%% -- Add development only options if KATT mode is DEV --
%% * add the deps from dev_only_deps defined in rebar.config
%% * define the compiler macro DEV_MODE
DevOnlyConfig = (
fun(true) ->
DevOnlyDeps = case lists:keyfind(dev_only_deps, 1, CONFIG) of
false ->
[];
{dev_only_deps, DOD} ->
DOD
end,
[ {deps, DevOnlyDeps}
, {erl_opts, [ {d, 'DEV_MODE'}
, debug_info
]}
];
(false) ->
[]
end
)(FileMarker([".rebar", "DEV_MODE"]) orelse EnvMarker("KATT_DEV_MODE")).
%% -- Remove optional options if KATT mode is BARE --
%% * remove the deps from optional_deps defined in rebar.config
%% * add the compiler macro BARE_MODE
OptionalConfig = (
fun(false) ->
OptionalDeps = case lists:keyfind(optional_deps, 1, CONFIG) of
false ->
[];
{optional_deps, DOD} ->
DOD
end,
[{deps, OptionalDeps}];
(true) ->
[{erl_opts, [ {d, 'BARE_MODE'}
, debug_info
]}
]
end
)(FileMarker([".rebar", "BARE_MODE"]) orelse EnvMarker("KATT_BARE_MODE")).
lists:foldl(MergeConfig, CONFIG, DevOnlyConfig ++ OptionalConfig).