forked from rvirding/luerl
-
Notifications
You must be signed in to change notification settings - Fork 1
/
rebar.config.script
92 lines (77 loc) · 3.5 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
%% -*- mode: erlang; indent-tabs-mode: nil -*-
Conf0 = CONFIG, %The original config
%% Do a deep set stepping down a list of keys replacing/adding last
%% with value. Named funs would be nicer but not always available.
SetConf = fun ([K], Val, Ps, _F) ->
%% Replace the whole K field with Val.
[Val|proplists:delete(K, Ps)];
([K|Ks], Val, Ps, F) ->
%% Step down and build coming up.
case lists:keyfind(K, 1, Ps) of
{K,Kps} ->
lists:keyreplace(K, 1, Ps, {K,F(Ks, Val, Kps, F)});
false -> Ps ++ [{K,F(Ks, Val, [], F)}]
end
end,
%% Get the release number.
%% We have stolen the idea and most of the code from rebar3.
OTPRelease =
fun () ->
case erlang:system_info(otp_release) of
[$R,N1|Rest] when is_integer(N1) ->
%% If OTP <= R16, take the digits.
[N1|Rest];
Rel ->
File = filename:join([code:root_dir(),"releases",Rel,"OTP_VERSION"]),
case file:read_file(File) of
{error, _} -> Rel;
{ok, Vsn} ->
Size = byte_size(Vsn),
%% The shortest vsn string consists of at least
%% two digits followed by "\n". Therefore, it's
%% safe to assume Size >= 3.
case binary:part(Vsn, {Size, -3}) of
<<"**\n">> ->
binary:bin_to_list(Vsn, {0, Size - 3});
_ ->
binary:bin_to_list(Vsn, {0, Size - 1})
end
end
end
end,
Version = OTPRelease(),
%% Collect the macro definitions we will add to the compiler options.
%% Collect the macro definitions we will add to the compiler options.
%% Named funs would be nicer but not always available.
AppendCopts = fun (Version, [{Ver,Opt}|Opts], F) ->
Rest = F(Version, Opts, F),
if Version >= Ver ->
[{d,Opt,true}|Rest];
true -> Rest
end;
(_Version, [], _F) -> []
end,
Copts0 = [{d,'ERLANG_VERSION',Version}],
Copts = Copts0 ++ AppendCopts(Version,
[{"17",'HAS_MAPS'},
{"18",'HAS_FULL_KEYS'},
{"19",'NEW_REC_CORE'},
{"19",'NEW_RAND'},
{"20",'NEW_BOOL_GUARD'},
{"20",'HAS_FLOOR'},
{"20",'HAS_CEIL'},
{"21",'NEW_STACKTRACE'}],
AppendCopts),
%% Ensure they are in erl_opts.
Conf1 = case lists:keyfind(erl_opts, 1, Conf0) of
{erl_opts,Opts} -> %Existing erl_opts
NewOpts = {erl_opts,Opts ++ Copts},
lists:keyreplace(erl_opts, 1, Conf0, NewOpts);
false -> %No erl_opts
Conf0 ++ [{erl_opts,Copts}]
end,
TestConfig = [{cover_enabled, true}, {cover_opts, [verbose]}],
Aliases = [{alias, [
{test, [eunit, {ct, "--cover"}, cover]}
]}],
Conf1 ++ TestConfig ++ Aliases.