-
Notifications
You must be signed in to change notification settings - Fork 23
/
rebar.config.script
138 lines (122 loc) · 4.74 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
%%% eturnal STUN/TURN server.
%%%
%%% Copyright (c) 2020-2023 Holger Weiss <[email protected]>.
%%% Copyright (c) 2020-2023 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.
Find =
fun(K, L) ->
lists:keyfind(K, 1, L)
end,
Store =
fun(K, V, L) ->
lists:keystore(K, 1, L, {K, V})
end,
Delete =
fun(K, L) ->
lists:keydelete(K, 1, L)
end,
AddSuffix =
fun(N, S) ->
list_to_atom(atom_to_list(N) ++ [$_ | atom_to_list(S)])
end,
%% If any of the build.config settings are overridden via environment variables,
%% create a .build.config file and point Relx to that one.
{ok, OldSettings} = file:consult("build.config"),
NewSettings =
lists:map(
fun({K, V}) ->
EnvKey = string:uppercase(atom_to_list(K)),
case os:getenv(EnvKey) of
EnvVal when is_list(EnvVal) ->
{K, EnvVal};
false ->
{K, V}
end
end, OldSettings),
OldOverlayVars = "build.config",
NewOverlayVars = ".build.config",
OverlayVars =
case {lists:sort(OldSettings), lists:sort(NewSettings)} of
{Settings, Settings} ->
_ = file:delete(NewOverlayVars),
OldOverlayVars;
{_, _} ->
NewData = [io_lib:format("~p.~n", [S]) || S <- NewSettings],
ok = file:write_file(NewOverlayVars, NewData),
NewOverlayVars
end,
{profiles, Profiles} = Find(profiles, CONFIG),
Profiles1 =
lists:map(
fun({ProfName, ProfOpts} = Profile) ->
case Find(relx, ProfOpts) of
{relx, RelxOpts} ->
RelxOpts1 = Store(overlay_vars, OverlayVars, RelxOpts),
ProfOpts1 = Store(relx, RelxOpts1, ProfOpts),
{ProfName, ProfOpts1};
false ->
Profile
end
end, Profiles),
%% For each profile with a 'relx' configuration specified in the rebar.config
%% file, generate three additional profiles. E.g., for the 'prod' profile:
%%
%% - The 'prod_minimal' profile excludes non-essential dependencies.
%% - The 'prod_cross' profile includes ERTS and system libraries from the
%% "lib/erlang" directory (for cross compilation).
%% - The 'prod_cross_minimal' does both.
Profiles2 =
lists:flatmap(
fun({ProfName, ProfOpts} = Profile) ->
case Find(relx, ProfOpts) of
{relx, RelxOpts} ->
InclErts = "lib/erlang",
InclLibs = "lib/erlang/lib",
ExclApps = case Find(exclude_apps, RelxOpts) of
{exclude_apps, Apps} ->
[sasl, recon | Apps];
false ->
[sasl, recon]
end,
ProfName1 = AddSuffix(ProfName, cross),
ProfName2 = AddSuffix(ProfName, minimal),
ProfName3 = AddSuffix(ProfName1, minimal),
RelxOpts0 = Store(include_erts, InclErts, RelxOpts),
RelxOpts1 = Store(system_libs, InclLibs, RelxOpts0),
RelxOpts2 = Store(exclude_apps, ExclApps, RelxOpts),
RelxOpts3 = Store(exclude_apps, ExclApps, RelxOpts1),
ProfOpts1 = Store(relx, RelxOpts1, ProfOpts),
ProfOpts2 = Store(relx, RelxOpts2, ProfOpts),
ProfOpts3 = Store(relx, RelxOpts3, ProfOpts),
[Profile,
{ProfName1, ProfOpts1},
{ProfName2, ProfOpts2},
{ProfName3, ProfOpts3}];
false ->
[Profile]
end
end, Profiles1),
Config1 = Store(profiles, Profiles2, CONFIG),
%% Remove the rebar.lock file and set SKIP_DEPS=true to skip dependency
%% handling.
case os:getenv("SKIP_DEPS") of
"true" ->
SkipOpts = [deps, plugins],
lists:foldl(fun(Opt, Acc) ->
Delete(Opt, Acc)
end, Config1, SkipOpts);
_ ->
Config1
end.