blob: ffdea832be3004544800f15948c7612aa0e167e1 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Patrick Williams92b42cb2022-09-03 06:53:57 -05002# Copyright OpenEmbedded Contributors
3#
Brad Bishopc342db32019-05-15 21:57:59 -04004# SPDX-License-Identifier: MIT
5#
6
Brad Bishopd7bf8c12018-02-25 22:55:05 -05007import os
8import glob
9from oeqa.utils.commands import bitbake, get_bb_vars
10from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -050011
12class Archiver(OESelftestTestCase):
13
Brad Bishopd7bf8c12018-02-25 22:55:05 -050014 def test_archiver_allows_to_filter_on_recipe_name(self):
15 """
16 Summary: The archiver should offer the possibility to filter on the recipe. (#6929)
17 Expected: 1. Included recipe (busybox) should be included
18 2. Excluded recipe (zlib) should be excluded
19 Product: oe-core
20 Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
21 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
22 """
23
Andrew Geissler5a43b432020-06-13 10:46:56 -050024 include_recipe = 'selftest-ed'
25 exclude_recipe = 'initscripts'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050026
27 features = 'INHERIT += "archiver"\n'
28 features += 'ARCHIVER_MODE[src] = "original"\n'
29 features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % include_recipe
30 features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % exclude_recipe
31 self.write_config(features)
32
33 bitbake('-c clean %s %s' % (include_recipe, exclude_recipe))
34 bitbake("-c deploy_archives %s %s" % (include_recipe, exclude_recipe))
35
36 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS'])
37 src_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
38
39 # Check that include_recipe was included
Andrew Geissler5f350902021-07-23 13:09:54 -040040 included_present = len(glob.glob(src_path + '/%s-*/*' % include_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050041 self.assertTrue(included_present, 'Recipe %s was not included.' % include_recipe)
42
43 # Check that exclude_recipe was excluded
Andrew Geissler5f350902021-07-23 13:09:54 -040044 excluded_present = len(glob.glob(src_path + '/%s-*/*' % exclude_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % exclude_recipe)
46
Brad Bishopd7bf8c12018-02-25 22:55:05 -050047 def test_archiver_filters_by_type(self):
48 """
49 Summary: The archiver is documented to filter on the recipe type.
50 Expected: 1. included recipe type (target) should be included
51 2. other types should be excluded
52 Product: oe-core
53 Author: André Draszik <adraszik@tycoint.com>
54 """
55
Andrew Geissler5a43b432020-06-13 10:46:56 -050056 target_recipe = 'selftest-ed'
57 native_recipe = 'selftest-ed-native'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050058
59 features = 'INHERIT += "archiver"\n'
60 features += 'ARCHIVER_MODE[src] = "original"\n'
61 features += 'COPYLEFT_RECIPE_TYPES = "target"\n'
62 self.write_config(features)
63
64 bitbake('-c clean %s %s' % (target_recipe, native_recipe))
65 bitbake("%s -c deploy_archives %s" % (target_recipe, native_recipe))
66
67 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS'])
68 src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
69 src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'])
70
71 # Check that target_recipe was included
Andrew Geissler5f350902021-07-23 13:09:54 -040072 included_present = len(glob.glob(src_path_target + '/%s-*/*' % target_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050073 self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipe)
74
75 # Check that native_recipe was excluded
Andrew Geissler5f350902021-07-23 13:09:54 -040076 excluded_present = len(glob.glob(src_path_native + '/%s-*/*' % native_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050077 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipe)
78
Brad Bishopd7bf8c12018-02-25 22:55:05 -050079 def test_archiver_filters_by_type_and_name(self):
80 """
81 Summary: Test that the archiver archives by recipe type, taking the
82 recipe name into account.
83 Expected: 1. included recipe type (target) should be included
84 2. other types should be excluded
85 3. recipe by name should be included / excluded,
86 overriding previous decision by type
87 Product: oe-core
88 Author: André Draszik <adraszik@tycoint.com>
89 """
90
Andrew Geissler5a43b432020-06-13 10:46:56 -050091 target_recipes = [ 'initscripts', 'selftest-ed' ]
92 native_recipes = [ 'update-rc.d-native', 'selftest-ed-native' ]
Brad Bishopd7bf8c12018-02-25 22:55:05 -050093
94 features = 'INHERIT += "archiver"\n'
95 features += 'ARCHIVER_MODE[src] = "original"\n'
96 features += 'COPYLEFT_RECIPE_TYPES = "target"\n'
97 features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % native_recipes[1]
98 features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % target_recipes[1]
99 self.write_config(features)
100
101 bitbake('-c clean %s %s' % (' '.join(target_recipes), ' '.join(native_recipes)))
102 bitbake('-c deploy_archives %s %s' % (' '.join(target_recipes), ' '.join(native_recipes)))
103
104 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS'])
105 src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
106 src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'])
107
108 # Check that target_recipe[0] and native_recipes[1] were included
Andrew Geissler5f350902021-07-23 13:09:54 -0400109 included_present = len(glob.glob(src_path_target + '/%s-*/*' % target_recipes[0]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500110 self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipes[0])
111
Andrew Geissler5f350902021-07-23 13:09:54 -0400112 included_present = len(glob.glob(src_path_native + '/%s-*/*' % native_recipes[1]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500113 self.assertTrue(included_present, 'Recipe %s was not included.' % native_recipes[1])
114
115 # Check that native_recipes[0] and target_recipes[1] were excluded
Andrew Geissler5f350902021-07-23 13:09:54 -0400116 excluded_present = len(glob.glob(src_path_native + '/%s-*/*' % native_recipes[0]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500117 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipes[0])
118
Andrew Geissler5f350902021-07-23 13:09:54 -0400119 excluded_present = len(glob.glob(src_path_target + '/%s-*/*' % target_recipes[1]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500120 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % target_recipes[1])
Brad Bishop316dfdd2018-06-25 12:45:53 -0400121
122
123
124 def test_archiver_srpm_mode(self):
125 """
126 Test that in srpm mode, the added recipe dependencies at least exist/work [YOCTO #11121]
127 """
128
129 features = 'INHERIT += "archiver"\n'
130 features += 'ARCHIVER_MODE[srpm] = "1"\n'
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500131 features += 'PACKAGE_CLASSES = "package_rpm"\n'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400132 self.write_config(features)
133
Andrew Geissler5a43b432020-06-13 10:46:56 -0500134 bitbake('-n selftest-nopackages selftest-ed')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500135
136 def _test_archiver_mode(self, mode, target_file_name, extra_config=None):
Andrew Geissler5a43b432020-06-13 10:46:56 -0500137 target = 'selftest-ed-native'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500138
139 features = 'INHERIT += "archiver"\n'
140 features += 'ARCHIVER_MODE[src] = "%s"\n' % (mode)
141 if extra_config:
142 features += extra_config
143 self.write_config(features)
144
145 bitbake('-c clean %s' % (target))
146 bitbake('-c deploy_archives %s' % (target))
147
Andrew Geissler5a43b432020-06-13 10:46:56 -0500148 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'BUILD_SYS'])
149 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'], '%s-*' % (target))
Andrew Geissler82c905d2020-04-13 13:39:40 -0500150 glob_result = glob.glob(glob_str)
151 self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target))
152
153 archive_path = os.path.join(glob_result[0], target_file_name)
154 self.assertTrue(os.path.exists(archive_path), 'Missing archive file %s' % (target_file_name))
155
156 def test_archiver_mode_original(self):
157 """
158 Test that the archiver works with `ARCHIVER_MODE[src] = "original"`.
159 """
160
161 self._test_archiver_mode('original', 'ed-1.14.1.tar.lz')
162
163 def test_archiver_mode_patched(self):
164 """
165 Test that the archiver works with `ARCHIVER_MODE[src] = "patched"`.
166 """
167
Andrew Geissler595f6302022-01-24 19:11:47 +0000168 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-patched.tar.xz')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500169
170 def test_archiver_mode_configured(self):
171 """
172 Test that the archiver works with `ARCHIVER_MODE[src] = "configured"`.
173 """
174
Andrew Geissler595f6302022-01-24 19:11:47 +0000175 self._test_archiver_mode('configured', 'selftest-ed-native-1.14.1-r0-configured.tar.xz')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500176
177 def test_archiver_mode_recipe(self):
178 """
179 Test that the archiver works with `ARCHIVER_MODE[recipe] = "1"`.
180 """
181
Andrew Geissler595f6302022-01-24 19:11:47 +0000182 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-recipe.tar.xz',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500183 'ARCHIVER_MODE[recipe] = "1"\n')
184
185 def test_archiver_mode_diff(self):
186 """
187 Test that the archiver works with `ARCHIVER_MODE[diff] = "1"`.
188 Exclusions controlled by `ARCHIVER_MODE[diff-exclude]` are not yet tested.
189 """
190
Andrew Geissler5a43b432020-06-13 10:46:56 -0500191 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-diff.gz',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500192 'ARCHIVER_MODE[diff] = "1"\n')
193
194 def test_archiver_mode_dumpdata(self):
195 """
196 Test that the archiver works with `ARCHIVER_MODE[dumpdata] = "1"`.
197 """
198
Andrew Geissler5a43b432020-06-13 10:46:56 -0500199 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-showdata.dump',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500200 'ARCHIVER_MODE[dumpdata] = "1"\n')
201
202 def test_archiver_mode_mirror(self):
203 """
204 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"`.
205 """
206
207 self._test_archiver_mode('mirror', 'ed-1.14.1.tar.lz',
208 'BB_GENERATE_MIRROR_TARBALLS = "1"\n')
209
210 def test_archiver_mode_mirror_excludes(self):
211 """
212 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"` and
213 correctly excludes an archive when its URL matches
214 `ARCHIVER_MIRROR_EXCLUDE`.
215 """
216
217 target='selftest-ed'
218 target_file_name = 'ed-1.14.1.tar.lz'
219
220 features = 'INHERIT += "archiver"\n'
221 features += 'ARCHIVER_MODE[src] = "mirror"\n'
222 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
223 features += 'ARCHIVER_MIRROR_EXCLUDE = "${GNU_MIRROR}"\n'
224 self.write_config(features)
225
226 bitbake('-c clean %s' % (target))
227 bitbake('-c deploy_archives %s' % (target))
228
229 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS'])
230 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'], '%s-*' % (target))
231 glob_result = glob.glob(glob_str)
232 self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target))
233
234 archive_path = os.path.join(glob_result[0], target_file_name)
235 self.assertFalse(os.path.exists(archive_path), 'Failed to exclude archive file %s' % (target_file_name))
236
237 def test_archiver_mode_mirror_combined(self):
238 """
239 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"`
240 and `ARCHIVER_MODE[mirror] = "combined"`. Archives for multiple recipes
241 should all end up in the 'mirror' directory.
242 """
243
244 features = 'INHERIT += "archiver"\n'
245 features += 'ARCHIVER_MODE[src] = "mirror"\n'
246 features += 'ARCHIVER_MODE[mirror] = "combined"\n'
247 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
248 features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
249 self.write_config(features)
250
251 for target in ['selftest-ed', 'selftest-hardlink']:
252 bitbake('-c clean %s' % (target))
253 bitbake('-c deploy_archives %s' % (target))
254
255 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'])
256 for target_file_name in ['ed-1.14.1.tar.lz', 'hello.c']:
257 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
258 glob_result = glob.glob(glob_str)
259 self.assertTrue(glob_result, 'Missing archive file %s' % (target_file_name))
Andrew Geissler5a43b432020-06-13 10:46:56 -0500260
261 def test_archiver_mode_mirror_gitsm(self):
262 """
263 Test that the archiver correctly handles git submodules with
264 `ARCHIVER_MODE[src] = "mirror"`.
265 """
266 features = 'INHERIT += "archiver"\n'
267 features += 'ARCHIVER_MODE[src] = "mirror"\n'
268 features += 'ARCHIVER_MODE[mirror] = "combined"\n'
269 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
270 features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
271 self.write_config(features)
272
273 bitbake('-c clean git-submodule-test')
274 bitbake('-c deploy_archives -f git-submodule-test')
275
276 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'])
277 for target_file_name in [
278 'git2_git.yoctoproject.org.git-submodule-test.tar.gz',
279 'git2_git.yoctoproject.org.bitbake-gitsm-test1.tar.gz',
280 'git2_git.yoctoproject.org.bitbake-gitsm-test2.tar.gz',
281 'git2_git.openembedded.org.bitbake.tar.gz'
282 ]:
283 target_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
284 self.assertTrue(os.path.exists(target_path))
285
286 def test_archiver_mode_mirror_gitsm_shallow(self):
287 """
288 Test that the archiver correctly handles git submodules with
289 `ARCHIVER_MODE[src] = "mirror"`.
290 """
291 features = 'INHERIT += "archiver"\n'
292 features += 'ARCHIVER_MODE[src] = "mirror"\n'
293 features += 'ARCHIVER_MODE[mirror] = "combined"\n'
294 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
295 features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
296 features += 'BB_GIT_SHALLOW = "1"\n'
297 features += 'BB_GENERATE_SHALLOW_TARBALLS = "1"\n'
298 features += 'DL_DIR = "${TOPDIR}/downloads-shallow"\n'
299 self.write_config(features)
300
301 bitbake('-c clean git-submodule-test')
302 bitbake('-c deploy_archives -f git-submodule-test')
303
304 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'])
305 for target_file_name in [
306 'gitsmshallow_git.yoctoproject.org.git-submodule-test_a2885dd-1_master.tar.gz',
307 'gitsmshallow_git.yoctoproject.org.bitbake-gitsm-test1_bare_120f4c7-1.tar.gz',
308 'gitsmshallow_git.yoctoproject.org.bitbake-gitsm-test2_bare_f66699e-1.tar.gz',
309 'gitsmshallow_git.openembedded.org.bitbake_bare_52a144a-1.tar.gz',
310 'gitsmshallow_git.openembedded.org.bitbake_bare_c39b997-1.tar.gz'
311 ]:
312 target_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
313 self.assertTrue(os.path.exists(target_path))