-
Notifications
You must be signed in to change notification settings - Fork 60
/
rebar.config.script
86 lines (75 loc) · 2.65 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
%% -*- mode: erlang;erlang-indent-level: 4;indent-tabs-mode: nil -*-
%% ex: ts=4 sw=4 ft=erlang et
%%
%% We will add the location of the OTP patched modules based on the
%% OTP version
Vsn = erlang:system_info(otp_release),
%% CONFIG is a special variable injected by rebar3.
Eqwalizer =
case os:getenv("PARTISAN_EQWALIZER", false) of
Var when Var == "1" orelse Var == "true" ->
true;
_ ->
false
end,
%% Dynamically adds the Partisan OTP sources to the src_dirs configuration key,
%% based on the OTP version.
SetSrcDirs = fun
(V, Acc) when V >= "24" ->
Default = ["src"],
SrcDirs =
case lists:keyfind(src_dirs, 1, Acc) of
{src_dirs, Val} ->
Val ++ ["priv/otp/24"];
false ->
Default ++ ["priv/otp/24"]
end,
lists:keystore(src_dirs, 1, Acc, {src_dirs, SrcDirs});
(V, _) ->
exit("OTP version " ++ V ++ " not supported by Partisan.")
end,
%% Adds Eqwalizer support only if Vsn >= "25".
%% We do this as the Eqwalizer executable doesn't allow us to use a separate
%% rebar3 profile.
MaybeEqwalizerSupport = fun
(V, Acc0) when V >= "25" ->
{profiles, Profiles0} = lists:keyfind(profiles, 1, Acc0),
{test, Test0} = lists:keyfind(test, 1, Profiles0),
{deps, Deps0} = lists:keyfind(deps, 1, Test0),
Deps = Deps0 ++ [
{eqwalizer_support,
{
git_subdir,
"https://github.com/whatsapp/eqwalizer.git",
{tag, "v0.17.16"},
"eqwalizer_support"
}
}
],
Test = lists:keystore(deps, 1, Test0, {deps, Deps}),
Profiles = lists:keystore(test, 1, Profiles0, {test, Test}),
Acc1 = lists:keystore(profiles, 1, Acc0, {profiles, Profiles}),
{project_plugins, Plugs0} = lists:keyfind(project_plugins, 1, Acc1),
Plugs = Plugs0 ++ [
{eqwalizer_rebar3,
{
git_subdir,
"https://github.com/whatsapp/eqwalizer.git",
{branch, "main"},
"eqwalizer_rebar3"
}
}
],
lists:keystore(deps, 1, Acc1, {project_plugins, Plugs});
(_, Acc) ->
Acc
end,
case Eqwalizer of
true ->
%% We do not want to add OTP sources as we are not modifying those
%% sources to fix eqwalizer warnings, so that the diff between the
%% original and ours is just due to partisan requirements.
MaybeEqwalizerSupport(Vsn, SetSrcDirs(Vsn, CONFIG));
false ->
SetSrcDirs(Vsn, CONFIG)
end.