-
Notifications
You must be signed in to change notification settings - Fork 46
/
rebar.config.script
41 lines (33 loc) · 1.33 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
%% -*- mode: erlang;erlang-indent-level: 2;indent-tabs-mode: nil -*-
%% vim: set ft=erlang ts=2 sw=2:
%% this code is not particularly nice.
%% we fold a list of fun/0's over CONFIG (the rebar.config).
%% If the fun returns 'true', nothing happens,
%% If it returns '{Key, Val}', 'Val' is inserted or appended to the value of 'Key'.
NOW = fun() ->
erlang:is_builtin(erlang, timestamp, 0) orelse {erl_opts, {d, 'USE_NOW'}}
end,
PEER = fun() ->
try not lists:member({start,0}, peer:module_info(exports)) orelse {erl_opts, {d, 'USE_PEER'}}
catch _:_ -> true
end
end,
GITVSN = fun() ->
case os:cmd("(git describe | grep -Eo '^[0-9\.]+' | tr -d '\n') 2>/dev/null") of
[] -> true;
VSN -> {edoc_opts, {def, [{version, VSN}]}}
end
end,
Funs = [NOW, PEER, GITVSN],
%% ================================================
KeyAppend = fun(_, Tag, E, []) -> [{Tag, [E]}];
(_, Tag, E, [{Tag, O}|T]) -> [{Tag, [E|O]}|T];
(G, Tag, E, [H|T]) -> [H|G(G, Tag, E, T)]
end,
Checker = fun(Fun, CFG) ->
case Fun() of
true -> CFG;
{Key, Val} -> KeyAppend(KeyAppend, Key, Val, CFG)
end
end,
lists:foldl(Checker, CONFIG, Funs).