File: rebar.config.script

package info (click to toggle)
rabbitmq-server 4.0.5-8
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 37,972 kB
  • sloc: erlang: 257,835; javascript: 22,466; sh: 3,037; makefile: 2,517; python: 1,966; xml: 646; cs: 335; java: 244; ruby: 212; php: 100; perl: 63; awk: 13
file content (41 lines) | stat: -rw-r--r-- 1,357 bytes parent folder | download | duplicates (2)
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).