blob: 0194ae9f69c54f8e395c8ed43ad0310740be0e0b [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
2# SPDX-License-Identifier: MIT
3#
4
Brad Bishopd7bf8c12018-02-25 22:55:05 -05005import os
6import glob
7from oeqa.utils.commands import bitbake, get_bb_vars
8from oeqa.selftest.case import OESelftestTestCase
Brad Bishopd7bf8c12018-02-25 22:55:05 -05009
10class Archiver(OESelftestTestCase):
11
Brad Bishopd7bf8c12018-02-25 22:55:05 -050012 def test_archiver_allows_to_filter_on_recipe_name(self):
13 """
14 Summary: The archiver should offer the possibility to filter on the recipe. (#6929)
15 Expected: 1. Included recipe (busybox) should be included
16 2. Excluded recipe (zlib) should be excluded
17 Product: oe-core
18 Author: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
19 AutomatedBy: Daniel Istrate <daniel.alexandrux.istrate@intel.com>
20 """
21
Andrew Geissler5a43b432020-06-13 10:46:56 -050022 include_recipe = 'selftest-ed'
23 exclude_recipe = 'initscripts'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050024
25 features = 'INHERIT += "archiver"\n'
26 features += 'ARCHIVER_MODE[src] = "original"\n'
27 features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % include_recipe
28 features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % exclude_recipe
29 self.write_config(features)
30
31 bitbake('-c clean %s %s' % (include_recipe, exclude_recipe))
32 bitbake("-c deploy_archives %s %s" % (include_recipe, exclude_recipe))
33
34 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS'])
35 src_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
36
37 # Check that include_recipe was included
Andrew Geissler5f350902021-07-23 13:09:54 -040038 included_present = len(glob.glob(src_path + '/%s-*/*' % include_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050039 self.assertTrue(included_present, 'Recipe %s was not included.' % include_recipe)
40
41 # Check that exclude_recipe was excluded
Andrew Geissler5f350902021-07-23 13:09:54 -040042 excluded_present = len(glob.glob(src_path + '/%s-*/*' % exclude_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050043 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % exclude_recipe)
44
Brad Bishopd7bf8c12018-02-25 22:55:05 -050045 def test_archiver_filters_by_type(self):
46 """
47 Summary: The archiver is documented to filter on the recipe type.
48 Expected: 1. included recipe type (target) should be included
49 2. other types should be excluded
50 Product: oe-core
51 Author: André Draszik <adraszik@tycoint.com>
52 """
53
Andrew Geissler5a43b432020-06-13 10:46:56 -050054 target_recipe = 'selftest-ed'
55 native_recipe = 'selftest-ed-native'
Brad Bishopd7bf8c12018-02-25 22:55:05 -050056
57 features = 'INHERIT += "archiver"\n'
58 features += 'ARCHIVER_MODE[src] = "original"\n'
59 features += 'COPYLEFT_RECIPE_TYPES = "target"\n'
60 self.write_config(features)
61
62 bitbake('-c clean %s %s' % (target_recipe, native_recipe))
63 bitbake("%s -c deploy_archives %s" % (target_recipe, native_recipe))
64
65 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS'])
66 src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
67 src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'])
68
69 # Check that target_recipe was included
Andrew Geissler5f350902021-07-23 13:09:54 -040070 included_present = len(glob.glob(src_path_target + '/%s-*/*' % target_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050071 self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipe)
72
73 # Check that native_recipe was excluded
Andrew Geissler5f350902021-07-23 13:09:54 -040074 excluded_present = len(glob.glob(src_path_native + '/%s-*/*' % native_recipe))
Brad Bishopd7bf8c12018-02-25 22:55:05 -050075 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipe)
76
Brad Bishopd7bf8c12018-02-25 22:55:05 -050077 def test_archiver_filters_by_type_and_name(self):
78 """
79 Summary: Test that the archiver archives by recipe type, taking the
80 recipe name into account.
81 Expected: 1. included recipe type (target) should be included
82 2. other types should be excluded
83 3. recipe by name should be included / excluded,
84 overriding previous decision by type
85 Product: oe-core
86 Author: André Draszik <adraszik@tycoint.com>
87 """
88
Andrew Geissler5a43b432020-06-13 10:46:56 -050089 target_recipes = [ 'initscripts', 'selftest-ed' ]
90 native_recipes = [ 'update-rc.d-native', 'selftest-ed-native' ]
Brad Bishopd7bf8c12018-02-25 22:55:05 -050091
92 features = 'INHERIT += "archiver"\n'
93 features += 'ARCHIVER_MODE[src] = "original"\n'
94 features += 'COPYLEFT_RECIPE_TYPES = "target"\n'
95 features += 'COPYLEFT_PN_INCLUDE = "%s"\n' % native_recipes[1]
96 features += 'COPYLEFT_PN_EXCLUDE = "%s"\n' % target_recipes[1]
97 self.write_config(features)
98
99 bitbake('-c clean %s %s' % (' '.join(target_recipes), ' '.join(native_recipes)))
100 bitbake('-c deploy_archives %s %s' % (' '.join(target_recipes), ' '.join(native_recipes)))
101
102 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS', 'BUILD_SYS'])
103 src_path_target = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'])
104 src_path_native = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'])
105
106 # Check that target_recipe[0] and native_recipes[1] were included
Andrew Geissler5f350902021-07-23 13:09:54 -0400107 included_present = len(glob.glob(src_path_target + '/%s-*/*' % target_recipes[0]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500108 self.assertTrue(included_present, 'Recipe %s was not included.' % target_recipes[0])
109
Andrew Geissler5f350902021-07-23 13:09:54 -0400110 included_present = len(glob.glob(src_path_native + '/%s-*/*' % native_recipes[1]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500111 self.assertTrue(included_present, 'Recipe %s was not included.' % native_recipes[1])
112
113 # Check that native_recipes[0] and target_recipes[1] were excluded
Andrew Geissler5f350902021-07-23 13:09:54 -0400114 excluded_present = len(glob.glob(src_path_native + '/%s-*/*' % native_recipes[0]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500115 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % native_recipes[0])
116
Andrew Geissler5f350902021-07-23 13:09:54 -0400117 excluded_present = len(glob.glob(src_path_target + '/%s-*/*' % target_recipes[1]))
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500118 self.assertFalse(excluded_present, 'Recipe %s was not excluded.' % target_recipes[1])
Brad Bishop316dfdd2018-06-25 12:45:53 -0400119
120
121
122 def test_archiver_srpm_mode(self):
123 """
124 Test that in srpm mode, the added recipe dependencies at least exist/work [YOCTO #11121]
125 """
126
127 features = 'INHERIT += "archiver"\n'
128 features += 'ARCHIVER_MODE[srpm] = "1"\n'
Andrew Geissler4ed12e12020-06-05 18:00:41 -0500129 features += 'PACKAGE_CLASSES = "package_rpm"\n'
Brad Bishop316dfdd2018-06-25 12:45:53 -0400130 self.write_config(features)
131
Andrew Geissler5a43b432020-06-13 10:46:56 -0500132 bitbake('-n selftest-nopackages selftest-ed')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500133
134 def _test_archiver_mode(self, mode, target_file_name, extra_config=None):
Andrew Geissler5a43b432020-06-13 10:46:56 -0500135 target = 'selftest-ed-native'
Andrew Geissler82c905d2020-04-13 13:39:40 -0500136
137 features = 'INHERIT += "archiver"\n'
138 features += 'ARCHIVER_MODE[src] = "%s"\n' % (mode)
139 if extra_config:
140 features += extra_config
141 self.write_config(features)
142
143 bitbake('-c clean %s' % (target))
144 bitbake('-c deploy_archives %s' % (target))
145
Andrew Geissler5a43b432020-06-13 10:46:56 -0500146 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'BUILD_SYS'])
147 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['BUILD_SYS'], '%s-*' % (target))
Andrew Geissler82c905d2020-04-13 13:39:40 -0500148 glob_result = glob.glob(glob_str)
149 self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target))
150
151 archive_path = os.path.join(glob_result[0], target_file_name)
152 self.assertTrue(os.path.exists(archive_path), 'Missing archive file %s' % (target_file_name))
153
154 def test_archiver_mode_original(self):
155 """
156 Test that the archiver works with `ARCHIVER_MODE[src] = "original"`.
157 """
158
159 self._test_archiver_mode('original', 'ed-1.14.1.tar.lz')
160
161 def test_archiver_mode_patched(self):
162 """
163 Test that the archiver works with `ARCHIVER_MODE[src] = "patched"`.
164 """
165
Andrew Geissler5a43b432020-06-13 10:46:56 -0500166 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-patched.tar.gz')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500167
168 def test_archiver_mode_configured(self):
169 """
170 Test that the archiver works with `ARCHIVER_MODE[src] = "configured"`.
171 """
172
Andrew Geissler5a43b432020-06-13 10:46:56 -0500173 self._test_archiver_mode('configured', 'selftest-ed-native-1.14.1-r0-configured.tar.gz')
Andrew Geissler82c905d2020-04-13 13:39:40 -0500174
175 def test_archiver_mode_recipe(self):
176 """
177 Test that the archiver works with `ARCHIVER_MODE[recipe] = "1"`.
178 """
179
Andrew Geissler5a43b432020-06-13 10:46:56 -0500180 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-recipe.tar.gz',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500181 'ARCHIVER_MODE[recipe] = "1"\n')
182
183 def test_archiver_mode_diff(self):
184 """
185 Test that the archiver works with `ARCHIVER_MODE[diff] = "1"`.
186 Exclusions controlled by `ARCHIVER_MODE[diff-exclude]` are not yet tested.
187 """
188
Andrew Geissler5a43b432020-06-13 10:46:56 -0500189 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-diff.gz',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500190 'ARCHIVER_MODE[diff] = "1"\n')
191
192 def test_archiver_mode_dumpdata(self):
193 """
194 Test that the archiver works with `ARCHIVER_MODE[dumpdata] = "1"`.
195 """
196
Andrew Geissler5a43b432020-06-13 10:46:56 -0500197 self._test_archiver_mode('patched', 'selftest-ed-native-1.14.1-r0-showdata.dump',
Andrew Geissler82c905d2020-04-13 13:39:40 -0500198 'ARCHIVER_MODE[dumpdata] = "1"\n')
199
200 def test_archiver_mode_mirror(self):
201 """
202 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"`.
203 """
204
205 self._test_archiver_mode('mirror', 'ed-1.14.1.tar.lz',
206 'BB_GENERATE_MIRROR_TARBALLS = "1"\n')
207
208 def test_archiver_mode_mirror_excludes(self):
209 """
210 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"` and
211 correctly excludes an archive when its URL matches
212 `ARCHIVER_MIRROR_EXCLUDE`.
213 """
214
215 target='selftest-ed'
216 target_file_name = 'ed-1.14.1.tar.lz'
217
218 features = 'INHERIT += "archiver"\n'
219 features += 'ARCHIVER_MODE[src] = "mirror"\n'
220 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
221 features += 'ARCHIVER_MIRROR_EXCLUDE = "${GNU_MIRROR}"\n'
222 self.write_config(features)
223
224 bitbake('-c clean %s' % (target))
225 bitbake('-c deploy_archives %s' % (target))
226
227 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC', 'TARGET_SYS'])
228 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], bb_vars['TARGET_SYS'], '%s-*' % (target))
229 glob_result = glob.glob(glob_str)
230 self.assertTrue(glob_result, 'Missing archiver directory for %s' % (target))
231
232 archive_path = os.path.join(glob_result[0], target_file_name)
233 self.assertFalse(os.path.exists(archive_path), 'Failed to exclude archive file %s' % (target_file_name))
234
235 def test_archiver_mode_mirror_combined(self):
236 """
237 Test that the archiver works with `ARCHIVER_MODE[src] = "mirror"`
238 and `ARCHIVER_MODE[mirror] = "combined"`. Archives for multiple recipes
239 should all end up in the 'mirror' directory.
240 """
241
242 features = 'INHERIT += "archiver"\n'
243 features += 'ARCHIVER_MODE[src] = "mirror"\n'
244 features += 'ARCHIVER_MODE[mirror] = "combined"\n'
245 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
246 features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
247 self.write_config(features)
248
249 for target in ['selftest-ed', 'selftest-hardlink']:
250 bitbake('-c clean %s' % (target))
251 bitbake('-c deploy_archives %s' % (target))
252
253 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'])
254 for target_file_name in ['ed-1.14.1.tar.lz', 'hello.c']:
255 glob_str = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
256 glob_result = glob.glob(glob_str)
257 self.assertTrue(glob_result, 'Missing archive file %s' % (target_file_name))
Andrew Geissler5a43b432020-06-13 10:46:56 -0500258
259 def test_archiver_mode_mirror_gitsm(self):
260 """
261 Test that the archiver correctly handles git submodules with
262 `ARCHIVER_MODE[src] = "mirror"`.
263 """
264 features = 'INHERIT += "archiver"\n'
265 features += 'ARCHIVER_MODE[src] = "mirror"\n'
266 features += 'ARCHIVER_MODE[mirror] = "combined"\n'
267 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
268 features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
269 self.write_config(features)
270
271 bitbake('-c clean git-submodule-test')
272 bitbake('-c deploy_archives -f git-submodule-test')
273
274 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'])
275 for target_file_name in [
276 'git2_git.yoctoproject.org.git-submodule-test.tar.gz',
277 'git2_git.yoctoproject.org.bitbake-gitsm-test1.tar.gz',
278 'git2_git.yoctoproject.org.bitbake-gitsm-test2.tar.gz',
279 'git2_git.openembedded.org.bitbake.tar.gz'
280 ]:
281 target_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
282 self.assertTrue(os.path.exists(target_path))
283
284 def test_archiver_mode_mirror_gitsm_shallow(self):
285 """
286 Test that the archiver correctly handles git submodules with
287 `ARCHIVER_MODE[src] = "mirror"`.
288 """
289 features = 'INHERIT += "archiver"\n'
290 features += 'ARCHIVER_MODE[src] = "mirror"\n'
291 features += 'ARCHIVER_MODE[mirror] = "combined"\n'
292 features += 'BB_GENERATE_MIRROR_TARBALLS = "1"\n'
293 features += 'COPYLEFT_LICENSE_INCLUDE = "*"\n'
294 features += 'BB_GIT_SHALLOW = "1"\n'
295 features += 'BB_GENERATE_SHALLOW_TARBALLS = "1"\n'
296 features += 'DL_DIR = "${TOPDIR}/downloads-shallow"\n'
297 self.write_config(features)
298
299 bitbake('-c clean git-submodule-test')
300 bitbake('-c deploy_archives -f git-submodule-test')
301
302 bb_vars = get_bb_vars(['DEPLOY_DIR_SRC'])
303 for target_file_name in [
304 'gitsmshallow_git.yoctoproject.org.git-submodule-test_a2885dd-1_master.tar.gz',
305 'gitsmshallow_git.yoctoproject.org.bitbake-gitsm-test1_bare_120f4c7-1.tar.gz',
306 'gitsmshallow_git.yoctoproject.org.bitbake-gitsm-test2_bare_f66699e-1.tar.gz',
307 'gitsmshallow_git.openembedded.org.bitbake_bare_52a144a-1.tar.gz',
308 'gitsmshallow_git.openembedded.org.bitbake_bare_c39b997-1.tar.gz'
309 ]:
310 target_path = os.path.join(bb_vars['DEPLOY_DIR_SRC'], 'mirror', target_file_name)
311 self.assertTrue(os.path.exists(target_path))