-
Notifications
You must be signed in to change notification settings - Fork 428
/
rebar.config.script
88 lines (78 loc) · 2.77 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
os:putenv("EXOMETER_PACKAGES", "(minimal)"),
MaybeReadFromConfig =
fun ({ok, Content}) ->
Parts = binary:split(Content, <<"\n">>, [global]),
%% find only this line which starts with "export APPS="
[Apps] = [Item || <<"export APPS=\"",Item/binary>> <- Parts],
%% remove trailing " and conver to string
binary_to_list(binary:part(Apps, 0, size(Apps) - 1));
(_) ->
io:format("WARNING! The configure.out file was not created, using minimal configuration~n"),
""
end,
ReadFromConfig =
fun(Path) ->
case filelib:is_file(Path) of
true ->
MaybeReadFromConfig(file:read_file(Path));
_ ->
Script = filename:join(["tools", "configure"]),
os:cmd(Script ++ " with-all without-jingle-sip"),
MaybeReadFromConfig(file:read_file("configure.out"))
end
end,
GetEnvApps =
fun() ->
case os:getenv("APPS") of
false ->
ConfigurePath = "configure.out",
ReadFromConfig(ConfigurePath);
EnvApps ->
EnvApps
end
end,
DevAppsToInclude =
fun() ->
case os:getenv("DEVNODE") of
false -> [];
_ -> [meck]
end
end,
FirstApps = [kernel],
RequiredApps = [mongooseim, inets, tools, compiler],
OptionalApps = [{nksip, [nkservice, nkpacket, nklib]}],
EnvApps = GetEnvApps(),
PrepareApp =
fun(App) ->
case lists:keyfind(App, 1, OptionalApps) of
false ->
[App];
{App, DepsOfApp} ->
lists:map(fun(V) -> {V, load} end, [App | DepsOfApp])
end
end,
SetupIncludedApps =
fun(Config, EnvApps) ->
RelxCfg = proplists:get_value(relx, Config),
{release, Desc, _Apps} = lists:keyfind(release, 1, RelxCfg),
EnvAppsToInclude = [ list_to_atom(App) || App <- string:tokens(EnvApps, " \n\r") ],
AppsToIncludeIn = lists:usort(RequiredApps ++ DevAppsToInclude() ++ EnvAppsToInclude),
Apps = lists:subtract(AppsToIncludeIn, FirstApps),
NewReleaseCfg = {release, Desc, FirstApps ++ lists:flatmap(PrepareApp, Apps)},
NewRelxCfg = lists:keyreplace(release, 1, RelxCfg, NewReleaseCfg),
lists:keyreplace(relx, 1, Config, {relx, NewRelxCfg})
end,
MaybeFIPSSupport = fun(Config) ->
code:ensure_loaded(crypto),
case erlang:function_exported(crypto, info_fips, 0) of
false ->
Config;
_ ->
io:format("compiling with FIPS mode enabled~n"),
{erl_opts, ErlOpts} = lists:keyfind(erl_opts, 1, Config),
NewErlOpts = [{d, fips_mode} | ErlOpts],
lists:keyreplace(erl_opts, 1, Config, {erl_opts, NewErlOpts})
end
end,
Config0 = SetupIncludedApps(CONFIG, EnvApps),
MaybeFIPSSupport(Config0).