forked from processone/xmpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebar.config.script
195 lines (178 loc) · 6.05 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
%%%----------------------------------------------------------------------
%%% File : rebar.config.script
%%% Author : Mickael Remond <[email protected]>
%%% Purpose : Rebar build script. Compliant with rebar and rebar3.
%%% Created : 24 Nov 2015 by Mickael Remond <[email protected]>
%%%
%%% Copyright (C) 2002-2021 ProcessOne, SARL. All Rights Reserved.
%%%
%%% Licensed under the Apache License, Version 2.0 (the "License");
%%% you may not use this file except in compliance with the License.
%%% You may obtain a copy of the License at
%%%
%%% http://www.apache.org/licenses/LICENSE-2.0
%%%
%%% Unless required by applicable law or agreed to in writing, software
%%% distributed under the License is distributed on an "AS IS" BASIS,
%%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
%%% See the License for the specific language governing permissions and
%%% limitations under the License.
%%%
%%%----------------------------------------------------------------------
Cfg = case file:consult(filename:join([filename:dirname(SCRIPT),"vars.config"])) of
{ok, Terms} ->
Terms;
_Err ->
[]
end ++ [{cflags, "-g -O2 -Wall"}, {ldflags, ""}, {with_gcov, "false"}],
{cflags, CfgCFlags} = lists:keyfind(cflags, 1, Cfg),
{ldflags, CfgLDFlags} = lists:keyfind(ldflags, 1, Cfg),
{with_gcov, CfgWithGCov} = lists:keyfind(with_gcov, 1, Cfg),
SysVersion = lists:map(fun erlang:list_to_integer/1,
string:tokens(erlang:system_info(version), ".")),
IsRebar3 = case application:get_key(rebar, vsn) of
{ok, VSN} ->
[VSN1 | _] = string:tokens(VSN, "-"),
[Maj|_] = string:tokens(VSN1, "."),
(list_to_integer(Maj) >= 3);
undefined ->
lists:keymember(mix, 1, application:loaded_applications())
end,
ModCfg0 = fun(F, Cfg, [Key|Tail], Op, Default) ->
{OldVal,PartCfg} = case lists:keytake(Key, 1, Cfg) of
{value, {_, V1}, V2} -> {V1, V2};
false -> {if Tail == [] -> Default; true -> [] end, Cfg}
end,
case Tail of
[] ->
[{Key, Op(OldVal)} | PartCfg];
_ ->
[{Key, F(F, OldVal, Tail, Op, Default)} | PartCfg]
end
end,
ModCfg = fun(Cfg, Keys, Op, Default) -> ModCfg0(ModCfg0, Cfg, Keys, Op,
Default) end,
ModCfgS = fun(Cfg, Keys, Val) -> ModCfg0(ModCfg0, Cfg, Keys, fun(_V) ->
Val end, "") end,
FilterConfig = fun(F, Cfg, [{Path, true, ModFun, Default} | Tail]) ->
F(F, ModCfg0(ModCfg0, Cfg, Path, ModFun, Default), Tail);
(F, Cfg, [_ | Tail]) ->
F(F, Cfg, Tail);
(F, Cfg, []) ->
Cfg
end,
AppendStr = fun(Append) ->
fun("") ->
Append;
(Val) ->
Val ++ " " ++ Append
end
end,
AppendList = fun(Append) ->
fun(Val) ->
Val ++ Append
end
end,
Rebar3DepsFilter = fun(DepsList) ->
lists:map(fun({DepName,_, {git,_, {tag,Version}}}) ->
{DepName, Version};
(Dep) ->
Dep
end, DepsList)
end,
GlobalDepsFilter = fun(Deps) ->
DepNames = lists:map(fun({DepName, _, _}) -> DepName;
({DepName, _}) -> DepName
end, Deps),
lists:filtermap(fun(Dep) ->
case code:lib_dir(Dep) of
{error, _} ->
{true,"Unable to locate dep '"++atom_to_list(Dep)++"' in system deps."};
_ ->
false
end
end, DepNames)
end,
ResolveDepPath = case IsRebar3 of
true ->
fun("deps/" ++ Rest) ->
Slash = string:str(Rest, "/"),
"_build/default/lib/" ++
string:sub_string(Rest, 1, Slash - 1) ++
string:sub_string(Rest, Slash);
(Path) ->
Path
end;
_ ->
fun(P) ->
P
end
end,
ProcessErlOpt = fun(Vals) ->
lists:map(
fun({i, Path}) ->
{i, ResolveDepPath(Path)};
(ErlOpt) ->
ErlOpt
end, Vals)
end,
GithubConfig = case {os:getenv("GITHUB_ACTIONS"), os:getenv("GITHUB_TOKEN")} of
{"true", Token} when is_list(Token) ->
CONFIG1 = [{coveralls_repo_token, Token},
{coveralls_service_job_id, os:getenv("GITHUB_RUN_ID")},
{coveralls_commit_sha, os:getenv("GITHUB_SHA")},
{coveralls_service_number, os:getenv("GITHUB_RUN_NUMBER")}],
case os:getenv("GITHUB_EVENT_NAME") =:= "pull_request"
andalso string:tokens(os:getenv("GITHUB_REF"), "/") of
[_, "pull", PRNO, _] ->
[{coveralls_service_pull_request, PRNO} | CONFIG1];
_ ->
CONFIG1
end;
_ ->
[]
end,
Rules = [
{[port_env, "CFLAGS"], SysVersion >= [7, 3],
AppendStr("-DHAS_ERTS_EXIT"), "$CFLAGS"},
{[port_env, "CFLAGS"], true,
AppendStr(CfgCFlags), "$CFLAGS"},
{[port_env, "LDFLAGS"], true,
AppendStr(CfgLDFlags), "$LDFLAGS"},
{[post_hooks], (not IsRebar3) and (CfgWithGCov == "true"),
AppendList([{eunit, "gcov -o c_src jid xmpp_lang xmpp_uri"},
{eunit, "mv *.gcov .eunit/"}]), []},
{[post_hooks], IsRebar3 and (CfgWithGCov == "true"),
AppendList([{eunit, "gcov -o c_src jid xmpp_lang xmpp_uri"},
{eunit, "mv *.gcov _build/test/cover/"}]), []},
{[port_env, "LDFLAGS"], CfgWithGCov == "true",
AppendStr("--coverage"), ""},
{[port_env, "CFLAGS"], CfgWithGCov == "true",
AppendStr("--coverage"), ""},
{[deps], IsRebar3,
Rebar3DepsFilter, []},
{[plugins], IsRebar3,
AppendList([pc, provider_asn1]), []},
{[provider_hooks], IsRebar3,
AppendList([{pre, [
{compile, {pc, compile}},
{clean, {pc, clean}},
{compile, {asn, compile}},
{clean, {asn, clean}}
]}]), []},
{[plugins], os:getenv("COVERALLS") == "true",
AppendList([{coveralls, {git,
"https://github.com/processone/coveralls-erl.git",
{branch, "addjsonfile"}}} ]), []},
{[deps], os:getenv("USE_GLOBAL_DEPS") /= false,
GlobalDepsFilter, []},
{[erl_opts], true,
ProcessErlOpt, []}
],
Config = FilterConfig(FilterConfig, CONFIG, Rules) ++ GithubConfig,
%io:format("Rules:~n~p~n~nCONFIG:~n~p~n~nConfig:~n~p~n", [Rules, CONFIG, Config]),
Config.
%% Local Variables:
%% mode: erlang
%% End:
%% vim: set filetype=erlang tabstop=8: