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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
|
%%% @author Tristan Sloughter <[email protected]>
%%% @copyright (C) 2015, Tristan Sloughter
-module(rlx_archive_SUITE).
-export([suite/0,
init_per_suite/1,
end_per_suite/1,
init_per_testcase/2,
all/0,
basic_tar/1,
exclude_erts/1,
exclude_src/1,
include_src/1]).
-include_lib("common_test/include/ct.hrl").
-include_lib("eunit/include/eunit.hrl").
-include_lib("kernel/include/file.hrl").
suite() ->
[{timetrap, {seconds, 30}}].
init_per_suite(Config) ->
Config.
end_per_suite(_Config) ->
ok.
init_per_testcase(_, Config) ->
DataDir = proplists:get_value(data_dir, Config),
LibDir1 = filename:join([DataDir, rlx_test_utils:create_random_name("lib_dir1_")]),
ok = rlx_util:mkdir_p(LibDir1),
State = rlx_state:new([], [{lib_dirs, [LibDir1]}], [release]),
{ok, State1} = rlx_config:do(State),
[{lib1, LibDir1},
{state, State1} | Config].
all() ->
[basic_tar, exclude_erts, exclude_src, include_src].
basic_tar(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
[(fun({Name, Vsn}) ->
rlx_test_utils:create_app(LibDir1, Name, Vsn, [kernel, stdlib], [])
end)(App)
||
App <-
[{rlx_test_utils:create_random_name("lib_app1_"), rlx_test_utils:create_random_vsn()}
|| _ <- lists:seq(1, 100)]],
rlx_test_utils:create_app(LibDir1, "goal_app_1", "0.0.1", [stdlib,kernel,non_goal_1], []),
rlx_test_utils:create_app(LibDir1, "lib_dep_1", "0.0.1", [stdlib,kernel], []),
rlx_test_utils:create_app(LibDir1, "goal_app_2", "0.0.1", [stdlib,kernel,goal_app_1,non_goal_2], []),
rlx_test_utils:create_app(LibDir1, "non_goal_1", "0.0.1", [stdlib,kernel], [lib_dep_1]),
rlx_test_utils:create_app(LibDir1, "non_goal_2", "0.0.1", [stdlib,kernel], []),
ConfigFile = filename:join([LibDir1, "relx.config"]),
rlx_test_utils:write_config(ConfigFile,
[{release, {foo, "0.0.1"},
[goal_app_1,
goal_app_2]}]),
OutputDir = filename:join([proplists:get_value(data_dir, Config),
rlx_test_utils:create_random_name("relx-output")]),
{ok, State} = relx:do([{relname, foo},
{relvsn, "0.0.1"},
{goals, []},
{lib_dirs, [LibDir1]},
{log_level, 3},
{output_dir, OutputDir},
{config, ConfigFile}], ["release", "tar"]),
[{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
AppSpecs = rlx_release:applications(Release),
?assert(lists:keymember(stdlib, 1, AppSpecs)),
?assert(lists:keymember(kernel, 1, AppSpecs)),
?assert(lists:member({non_goal_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({non_goal_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)),
TarFile = filename:join([OutputDir, "foo", "foo-0.0.1.tar.gz"]),
{ok, Files} = erl_tar:table(TarFile, [compressed]),
?assert(lists:any(fun(X) -> re:run(X, "lib/stdlib-.*/ebin/.*") =/= nomatch end, Files)),
?assert(lists:any(fun(X) -> re:run(X, "lib/kernel-.*/ebin/.*") =/= nomatch end, Files)),
?assert(filelib:is_regular(TarFile)).
exclude_erts(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
[(fun({Name, Vsn}) ->
rlx_test_utils:create_app(LibDir1, Name, Vsn, [kernel, stdlib], [])
end)(App)
||
App <-
[{rlx_test_utils:create_random_name("lib_app1_"), rlx_test_utils:create_random_vsn()}
|| _ <- lists:seq(1, 100)]],
rlx_test_utils:create_app(LibDir1, "goal_app_1", "0.0.1", [stdlib,kernel,non_goal_1], []),
rlx_test_utils:create_app(LibDir1, "lib_dep_1", "0.0.1", [stdlib,kernel], []),
rlx_test_utils:create_app(LibDir1, "goal_app_2", "0.0.1", [stdlib,kernel,goal_app_1,non_goal_2], []),
rlx_test_utils:create_app(LibDir1, "non_goal_1", "0.0.1", [stdlib,kernel], [lib_dep_1]),
rlx_test_utils:create_app(LibDir1, "non_goal_2", "0.0.1", [stdlib,kernel], []),
ConfigFile = filename:join([LibDir1, "relx.config"]),
rlx_test_utils:write_config(ConfigFile,
[{release, {foo, "0.0.1"},
[goal_app_1,
goal_app_2]}]),
OutputDir = filename:join([proplists:get_value(data_dir, Config),
rlx_test_utils:create_random_name("relx-output")]),
{ok, State} = relx:do([{relname, foo},
{relvsn, "0.0.1"},
{goals, []},
{lib_dirs, [LibDir1]},
{log_level, 3},
{output_dir, OutputDir},
{config, ConfigFile},
{include_erts, false},
{system_libs, false}], ["release", "tar"]),
[{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
AppSpecs = rlx_release:applications(Release),
?assert(lists:keymember(stdlib, 1, AppSpecs)),
?assert(lists:keymember(kernel, 1, AppSpecs)),
?assert(lists:member({non_goal_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({non_goal_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)),
TarFile = filename:join([OutputDir, "foo", "foo-0.0.1.tar.gz"]),
{ok, Files} = erl_tar:table(TarFile, [compressed]),
?assert(lists:all(fun(X) -> re:run(X, "lib/stdlib-.*/ebin/.*") =:= nomatch end, Files)),
?assert(lists:all(fun(X) -> re:run(X, "lib/kernel-.*/ebin/.*") =:= nomatch end, Files)),
?assert(filelib:is_regular(TarFile)).
exclude_src(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
[(fun({Name, Vsn}) ->
rlx_test_utils:create_app(LibDir1, Name, Vsn, [kernel, stdlib], [])
end)(App)
||
App <-
[{rlx_test_utils:create_random_name("lib_app1_"), rlx_test_utils:create_random_vsn()}
|| _ <- lists:seq(1, 100)]],
rlx_test_utils:create_app(LibDir1, "goal_app_1", "0.0.1", [stdlib,kernel,non_goal_1], []),
rlx_test_utils:create_app(LibDir1, "lib_dep_1", "0.0.1", [stdlib,kernel], []),
rlx_test_utils:create_app(LibDir1, "goal_app_2", "0.0.1", [stdlib,kernel,goal_app_1,non_goal_2], []),
rlx_test_utils:create_app(LibDir1, "non_goal_1", "0.0.1", [stdlib,kernel], [lib_dep_1]),
rlx_test_utils:create_app(LibDir1, "non_goal_2", "0.0.1", [stdlib,kernel], []),
ConfigFile = filename:join([LibDir1, "relx.config"]),
rlx_test_utils:write_config(ConfigFile,
[{release, {foo, "0.0.1"},
[goal_app_1,
goal_app_2]},
{include_src, false}]),
OutputDir = filename:join([proplists:get_value(data_dir, Config),
rlx_test_utils:create_random_name("relx-output")]),
{ok, State} = relx:do([{relname, foo},
{relvsn, "0.0.1"},
{goals, []},
{lib_dirs, [LibDir1]},
{log_level, 3},
{output_dir, OutputDir},
{config, ConfigFile}], ["release", "tar"]),
[{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
AppSpecs = rlx_release:applications(Release),
?assert(lists:keymember(stdlib, 1, AppSpecs)),
?assert(lists:keymember(kernel, 1, AppSpecs)),
?assert(lists:member({non_goal_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({non_goal_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)),
TarFile = filename:join([OutputDir, "foo", "foo-0.0.1.tar.gz"]),
{ok, Files} = erl_tar:table(TarFile, [compressed]),
?assert(lists:any(fun(X) -> re:run(X, "lib/stdlib-.*/src/.*") =:= nomatch end, Files)),
?assert(lists:any(fun(X) -> re:run(X, "lib/kernel-.*/src/.*") =:= nomatch end, Files)),
?assert(filelib:is_regular(TarFile)).
include_src(Config) ->
LibDir1 = proplists:get_value(lib1, Config),
[(fun({Name, Vsn}) ->
rlx_test_utils:create_app(LibDir1, Name, Vsn, [kernel, stdlib], [])
end)(App)
||
App <-
[{rlx_test_utils:create_random_name("lib_app1_"), rlx_test_utils:create_random_vsn()}
|| _ <- lists:seq(1, 100)]],
rlx_test_utils:create_app(LibDir1, "goal_app_1", "0.0.1", [stdlib,kernel,non_goal_1], []),
rlx_test_utils:create_app(LibDir1, "lib_dep_1", "0.0.1", [stdlib,kernel], []),
rlx_test_utils:create_app(LibDir1, "goal_app_2", "0.0.1", [stdlib,kernel,goal_app_1,non_goal_2], []),
rlx_test_utils:create_app(LibDir1, "non_goal_1", "0.0.1", [stdlib,kernel], [lib_dep_1]),
rlx_test_utils:create_app(LibDir1, "non_goal_2", "0.0.1", [stdlib,kernel], []),
ConfigFile = filename:join([LibDir1, "relx.config"]),
rlx_test_utils:write_config(ConfigFile,
[{release, {foo, "0.0.1"},
[goal_app_1,
goal_app_2]}]),
OutputDir = filename:join([proplists:get_value(data_dir, Config),
rlx_test_utils:create_random_name("relx-output")]),
{ok, State} = relx:do([{relname, foo},
{relvsn, "0.0.1"},
{goals, []},
{lib_dirs, [LibDir1]},
{log_level, 3},
{output_dir, OutputDir},
{config, ConfigFile}], ["release", "tar"]),
[{{foo, "0.0.1"}, Release}] = ec_dictionary:to_list(rlx_state:realized_releases(State)),
AppSpecs = rlx_release:applications(Release),
?assert(lists:keymember(stdlib, 1, AppSpecs)),
?assert(lists:keymember(kernel, 1, AppSpecs)),
?assert(lists:member({non_goal_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({non_goal_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_1, "0.0.1"}, AppSpecs)),
?assert(lists:member({goal_app_2, "0.0.1"}, AppSpecs)),
?assert(lists:member({lib_dep_1, "0.0.1", load}, AppSpecs)),
TarFile = filename:join([OutputDir, "foo", "foo-0.0.1.tar.gz"]),
{ok, Files} = erl_tar:table(TarFile, [compressed]),
?assert(lists:any(fun(X) -> re:run(X, "lib/stdlib-.*/src/.*") =/= nomatch end, Files)),
?assert(lists:any(fun(X) -> re:run(X, "lib/kernel-.*/src/.*") =/= nomatch end, Files)),
?assert(filelib:is_regular(TarFile)).
|