forked from aeternity/aeternity
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rebar.config.script
94 lines (85 loc) · 4.16 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
%% -*- erlang -*-
IsWindows = case os:type() of {win32, _} -> true; {_, _} -> false end,
FilterRocksDbCheck = (IsWindows orelse os:getenv("AE_DISABLE_ROCKSDB") =/= false),
FilterRelxRocksDb = fun(Apps) ->
case FilterRocksDbCheck of
false ->
Apps;
true ->
Apps -- [rocksdb, mnesia_rocksdb, {rocksdb, load}, {mnesia_rocksdb, load}]
end
end,
FilterDepsRocksDb = fun(Deps) ->
case FilterRocksDbCheck of
false ->
Deps;
true ->
lists:foldl(
fun(App, Acc) ->
lists:keydelete(App, 1, Acc)
end,
Deps,
[rocksdb, mnesia_rocksdb]
)
end
end,
%% In order to avoid ugly dynamic module loading over rpc - inject meck into the common test release
%% This does not inject any applications into the system tests, smoke tests and production releases
Args = init:get_plain_arguments(),
IsCommonTestRelease = lists:member("test", Args) and lists:member("release", Args),
AddMeckInCommonTests = fun(Apps) ->
case IsCommonTestRelease of
false ->
Apps;
true ->
[meck] ++ Apps
end
end,
% We check all overlay entries' destinations against these regular expressions,
% and replacement found matches with the corresponding .cmd entry.
OverlayReplacements = [
"^bin/extensions/.*"
],
AdaptOverlayBin = fun(Overlay) ->
case IsWindows of
false ->
Overlay;
true ->
lists:foldl(
fun
({copy, Src0, Dest0}, Acc0) ->
lists:foldl(
fun(Format, Acc1) ->
{ok, Re} = re:compile(Format),
case re:run(Dest0, Re) of
nomatch ->
Acc1;
_ ->
Src = filename:rootname(Src0) ++ ".cmd",
Dest = filename:rootname(Dest0) ++ ".cmd",
lists:keyreplace(Dest0, 3, Acc1, {copy, Src, Dest})
end
end, Acc0, OverlayReplacements);
(_, Acc0) ->
Acc0
end, Overlay, Overlay)
end
end,
%% Update relx config
Relx0 = lists:keyfind(relx, 1, CONFIG),
{relx, [{release, {aeternity, _}, RelxApps0} | RelxT0]} = Relx0,
{overlay, RelxOverlay0} = lists:keyfind(overlay, 1, RelxT0),
RelxT1 = lists:keyreplace(overlay, 1, RelxT0, {overlay, AdaptOverlayBin(RelxOverlay0)}),
%% VERSION file could be missing in some cases i.e. clean target
Version = case file:read_file(<<"VERSION">>) of
{ok, VersionBin} -> string:trim(binary_to_list(VersionBin));
_ -> "UNKNOWN_VERSION"
end,
%% the release should be in front
RelxApps1 = FilterRelxRocksDb(RelxApps0),
RelxApps2 = AddMeckInCommonTests(RelxApps1),
Relx = {relx, [{release, {aeternity, Version}, RelxApps2}] ++ RelxT1},
CONFIG1 = lists:keyreplace(relx, 1, CONFIG, Relx),
%% Update rebar deps
{deps, Deps0} = lists:keyfind(deps, 1, CONFIG1),
lists:keyreplace(deps, 1, CONFIG1, {deps, FilterDepsRocksDb(Deps0)}).