summaryrefslogtreecommitdiffstats
path: root/meta/lib/oeqa/selftest/cases/recipetool.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oeqa/selftest/cases/recipetool.py')
-rw-r--r--meta/lib/oeqa/selftest/cases/recipetool.py713
1 files changed, 599 insertions, 114 deletions
diff --git a/meta/lib/oeqa/selftest/cases/recipetool.py b/meta/lib/oeqa/selftest/cases/recipetool.py
index 9d56e9e1e3..0bd724c8ee 100644
--- a/meta/lib/oeqa/selftest/cases/recipetool.py
+++ b/meta/lib/oeqa/selftest/cases/recipetool.py
@@ -1,7 +1,10 @@
1# 1#
2# Copyright OpenEmbedded Contributors
3#
2# SPDX-License-Identifier: MIT 4# SPDX-License-Identifier: MIT
3# 5#
4 6
7import errno
5import os 8import os
6import shutil 9import shutil
7import tempfile 10import tempfile
@@ -25,7 +28,17 @@ def tearDownModule():
25 runCmd('rm -rf %s' % templayerdir) 28 runCmd('rm -rf %s' % templayerdir)
26 29
27 30
28class RecipetoolBase(devtool.DevtoolBase): 31def needTomllib(test):
32 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
33 try:
34 import tomllib
35 except ImportError:
36 try:
37 import tomli
38 except ImportError:
39 test.skipTest('Test requires python 3.11 or above for tomllib module or tomli module')
40
41class RecipetoolBase(devtool.DevtoolTestCase):
29 42
30 def setUpLocal(self): 43 def setUpLocal(self):
31 super(RecipetoolBase, self).setUpLocal() 44 super(RecipetoolBase, self).setUpLocal()
@@ -35,6 +48,8 @@ class RecipetoolBase(devtool.DevtoolBase):
35 self.testfile = os.path.join(self.tempdir, 'testfile') 48 self.testfile = os.path.join(self.tempdir, 'testfile')
36 with open(self.testfile, 'w') as f: 49 with open(self.testfile, 'w') as f:
37 f.write('Test file\n') 50 f.write('Test file\n')
51 config = 'BBMASK += "meta-poky/recipes-core/base-files/base-files_%.bbappend"\n'
52 self.append_config(config)
38 53
39 def tearDownLocal(self): 54 def tearDownLocal(self):
40 runCmd('rm -rf %s/recipes-*' % self.templayerdir) 55 runCmd('rm -rf %s/recipes-*' % self.templayerdir)
@@ -68,17 +83,16 @@ class RecipetoolBase(devtool.DevtoolBase):
68 return bbappendfile, result.output 83 return bbappendfile, result.output
69 84
70 85
71class RecipetoolTests(RecipetoolBase): 86class RecipetoolAppendTests(RecipetoolBase):
72 87
73 @classmethod 88 @classmethod
74 def setUpClass(cls): 89 def setUpClass(cls):
75 super(RecipetoolTests, cls).setUpClass() 90 super(RecipetoolAppendTests, cls).setUpClass()
76 # Ensure we have the right data in shlibs/pkgdata 91 # Ensure we have the right data in shlibs/pkgdata
77 cls.logger.info('Running bitbake to generate pkgdata') 92 cls.logger.info('Running bitbake to generate pkgdata')
78 bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile') 93 bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile')
79 bb_vars = get_bb_vars(['COREBASE', 'BBPATH']) 94 bb_vars = get_bb_vars(['COREBASE'])
80 cls.corebase = bb_vars['COREBASE'] 95 cls.corebase = bb_vars['COREBASE']
81 cls.bbpath = bb_vars['BBPATH']
82 96
83 def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles): 97 def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles):
84 cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options) 98 cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options)
@@ -94,7 +108,7 @@ class RecipetoolTests(RecipetoolBase):
94 108
95 def test_recipetool_appendfile_basic(self): 109 def test_recipetool_appendfile_basic(self):
96 # Basic test 110 # Basic test
97 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 111 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
98 '\n'] 112 '\n']
99 _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd']) 113 _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd'])
100 self.assertNotIn('WARNING: ', output) 114 self.assertNotIn('WARNING: ', output)
@@ -106,23 +120,29 @@ class RecipetoolTests(RecipetoolBase):
106 self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool']) 120 self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool'])
107 121
108 def test_recipetool_appendfile_alternatives(self): 122 def test_recipetool_appendfile_alternatives(self):
123 lspath = '/bin/ls'
124 dirname = "base_bindir"
125 if "usrmerge" in get_bb_var('DISTRO_FEATURES'):
126 lspath = '/usr/bin/ls'
127 dirname = "bindir"
128
109 # Now try with a file we know should be an alternative 129 # Now try with a file we know should be an alternative
110 # (this is very much a fake example, but one we know is reliably an alternative) 130 # (this is very much a fake example, but one we know is reliably an alternative)
111 self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox']) 131 self._try_recipetool_appendfile_fail(lspath, self.testfile, ['ERROR: File %s is an alternative possibly provided by the following recipes:' % lspath, 'coreutils', 'busybox'])
112 # Need a test file - should be executable 132 # Need a test file - should be executable
113 testfile2 = os.path.join(self.corebase, 'oe-init-build-env') 133 testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
114 testfile2name = os.path.basename(testfile2) 134 testfile2name = os.path.basename(testfile2)
115 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 135 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
116 '\n', 136 '\n',
117 'SRC_URI += "file://%s"\n' % testfile2name, 137 'SRC_URI += "file://%s"\n' % testfile2name,
118 '\n', 138 '\n',
119 'do_install_append() {\n', 139 'do_install:append() {\n',
120 ' install -d ${D}${base_bindir}\n', 140 ' install -d ${D}${%s}\n' % dirname,
121 ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name, 141 ' install -m 0755 ${UNPACKDIR}/%s ${D}${%s}/ls\n' % (testfile2name, dirname),
122 '}\n'] 142 '}\n']
123 self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name]) 143 self._try_recipetool_appendfile('coreutils', lspath, testfile2, '-r coreutils', expectedlines, [testfile2name])
124 # Now try bbappending the same file again, contents should not change 144 # Now try bbappending the same file again, contents should not change
125 bbappendfile, _ = self._try_recipetool_appendfile('coreutils', '/bin/ls', self.testfile, '-r coreutils', expectedlines, [testfile2name]) 145 bbappendfile, _ = self._try_recipetool_appendfile('coreutils', lspath, self.testfile, '-r coreutils', expectedlines, [testfile2name])
126 # But file should have 146 # But file should have
127 copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name) 147 copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name)
128 result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True) 148 result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True)
@@ -138,117 +158,117 @@ class RecipetoolTests(RecipetoolBase):
138 158
139 def test_recipetool_appendfile_add(self): 159 def test_recipetool_appendfile_add(self):
140 # Try arbitrary file add to a recipe 160 # Try arbitrary file add to a recipe
141 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 161 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
142 '\n', 162 '\n',
143 'SRC_URI += "file://testfile"\n', 163 'SRC_URI += "file://testfile"\n',
144 '\n', 164 '\n',
145 'do_install_append() {\n', 165 'do_install:append() {\n',
146 ' install -d ${D}${datadir}\n', 166 ' install -d ${D}${datadir}\n',
147 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', 167 ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/something\n',
148 '}\n'] 168 '}\n']
149 self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile']) 169 self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile'])
150 # Try adding another file, this time where the source file is executable 170 # Try adding another file, this time where the source file is executable
151 # (so we're testing that, plus modifying an existing bbappend) 171 # (so we're testing that, plus modifying an existing bbappend)
152 testfile2 = os.path.join(self.corebase, 'oe-init-build-env') 172 testfile2 = os.path.join(self.corebase, 'oe-init-build-env')
153 testfile2name = os.path.basename(testfile2) 173 testfile2name = os.path.basename(testfile2)
154 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 174 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
155 '\n', 175 '\n',
156 'SRC_URI += "file://testfile \\\n', 176 'SRC_URI += "file://testfile \\\n',
157 ' file://%s \\\n' % testfile2name, 177 ' file://%s \\\n' % testfile2name,
158 ' "\n', 178 ' "\n',
159 '\n', 179 '\n',
160 'do_install_append() {\n', 180 'do_install:append() {\n',
161 ' install -d ${D}${datadir}\n', 181 ' install -d ${D}${datadir}\n',
162 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', 182 ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/something\n',
163 ' install -m 0755 ${WORKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name, 183 ' install -m 0755 ${UNPACKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name,
164 '}\n'] 184 '}\n']
165 self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name]) 185 self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name])
166 186
167 def test_recipetool_appendfile_add_bindir(self): 187 def test_recipetool_appendfile_add_bindir(self):
168 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable 188 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
169 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 189 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
170 '\n', 190 '\n',
171 'SRC_URI += "file://testfile"\n', 191 'SRC_URI += "file://testfile"\n',
172 '\n', 192 '\n',
173 'do_install_append() {\n', 193 'do_install:append() {\n',
174 ' install -d ${D}${bindir}\n', 194 ' install -d ${D}${bindir}\n',
175 ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n', 195 ' install -m 0755 ${UNPACKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n',
176 '}\n'] 196 '}\n']
177 _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile']) 197 _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile'])
178 self.assertNotIn('WARNING: ', output) 198 self.assertNotIn('WARNING: ', output)
179 199
180 def test_recipetool_appendfile_add_machine(self): 200 def test_recipetool_appendfile_add_machine(self):
181 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable 201 # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable
182 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 202 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
183 '\n', 203 '\n',
184 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n', 204 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
185 '\n', 205 '\n',
186 'SRC_URI_append_mymachine = " file://testfile"\n', 206 'SRC_URI:append:mymachine = " file://testfile"\n',
187 '\n', 207 '\n',
188 'do_install_append_mymachine() {\n', 208 'do_install:append:mymachine() {\n',
189 ' install -d ${D}${datadir}\n', 209 ' install -d ${D}${datadir}\n',
190 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', 210 ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/something\n',
191 '}\n'] 211 '}\n']
192 _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile']) 212 _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile'])
193 self.assertNotIn('WARNING: ', output) 213 self.assertNotIn('WARNING: ', output)
194 214
195 def test_recipetool_appendfile_orig(self): 215 def test_recipetool_appendfile_orig(self):
196 # A file that's in SRC_URI and in do_install with the same name 216 # A file that's in SRC_URI and in do_install with the same name
197 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 217 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
198 '\n'] 218 '\n']
199 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig']) 219 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig'])
200 self.assertNotIn('WARNING: ', output) 220 self.assertNotIn('WARNING: ', output)
201 221
202 def test_recipetool_appendfile_todir(self): 222 def test_recipetool_appendfile_todir(self):
203 # A file that's in SRC_URI and in do_install with destination directory rather than file 223 # A file that's in SRC_URI and in do_install with destination directory rather than file
204 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 224 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
205 '\n'] 225 '\n']
206 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir']) 226 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir'])
207 self.assertNotIn('WARNING: ', output) 227 self.assertNotIn('WARNING: ', output)
208 228
209 def test_recipetool_appendfile_renamed(self): 229 def test_recipetool_appendfile_renamed(self):
210 # A file that's in SRC_URI with a different name to the destination file 230 # A file that's in SRC_URI with a different name to the destination file
211 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 231 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
212 '\n'] 232 '\n']
213 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1']) 233 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1'])
214 self.assertNotIn('WARNING: ', output) 234 self.assertNotIn('WARNING: ', output)
215 235
216 def test_recipetool_appendfile_subdir(self): 236 def test_recipetool_appendfile_subdir(self):
217 # A file that's in SRC_URI in a subdir 237 # A file that's in SRC_URI in a subdir
218 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 238 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
219 '\n', 239 '\n',
220 'SRC_URI += "file://testfile"\n', 240 'SRC_URI += "file://testfile"\n',
221 '\n', 241 '\n',
222 'do_install_append() {\n', 242 'do_install:append() {\n',
223 ' install -d ${D}${datadir}\n', 243 ' install -d ${D}${datadir}\n',
224 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n', 244 ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n',
225 '}\n'] 245 '}\n']
226 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile']) 246 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile'])
227 self.assertNotIn('WARNING: ', output) 247 self.assertNotIn('WARNING: ', output)
228 248
229 def test_recipetool_appendfile_inst_glob(self): 249 def test_recipetool_appendfile_inst_glob(self):
230 # A file that's in do_install as a glob 250 # A file that's in do_install as a glob
231 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 251 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
232 '\n'] 252 '\n']
233 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile']) 253 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile'])
234 self.assertNotIn('WARNING: ', output) 254 self.assertNotIn('WARNING: ', output)
235 255
236 def test_recipetool_appendfile_inst_todir_glob(self): 256 def test_recipetool_appendfile_inst_todir_glob(self):
237 # A file that's in do_install as a glob with destination as a directory 257 # A file that's in do_install as a glob with destination as a directory
238 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 258 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
239 '\n'] 259 '\n']
240 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile']) 260 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile'])
241 self.assertNotIn('WARNING: ', output) 261 self.assertNotIn('WARNING: ', output)
242 262
243 def test_recipetool_appendfile_patch(self): 263 def test_recipetool_appendfile_patch(self):
244 # A file that's added by a patch in SRC_URI 264 # A file that's added by a patch in SRC_URI
245 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 265 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
246 '\n', 266 '\n',
247 'SRC_URI += "file://testfile"\n', 267 'SRC_URI += "file://testfile"\n',
248 '\n', 268 '\n',
249 'do_install_append() {\n', 269 'do_install:append() {\n',
250 ' install -d ${D}${sysconfdir}\n', 270 ' install -d ${D}${sysconfdir}\n',
251 ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n', 271 ' install -m 0644 ${UNPACKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n',
252 '}\n'] 272 '}\n']
253 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile']) 273 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile'])
254 for line in output.splitlines(): 274 for line in output.splitlines():
@@ -260,20 +280,20 @@ class RecipetoolTests(RecipetoolBase):
260 280
261 def test_recipetool_appendfile_script(self): 281 def test_recipetool_appendfile_script(self):
262 # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install) 282 # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install)
263 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 283 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
264 '\n', 284 '\n',
265 'SRC_URI += "file://testfile"\n', 285 'SRC_URI += "file://testfile"\n',
266 '\n', 286 '\n',
267 'do_install_append() {\n', 287 'do_install:append() {\n',
268 ' install -d ${D}${datadir}\n', 288 ' install -d ${D}${datadir}\n',
269 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n', 289 ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n',
270 '}\n'] 290 '}\n']
271 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile']) 291 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile'])
272 self.assertNotIn('WARNING: ', output) 292 self.assertNotIn('WARNING: ', output)
273 293
274 def test_recipetool_appendfile_inst_func(self): 294 def test_recipetool_appendfile_inst_func(self):
275 # A file that's installed from a function called by do_install 295 # A file that's installed from a function called by do_install
276 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 296 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
277 '\n'] 297 '\n']
278 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func']) 298 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func'])
279 self.assertNotIn('WARNING: ', output) 299 self.assertNotIn('WARNING: ', output)
@@ -283,13 +303,13 @@ class RecipetoolTests(RecipetoolBase):
283 # First try without specifying recipe 303 # First try without specifying recipe
284 self._try_recipetool_appendfile_fail('/usr/share/selftest-replaceme-postinst', self.testfile, ['File /usr/share/selftest-replaceme-postinst may be written out in a pre/postinstall script of the following recipes:', 'selftest-recipetool-appendfile']) 304 self._try_recipetool_appendfile_fail('/usr/share/selftest-replaceme-postinst', self.testfile, ['File /usr/share/selftest-replaceme-postinst may be written out in a pre/postinstall script of the following recipes:', 'selftest-recipetool-appendfile'])
285 # Now specify recipe 305 # Now specify recipe
286 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 306 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
287 '\n', 307 '\n',
288 'SRC_URI += "file://testfile"\n', 308 'SRC_URI += "file://testfile"\n',
289 '\n', 309 '\n',
290 'do_install_append() {\n', 310 'do_install:append() {\n',
291 ' install -d ${D}${datadir}\n', 311 ' install -d ${D}${datadir}\n',
292 ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n', 312 ' install -m 0644 ${UNPACKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n',
293 '}\n'] 313 '}\n']
294 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile']) 314 _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile'])
295 315
@@ -332,6 +352,9 @@ class RecipetoolTests(RecipetoolBase):
332 filename = try_appendfile_wc('-w') 352 filename = try_appendfile_wc('-w')
333 self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend') 353 self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend')
334 354
355
356class RecipetoolCreateTests(RecipetoolBase):
357
335 def test_recipetool_create(self): 358 def test_recipetool_create(self):
336 # Try adding a recipe 359 # Try adding a recipe
337 tempsrc = os.path.join(self.tempdir, 'srctree') 360 tempsrc = os.path.join(self.tempdir, 'srctree')
@@ -341,14 +364,13 @@ class RecipetoolTests(RecipetoolBase):
341 result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc)) 364 result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc))
342 self.assertTrue(os.path.isfile(recipefile)) 365 self.assertTrue(os.path.isfile(recipefile))
343 checkvars = {} 366 checkvars = {}
344 checkvars['LICENSE'] = 'GPLv2' 367 checkvars['LICENSE'] = 'GPL-2.0-only'
345 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263' 368 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'
346 checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/releases/download/${PV}/logrotate-${PV}.tar.xz' 369 checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/releases/download/${PV}/logrotate-${PV}.tar.xz'
347 checkvars['SRC_URI[md5sum]'] = 'a560c57fac87c45b2fc17406cdf79288'
348 checkvars['SRC_URI[sha256sum]'] = '2e6a401cac9024db2288297e3be1a8ab60e7401ba8e91225218aaf4a27e82a07' 370 checkvars['SRC_URI[sha256sum]'] = '2e6a401cac9024db2288297e3be1a8ab60e7401ba8e91225218aaf4a27e82a07'
349 self._test_recipe_contents(recipefile, checkvars, []) 371 self._test_recipe_contents(recipefile, checkvars, [])
350 372
351 def test_recipetool_create_git(self): 373 def test_recipetool_create_autotools(self):
352 if 'x11' not in get_bb_var('DISTRO_FEATURES'): 374 if 'x11' not in get_bb_var('DISTRO_FEATURES'):
353 self.skipTest('Test requires x11 as distro feature') 375 self.skipTest('Test requires x11 as distro feature')
354 # Ensure we have the right data in shlibs/pkgdata 376 # Ensure we have the right data in shlibs/pkgdata
@@ -357,15 +379,15 @@ class RecipetoolTests(RecipetoolBase):
357 tempsrc = os.path.join(self.tempdir, 'srctree') 379 tempsrc = os.path.join(self.tempdir, 'srctree')
358 os.makedirs(tempsrc) 380 os.makedirs(tempsrc)
359 recipefile = os.path.join(self.tempdir, 'libmatchbox.bb') 381 recipefile = os.path.join(self.tempdir, 'libmatchbox.bb')
360 srcuri = 'git://git.yoctoproject.org/libmatchbox' 382 srcuri = 'git://git.yoctoproject.org/libmatchbox;protocol=https'
361 result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc]) 383 result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc])
362 self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output) 384 self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output)
363 checkvars = {} 385 checkvars = {}
364 checkvars['LICENSE'] = 'LGPLv2.1' 386 checkvars['LICENSE'] = 'LGPL-2.1-only'
365 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34' 387 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34'
366 checkvars['S'] = '${WORKDIR}/git' 388 checkvars['S'] = None
367 checkvars['PV'] = '1.11+git${SRCPV}' 389 checkvars['PV'] = '1.11+git'
368 checkvars['SRC_URI'] = srcuri 390 checkvars['SRC_URI'] = srcuri + ';branch=master'
369 checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango']) 391 checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango'])
370 inherits = ['autotools', 'pkgconfig'] 392 inherits = ['autotools', 'pkgconfig']
371 self._test_recipe_contents(recipefile, checkvars, inherits) 393 self._test_recipe_contents(recipefile, checkvars, inherits)
@@ -374,8 +396,8 @@ class RecipetoolTests(RecipetoolBase):
374 # Try adding a recipe 396 # Try adding a recipe
375 temprecipe = os.path.join(self.tempdir, 'recipe') 397 temprecipe = os.path.join(self.tempdir, 'recipe')
376 os.makedirs(temprecipe) 398 os.makedirs(temprecipe)
377 pv = '1.7.3.0' 399 pv = '1.7.4.1'
378 srcuri = 'http://www.dest-unreach.org/socat/download/socat-%s.tar.bz2' % pv 400 srcuri = 'http://www.dest-unreach.org/socat/download/Archive/socat-%s.tar.bz2' % pv
379 result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe)) 401 result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe))
380 dirlist = os.listdir(temprecipe) 402 dirlist = os.listdir(temprecipe)
381 if len(dirlist) > 1: 403 if len(dirlist) > 1:
@@ -384,7 +406,7 @@ class RecipetoolTests(RecipetoolBase):
384 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist))) 406 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
385 self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named') 407 self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named')
386 checkvars = {} 408 checkvars = {}
387 checkvars['LICENSE'] = set(['Unknown', 'GPLv2']) 409 checkvars['LICENSE'] = set(['Unknown', 'GPL-2.0-only'])
388 checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263']) 410 checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263'])
389 # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot 411 # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot
390 checkvars['S'] = None 412 checkvars['S'] = None
@@ -400,9 +422,8 @@ class RecipetoolTests(RecipetoolBase):
400 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) 422 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
401 self.assertTrue(os.path.isfile(recipefile)) 423 self.assertTrue(os.path.isfile(recipefile))
402 checkvars = {} 424 checkvars = {}
403 checkvars['LICENSE'] = set(['LGPLv2.1', 'MPL-1.1']) 425 checkvars['LICENSE'] = set(['LGPL-2.1-only', 'MPL-1.1-only'])
404 checkvars['SRC_URI'] = 'http://taglib.github.io/releases/taglib-${PV}.tar.gz' 426 checkvars['SRC_URI'] = 'http://taglib.github.io/releases/taglib-${PV}.tar.gz'
405 checkvars['SRC_URI[md5sum]'] = 'cee7be0ccfc892fa433d6c837df9522a'
406 checkvars['SRC_URI[sha256sum]'] = 'b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b' 427 checkvars['SRC_URI[sha256sum]'] = 'b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b'
407 checkvars['DEPENDS'] = set(['boost', 'zlib']) 428 checkvars['DEPENDS'] = set(['boost', 'zlib'])
408 inherits = ['cmake'] 429 inherits = ['cmake']
@@ -424,77 +445,271 @@ class RecipetoolTests(RecipetoolBase):
424 checkvars = {} 445 checkvars = {}
425 checkvars['SUMMARY'] = 'Node Server Example' 446 checkvars['SUMMARY'] = 'Node Server Example'
426 checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme' 447 checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme'
427 checkvars['LICENSE'] = set(['MIT', 'ISC', 'Unknown']) 448 checkvars['LICENSE'] = 'BSD-3-Clause & ISC & MIT & Unknown'
428 urls = [] 449 urls = []
429 urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}') 450 urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}')
430 urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json') 451 urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json')
431 checkvars['SRC_URI'] = set(urls) 452 checkvars['SRC_URI'] = set(urls)
432 checkvars['S'] = '${WORKDIR}/npm' 453 checkvars['S'] = '${WORKDIR}/npm'
433 checkvars['LICENSE_${PN}'] = 'MIT' 454 checkvars['LICENSE:${PN}'] = 'MIT'
434 checkvars['LICENSE_${PN}-base64'] = 'Unknown' 455 checkvars['LICENSE:${PN}-base64'] = 'Unknown'
435 checkvars['LICENSE_${PN}-accepts'] = 'MIT' 456 checkvars['LICENSE:${PN}-accepts'] = 'MIT'
436 checkvars['LICENSE_${PN}-inherits'] = 'ISC' 457 checkvars['LICENSE:${PN}-inherits'] = 'ISC'
437 inherits = ['npm'] 458 inherits = ['npm']
438 self._test_recipe_contents(recipefile, checkvars, inherits) 459 self._test_recipe_contents(recipefile, checkvars, inherits)
439 460
440 def test_recipetool_create_github(self): 461 def test_recipetool_create_github(self):
441 # Basic test to see if github URL mangling works 462 # Basic test to see if github URL mangling works. Deliberately use an
463 # older release of Meson at present so we don't need a toml parser.
442 temprecipe = os.path.join(self.tempdir, 'recipe') 464 temprecipe = os.path.join(self.tempdir, 'recipe')
443 os.makedirs(temprecipe) 465 os.makedirs(temprecipe)
444 recipefile = os.path.join(temprecipe, 'meson_git.bb') 466 recipefile = os.path.join(temprecipe, 'python3-meson_git.bb')
445 srcuri = 'https://github.com/mesonbuild/meson;rev=0.32.0' 467 srcuri = 'https://github.com/mesonbuild/meson;rev=0.52.1'
446 result = runCmd(['recipetool', 'create', '-o', temprecipe, srcuri]) 468 cmd = ['recipetool', 'create', '-o', temprecipe, srcuri]
447 self.assertTrue(os.path.isfile(recipefile)) 469 result = runCmd(cmd)
470 self.assertTrue(os.path.isfile(recipefile), msg="recipe %s not created for command %s, output %s" % (recipefile, " ".join(cmd), result.output))
448 checkvars = {} 471 checkvars = {}
449 checkvars['LICENSE'] = set(['Apache-2.0']) 472 checkvars['LICENSE'] = set(['Apache-2.0', "Unknown"])
450 checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https' 473 checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https;branch=0.52'
451 inherits = ['setuptools3'] 474 inherits = ['setuptools3']
452 self._test_recipe_contents(recipefile, checkvars, inherits) 475 self._test_recipe_contents(recipefile, checkvars, inherits)
453 476
454 def test_recipetool_create_python3_setuptools(self): 477 def test_recipetool_create_python3_setuptools(self):
455 # Test creating python3 package from tarball (using setuptools3 class) 478 # Test creating python3 package from tarball (using setuptools3 class)
479 # Use the --no-pypi switch to avoid creating a pypi enabled recipe and
480 # and check the created recipe as if it was a more general tarball
456 temprecipe = os.path.join(self.tempdir, 'recipe') 481 temprecipe = os.path.join(self.tempdir, 'recipe')
457 os.makedirs(temprecipe) 482 os.makedirs(temprecipe)
458 pn = 'python-magic' 483 pn = 'python-magic'
459 pv = '0.4.15' 484 pv = '0.4.15'
460 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv)) 485 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
461 srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv 486 srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
462 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) 487 result = runCmd('recipetool create --no-pypi -o %s %s' % (temprecipe, srcuri))
463 self.assertTrue(os.path.isfile(recipefile)) 488 self.assertTrue(os.path.isfile(recipefile))
464 checkvars = {} 489 checkvars = {}
465 checkvars['LICENSE'] = set(['MIT']) 490 checkvars['LICENSE'] = set(['MIT'])
466 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88' 491 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
467 checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-${PV}.tar.gz' 492 checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-${PV}.tar.gz'
468 checkvars['SRC_URI[md5sum]'] = 'e384c95a47218f66c6501cd6dd45ff59'
469 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5' 493 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
470 inherits = ['setuptools3'] 494 inherits = ['setuptools3']
471 self._test_recipe_contents(recipefile, checkvars, inherits) 495 self._test_recipe_contents(recipefile, checkvars, inherits)
472 496
473 def test_recipetool_create_python3_distutils(self): 497 def test_recipetool_create_python3_setuptools_pypi_tarball(self):
474 # Test creating python3 package from tarball (using distutils3 class) 498 # Test creating python3 package from tarball (using setuptools3 and pypi classes)
499 temprecipe = os.path.join(self.tempdir, 'recipe')
500 os.makedirs(temprecipe)
501 pn = 'python-magic'
502 pv = '0.4.15'
503 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
504 srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv
505 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
506 self.assertTrue(os.path.isfile(recipefile))
507 checkvars = {}
508 checkvars['LICENSE'] = set(['MIT'])
509 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
510 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
511 checkvars['PYPI_PACKAGE'] = pn
512 inherits = ['setuptools3', 'pypi']
513 self._test_recipe_contents(recipefile, checkvars, inherits)
514
515 def test_recipetool_create_python3_setuptools_pypi(self):
516 # Test creating python3 package from pypi url (using setuptools3 and pypi classes)
517 # Intentionnaly using setuptools3 class here instead of any of the pep517 class
518 # to avoid the toml dependency and allows this test to run on host autobuilders
519 # with older version of python
475 temprecipe = os.path.join(self.tempdir, 'recipe') 520 temprecipe = os.path.join(self.tempdir, 'recipe')
476 os.makedirs(temprecipe) 521 os.makedirs(temprecipe)
477 pn = 'docutils' 522 pn = 'python-magic'
478 pv = '0.14' 523 pv = '0.4.15'
479 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv)) 524 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv))
480 srcuri = 'https://files.pythonhosted.org/packages/84/f4/5771e41fdf52aabebbadecc9381d11dea0fa34e4759b4071244fa094804c/docutils-%s.tar.gz' % pv 525 # First specify the required version in the url
526 srcuri = 'https://pypi.org/project/%s/%s' % (pn, pv)
527 runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
528 self.assertTrue(os.path.isfile(recipefile))
529 checkvars = {}
530 checkvars['LICENSE'] = set(['MIT'])
531 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
532 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
533 checkvars['PYPI_PACKAGE'] = pn
534 inherits = ['setuptools3', "pypi"]
535 self._test_recipe_contents(recipefile, checkvars, inherits)
536
537 # Now specify the version as a recipetool parameter
538 runCmd('rm -rf %s' % recipefile)
539 self.assertFalse(os.path.isfile(recipefile))
540 srcuri = 'https://pypi.org/project/%s' % pn
541 runCmd('recipetool create -o %s %s --version %s' % (temprecipe, srcuri, pv))
542 self.assertTrue(os.path.isfile(recipefile))
543 checkvars = {}
544 checkvars['LICENSE'] = set(['MIT'])
545 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88'
546 checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5'
547 checkvars['PYPI_PACKAGE'] = pn
548 inherits = ['setuptools3', "pypi"]
549 self._test_recipe_contents(recipefile, checkvars, inherits)
550
551 # Now, try to grab latest version of the package, so we cannot guess the name of the recipe,
552 # unless hardcoding the latest version but it means we will need to update the test for each release,
553 # so use a regexp
554 runCmd('rm -rf %s' % recipefile)
555 self.assertFalse(os.path.isfile(recipefile))
556 recipefile_re = r'%s_(.*)\.bb' % pn
557 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
558 dirlist = os.listdir(temprecipe)
559 if len(dirlist) > 1:
560 self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
561 if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])):
562 self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist)))
563 import re
564 match = re.match(recipefile_re, dirlist[0])
565 self.assertTrue(match)
566 latest_pv = match.group(1)
567 self.assertTrue(latest_pv != pv)
568 recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, latest_pv))
569 # Do not check LIC_FILES_CHKSUM and SRC_URI checksum here to avoid having updating the test on each release
570 checkvars = {}
571 checkvars['LICENSE'] = set(['MIT'])
572 checkvars['PYPI_PACKAGE'] = pn
573 inherits = ['setuptools3', "pypi"]
574 self._test_recipe_contents(recipefile, checkvars, inherits)
575
576 def test_recipetool_create_python3_pep517_setuptools_build_meta(self):
577 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
578 needTomllib(self)
579
580 # Test creating python3 package from tarball (using setuptools.build_meta class)
581 temprecipe = os.path.join(self.tempdir, 'recipe')
582 os.makedirs(temprecipe)
583 pn = 'webcolors'
584 pv = '1.13'
585 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
586 srcuri = 'https://files.pythonhosted.org/packages/a1/fb/f95560c6a5d4469d9c49e24cf1b5d4d21ffab5608251c6020a965fb7791c/%s-%s.tar.gz' % (pn, pv)
587 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
588 self.assertTrue(os.path.isfile(recipefile))
589 checkvars = {}
590 checkvars['SUMMARY'] = 'A library for working with the color formats defined by HTML and CSS.'
591 checkvars['LICENSE'] = set(['BSD-3-Clause'])
592 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=702b1ef12cf66832a88f24c8f2ee9c19'
593 checkvars['SRC_URI[sha256sum]'] = 'c225b674c83fa923be93d235330ce0300373d02885cef23238813b0d5668304a'
594 inherits = ['python_setuptools_build_meta', 'pypi']
595
596 self._test_recipe_contents(recipefile, checkvars, inherits)
597
598 def test_recipetool_create_python3_pep517_poetry_core_masonry_api(self):
599 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
600 needTomllib(self)
601
602 # Test creating python3 package from tarball (using poetry.core.masonry.api class)
603 temprecipe = os.path.join(self.tempdir, 'recipe')
604 os.makedirs(temprecipe)
605 pn = 'iso8601'
606 pv = '2.1.0'
607 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
608 srcuri = 'https://files.pythonhosted.org/packages/b9/f3/ef59cee614d5e0accf6fd0cbba025b93b272e626ca89fb70a3e9187c5d15/%s-%s.tar.gz' % (pn, pv)
609 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
610 self.assertTrue(os.path.isfile(recipefile))
611 checkvars = {}
612 checkvars['SUMMARY'] = 'Simple module to parse ISO 8601 dates'
613 checkvars['LICENSE'] = set(['MIT'])
614 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=aab31f2ef7ba214a5a341eaa47a7f367'
615 checkvars['SRC_URI[sha256sum]'] = '6b1d3829ee8921c4301998c909f7829fa9ed3cbdac0d3b16af2d743aed1ba8df'
616 inherits = ['python_poetry_core', 'pypi']
617
618 self._test_recipe_contents(recipefile, checkvars, inherits)
619
620 def test_recipetool_create_python3_pep517_flit_core_buildapi(self):
621 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
622 needTomllib(self)
623
624 # Test creating python3 package from tarball (using flit_core.buildapi class)
625 temprecipe = os.path.join(self.tempdir, 'recipe')
626 os.makedirs(temprecipe)
627 pn = 'typing-extensions'
628 pv = '4.8.0'
629 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
630 srcuri = 'https://files.pythonhosted.org/packages/1f/7a/8b94bb016069caa12fc9f587b28080ac33b4fbb8ca369b98bc0a4828543e/typing_extensions-%s.tar.gz' % pv
631 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
632 self.assertTrue(os.path.isfile(recipefile))
633 checkvars = {}
634 checkvars['SUMMARY'] = 'Backported and Experimental Type Hints for Python 3.8+'
635 checkvars['LICENSE'] = set(['PSF-2.0'])
636 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=fcf6b249c2641540219a727f35d8d2c2'
637 checkvars['SRC_URI[sha256sum]'] = 'df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef'
638 inherits = ['python_flit_core', 'pypi']
639
640 self._test_recipe_contents(recipefile, checkvars, inherits)
641
642 def test_recipetool_create_python3_pep517_hatchling(self):
643 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
644 needTomllib(self)
645
646 # Test creating python3 package from tarball (using hatchling class)
647 temprecipe = os.path.join(self.tempdir, 'recipe')
648 os.makedirs(temprecipe)
649 pn = 'jsonschema'
650 pv = '4.19.1'
651 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
652 srcuri = 'https://files.pythonhosted.org/packages/e4/43/087b24516db11722c8687e0caf0f66c7785c0b1c51b0ab951dfde924e3f5/jsonschema-%s.tar.gz' % pv
653 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
654 self.assertTrue(os.path.isfile(recipefile))
655 checkvars = {}
656 checkvars['SUMMARY'] = 'An implementation of JSON Schema validation for Python'
657 checkvars['HOMEPAGE'] = 'https://github.com/python-jsonschema/jsonschema'
658 checkvars['LICENSE'] = set(['MIT'])
659 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7a60a81c146ec25599a3e1dabb8610a8 file://json/LICENSE;md5=9d4de43111d33570c8fe49b4cb0e01af'
660 checkvars['SRC_URI[sha256sum]'] = 'ec84cc37cfa703ef7cd4928db24f9cb31428a5d0fa77747b8b51a847458e0bbf'
661 inherits = ['python_hatchling', 'pypi']
662
663 self._test_recipe_contents(recipefile, checkvars, inherits)
664
665 def test_recipetool_create_python3_pep517_maturin(self):
666 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
667 needTomllib(self)
668
669 # Test creating python3 package from tarball (using maturin class)
670 temprecipe = os.path.join(self.tempdir, 'recipe')
671 os.makedirs(temprecipe)
672 pn = 'pydantic-core'
673 pv = '2.14.5'
674 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
675 srcuri = 'https://files.pythonhosted.org/packages/64/26/cffb93fe9c6b5a91c497f37fae14a4b073ecbc47fc36a9979c7aa888b245/pydantic_core-%s.tar.gz' % pv
676 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
677 self.assertTrue(os.path.isfile(recipefile))
678 checkvars = {}
679 checkvars['HOMEPAGE'] = 'https://github.com/pydantic/pydantic-core'
680 checkvars['LICENSE'] = set(['MIT'])
681 checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=ab599c188b4a314d2856b3a55030c75c'
682 checkvars['SRC_URI[sha256sum]'] = '6d30226dfc816dd0fdf120cae611dd2215117e4f9b124af8c60ab9093b6e8e71'
683 inherits = ['python_maturin', 'pypi']
684
685 self._test_recipe_contents(recipefile, checkvars, inherits)
686
687 def test_recipetool_create_python3_pep517_mesonpy(self):
688 # This test require python 3.11 or above for the tomllib module or tomli module to be installed
689 needTomllib(self)
690
691 # Test creating python3 package from tarball (using mesonpy class)
692 temprecipe = os.path.join(self.tempdir, 'recipe')
693 os.makedirs(temprecipe)
694 pn = 'siphash24'
695 pv = '1.4'
696 recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv))
697 srcuri = 'https://files.pythonhosted.org/packages/c2/32/b934a70592f314afcfa86c7f7e388804a8061be65b822e2aa07e573b6477/%s-%s.tar.gz' % (pn, pv)
481 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) 698 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
482 self.assertTrue(os.path.isfile(recipefile)) 699 self.assertTrue(os.path.isfile(recipefile))
483 checkvars = {} 700 checkvars = {}
484 checkvars['LICENSE'] = set(['PSF', '&', 'BSD', 'GPL']) 701 checkvars['SRC_URI[sha256sum]'] = '7fd65e39b2a7c8c4ddc3a168a687f4610751b0ac2ebb518783c0cdfc30bec4a0'
485 checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING.txt;md5=35a23d42b615470583563132872c97d6' 702 inherits = ['python_mesonpy', 'pypi']
486 checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/f4/5771e41fdf52aabebbadecc9381d11dea0fa34e4759b4071244fa094804c/docutils-${PV}.tar.gz' 703
487 checkvars['SRC_URI[md5sum]'] = 'c53768d63db3873b7d452833553469de'
488 checkvars['SRC_URI[sha256sum]'] = '51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274'
489 inherits = ['distutils3']
490 self._test_recipe_contents(recipefile, checkvars, inherits) 704 self._test_recipe_contents(recipefile, checkvars, inherits)
491 705
492 def test_recipetool_create_github_tarball(self): 706 def test_recipetool_create_github_tarball(self):
493 # Basic test to ensure github URL mangling doesn't apply to release tarballs 707 # Basic test to ensure github URL mangling doesn't apply to release tarballs.
708 # Deliberately use an older release of Meson at present so we don't need a toml parser.
494 temprecipe = os.path.join(self.tempdir, 'recipe') 709 temprecipe = os.path.join(self.tempdir, 'recipe')
495 os.makedirs(temprecipe) 710 os.makedirs(temprecipe)
496 pv = '0.32.0' 711 pv = '0.52.1'
497 recipefile = os.path.join(temprecipe, 'meson_%s.bb' % pv) 712 recipefile = os.path.join(temprecipe, 'python3-meson_%s.bb' % pv)
498 srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv) 713 srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv)
499 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) 714 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri))
500 self.assertTrue(os.path.isfile(recipefile)) 715 self.assertTrue(os.path.isfile(recipefile))
@@ -504,19 +719,93 @@ class RecipetoolTests(RecipetoolBase):
504 inherits = ['setuptools3'] 719 inherits = ['setuptools3']
505 self._test_recipe_contents(recipefile, checkvars, inherits) 720 self._test_recipe_contents(recipefile, checkvars, inherits)
506 721
507 def test_recipetool_create_git_http(self): 722 def _test_recipetool_create_git(self, srcuri, branch=None):
508 # Basic test to check http git URL mangling works 723 # Basic test to check http git URL mangling works
509 temprecipe = os.path.join(self.tempdir, 'recipe') 724 temprecipe = os.path.join(self.tempdir, 'recipe')
510 os.makedirs(temprecipe) 725 os.makedirs(temprecipe)
511 recipefile = os.path.join(temprecipe, 'matchbox-terminal_git.bb') 726 name = srcuri.split(';')[0].split('/')[-1]
512 srcuri = 'http://git.yoctoproject.org/git/matchbox-terminal' 727 recipefile = os.path.join(temprecipe, name + '_git.bb')
513 result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) 728 options = ' -B %s' % branch if branch else ''
729 result = runCmd('recipetool create -o %s%s "%s"' % (temprecipe, options, srcuri))
514 self.assertTrue(os.path.isfile(recipefile)) 730 self.assertTrue(os.path.isfile(recipefile))
515 checkvars = {} 731 checkvars = {}
516 checkvars['LICENSE'] = set(['GPLv2']) 732 checkvars['SRC_URI'] = srcuri
517 checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/matchbox-terminal;protocol=http' 733 for scheme in ['http', 'https']:
518 inherits = ['pkgconfig', 'autotools'] 734 if srcuri.startswith(scheme + ":"):
735 checkvars['SRC_URI'] = 'git%s;protocol=%s' % (srcuri[len(scheme):], scheme)
736 if ';branch=' not in srcuri:
737 checkvars['SRC_URI'] += ';branch=' + (branch or 'master')
738 self._test_recipe_contents(recipefile, checkvars, [])
739
740 def test_recipetool_create_git_http(self):
741 self._test_recipetool_create_git('http://git.yoctoproject.org/git/matchbox-keyboard')
742
743 def test_recipetool_create_git_srcuri_master(self):
744 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=master;protocol=https')
745
746 def test_recipetool_create_git_srcuri_branch(self):
747 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=matchbox-keyboard-0-1;protocol=https')
748
749 def test_recipetool_create_git_srcbranch(self):
750 self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;protocol=https', 'matchbox-keyboard-0-1')
751
752 def _go_urifiy(self, url, version, modulepath = None, pathmajor = None, subdir = None):
753 modulepath = ",path='%s'" % modulepath if len(modulepath) else ''
754 pathmajor = ",pathmajor='%s'" % pathmajor if len(pathmajor) else ''
755 subdir = ",subdir='%s'" % subdir if len(subdir) else ''
756 return "${@go_src_uri('%s','%s'%s%s%s)}" % (url, version, modulepath, pathmajor, subdir)
757
758 def test_recipetool_create_go(self):
759 # Basic test to check go recipe generation
760 self.maxDiff = None
761
762 temprecipe = os.path.join(self.tempdir, 'recipe')
763 os.makedirs(temprecipe)
764
765 recipefile = os.path.join(temprecipe, 'recipetool-go-test_git.bb')
766
767 srcuri = 'https://git.yoctoproject.org/recipetool-go-test.git'
768 srcrev = "c3e213c01b6c1406b430df03ef0d1ae77de5d2f7"
769 srcbranch = "main"
770
771 result = runCmd('recipetool create -o %s %s -S %s -B %s' % (temprecipe, srcuri, srcrev, srcbranch))
772
773 inherits = ['go-mod', 'go-mod-update-modules']
774
775 checkvars = {}
776 checkvars['GO_IMPORT'] = "git.yoctoproject.org/recipetool-go-test"
777 checkvars['SRC_URI'] = {'git://${GO_IMPORT};protocol=https;nobranch=1;destsuffix=${GO_SRCURI_DESTSUFFIX}'}
778 checkvars['LIC_FILES_CHKSUM'] = {
779 'file://src/${GO_IMPORT}/LICENSE;md5=4e3933dd47afbf115e484d11385fb3bd',
780 'file://src/${GO_IMPORT}/is/LICENSE;md5=62beaee5a116dd1e80161667b1df39ab'
781 }
782
519 self._test_recipe_contents(recipefile, checkvars, inherits) 783 self._test_recipe_contents(recipefile, checkvars, inherits)
784 self.assertNotIn('Traceback', result.output)
785
786 lics_require_file = os.path.join(temprecipe, 'recipetool-go-test-licenses.inc')
787 self.assertFileExists(lics_require_file)
788 checkvars = {}
789 checkvars['LIC_FILES_CHKSUM'] = {'file://pkg/mod/github.com/godbus/dbus/v5@v5.1.0/LICENSE;md5=09042bd5c6c96a2b9e45ddf1bc517eed;spdx=BSD-2-Clause'}
790 self._test_recipe_contents(lics_require_file, checkvars, [])
791
792 deps_require_file = os.path.join(temprecipe, 'recipetool-go-test-go-mods.inc')
793 self.assertFileExists(deps_require_file)
794 checkvars = {}
795 checkvars['SRC_URI'] = {'gomod://github.com/godbus/dbus/v5;version=v5.1.0;sha256sum=03dfa8e71089a6f477310d15c4d3a036d82d028532881b50fee254358e782ad9'}
796 self._test_recipe_contents(deps_require_file, checkvars, [])
797
798class RecipetoolTests(RecipetoolBase):
799
800 @classmethod
801 def setUpClass(cls):
802 import sys
803
804 super(RecipetoolTests, cls).setUpClass()
805 bb_vars = get_bb_vars(['BBPATH'])
806 cls.bbpath = bb_vars['BBPATH']
807 libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool')
808 sys.path.insert(0, libpath)
520 809
521 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths): 810 def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths):
522 dstdir = basedstdir 811 dstdir = basedstdir
@@ -524,7 +813,15 @@ class RecipetoolTests(RecipetoolBase):
524 for p in paths: 813 for p in paths:
525 dstdir = os.path.join(dstdir, p) 814 dstdir = os.path.join(dstdir, p)
526 if not os.path.exists(dstdir): 815 if not os.path.exists(dstdir):
527 os.makedirs(dstdir) 816 try:
817 os.makedirs(dstdir)
818 except PermissionError:
819 return False
820 except OSError as e:
821 if e.errno == errno.EROFS:
822 return False
823 else:
824 raise e
528 if p == "lib": 825 if p == "lib":
529 # Can race with other tests 826 # Can race with other tests
530 self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir) 827 self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
@@ -532,8 +829,12 @@ class RecipetoolTests(RecipetoolBase):
532 self.track_for_cleanup(dstdir) 829 self.track_for_cleanup(dstdir)
533 dstfile = os.path.join(dstdir, os.path.basename(srcfile)) 830 dstfile = os.path.join(dstdir, os.path.basename(srcfile))
534 if srcfile != dstfile: 831 if srcfile != dstfile:
535 shutil.copy(srcfile, dstfile) 832 try:
833 shutil.copy(srcfile, dstfile)
834 except PermissionError:
835 return False
536 self.track_for_cleanup(dstfile) 836 self.track_for_cleanup(dstfile)
837 return True
537 838
538 def test_recipetool_load_plugin(self): 839 def test_recipetool_load_plugin(self):
539 """Test that recipetool loads only the first found plugin in BBPATH.""" 840 """Test that recipetool loads only the first found plugin in BBPATH."""
@@ -547,20 +848,148 @@ class RecipetoolTests(RecipetoolBase):
547 plugincontent = fh.readlines() 848 plugincontent = fh.readlines()
548 try: 849 try:
549 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found') 850 self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found')
550 for path in searchpath: 851 searchpath = [
551 self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool') 852 path for path in searchpath
853 if self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool')
854 ]
552 result = runCmd("recipetool --quiet count") 855 result = runCmd("recipetool --quiet count")
553 self.assertEqual(result.output, '1') 856 self.assertEqual(result.output, '1')
554 result = runCmd("recipetool --quiet multiloaded") 857 result = runCmd("recipetool --quiet multiloaded")
555 self.assertEqual(result.output, "no") 858 self.assertEqual(result.output, "no")
556 for path in searchpath: 859 for path in searchpath:
557 result = runCmd("recipetool --quiet bbdir") 860 result = runCmd("recipetool --quiet bbdir")
558 self.assertEqual(result.output, path) 861 self.assertEqual(os.path.realpath(result.output), os.path.realpath(path))
559 os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py')) 862 os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py'))
560 finally: 863 finally:
561 with open(srcfile, 'w') as fh: 864 with open(srcfile, 'w') as fh:
562 fh.writelines(plugincontent) 865 fh.writelines(plugincontent)
563 866
867 def test_recipetool_handle_license_vars(self):
868 from create import handle_license_vars
869 from unittest.mock import Mock
870
871 commonlicdir = get_bb_var('COMMON_LICENSE_DIR')
872
873 class DataConnectorCopy(bb.tinfoil.TinfoilDataStoreConnector):
874 pass
875
876 d = DataConnectorCopy
877 d.getVar = Mock(return_value=commonlicdir)
878 d.expand = Mock(side_effect=lambda x: x)
879
880 srctree = tempfile.mkdtemp(prefix='recipetoolqa')
881 self.track_for_cleanup(srctree)
882
883 # Multiple licenses
884 licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0']
885 for licence in licenses:
886 shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence))
887 # Duplicate license
888 shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE'))
889
890 extravalues = {
891 # Duplicate and missing licenses
892 'LICENSE': 'Zlib & BSD-2-Clause & Zlib',
893 'LIC_FILES_CHKSUM': [
894 'file://README.md;md5=0123456789abcdef0123456789abcd'
895 ]
896 }
897 lines_before = []
898 handled = []
899 licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d)
900 expected_lines_before = [
901 '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is',
902 '# your responsibility to verify that the values are complete and correct.',
903 '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib',
904 '#',
905 '# NOTE: multiple licenses have been detected; they have been separated with &',
906 '# in the LICENSE value for now since it is a reasonable assumption that all',
907 '# of the licenses apply. If instead there is a choice between the multiple',
908 '# licenses then you should change the value to separate the licenses with |',
909 '# instead of &. If there is any doubt, check the accompanying documentation',
910 '# to determine which situation is applicable.',
911 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"',
912 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
913 ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n'
914 ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n'
915 ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n'
916 ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n'
917 ' file://README.md;md5=0123456789abcdef0123456789abcd"',
918 ''
919 ]
920 self.assertEqual(lines_before, expected_lines_before)
921 expected_licvalues = [
922 ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'),
923 ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'),
924 ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9'),
925 ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'),
926 ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302')
927 ]
928 self.assertEqual(handled, [('license', expected_licvalues)])
929 self.assertEqual(extravalues, {})
930 self.assertEqual(licvalues, expected_licvalues)
931
932
933 def test_recipetool_split_pkg_licenses(self):
934 from create import split_pkg_licenses
935 licvalues = [
936 # Duplicate licenses
937 ('BSD-2-Clause', 'x/COPYING', None),
938 ('BSD-2-Clause', 'x/LICENSE', None),
939 # Multiple licenses
940 ('MIT', 'x/a/LICENSE.MIT', None),
941 ('ISC', 'x/a/LICENSE.ISC', None),
942 # Alternative licenses
943 ('(MIT | ISC)', 'x/b/LICENSE', None),
944 # Alternative licenses without brackets
945 ('MIT | BSD-2-Clause', 'x/c/LICENSE', None),
946 # Multi licenses with alternatives
947 ('MIT', 'x/d/COPYING', None),
948 ('MIT | BSD-2-Clause', 'x/d/LICENSE', None),
949 # Multi licenses with alternatives and brackets
950 ('Apache-2.0 & ((MIT | ISC) & BSD-3-Clause)', 'x/e/LICENSE', None)
951 ]
952 packages = {
953 '${PN}': '',
954 'a': 'x/a',
955 'b': 'x/b',
956 'c': 'x/c',
957 'd': 'x/d',
958 'e': 'x/e',
959 'f': 'x/f',
960 'g': 'x/g',
961 }
962 fallback_licenses = {
963 # Ignored
964 'a': 'BSD-3-Clause',
965 # Used
966 'f': 'BSD-3-Clause'
967 }
968 outlines = []
969 outlicenses = split_pkg_licenses(licvalues, packages, outlines, fallback_licenses)
970 expected_outlicenses = {
971 '${PN}': ['BSD-2-Clause'],
972 'a': ['ISC', 'MIT'],
973 'b': ['(ISC | MIT)'],
974 'c': ['(BSD-2-Clause | MIT)'],
975 'd': ['(BSD-2-Clause | MIT)', 'MIT'],
976 'e': ['(ISC | MIT)', 'Apache-2.0', 'BSD-3-Clause'],
977 'f': ['BSD-3-Clause'],
978 'g': ['Unknown']
979 }
980 self.assertEqual(outlicenses, expected_outlicenses)
981 expected_outlines = [
982 'LICENSE:${PN} = "BSD-2-Clause"',
983 'LICENSE:a = "ISC & MIT"',
984 'LICENSE:b = "(ISC | MIT)"',
985 'LICENSE:c = "(BSD-2-Clause | MIT)"',
986 'LICENSE:d = "(BSD-2-Clause | MIT) & MIT"',
987 'LICENSE:e = "(ISC | MIT) & Apache-2.0 & BSD-3-Clause"',
988 'LICENSE:f = "BSD-3-Clause"',
989 'LICENSE:g = "Unknown"'
990 ]
991 self.assertEqual(outlines, expected_outlines)
992
564 993
565class RecipetoolAppendsrcBase(RecipetoolBase): 994class RecipetoolAppendsrcBase(RecipetoolBase):
566 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles): 995 def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles):
@@ -593,9 +1022,9 @@ class RecipetoolAppendsrcBase(RecipetoolBase):
593 for uri in src_uri: 1022 for uri in src_uri:
594 p = urllib.parse.urlparse(uri) 1023 p = urllib.parse.urlparse(uri)
595 if p.scheme == 'file': 1024 if p.scheme == 'file':
596 return p.netloc + p.path 1025 return p.netloc + p.path, uri
597 1026
598 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''): 1027 def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, remove=None, machine=None , options=''):
599 if newfile is None: 1028 if newfile is None:
600 newfile = self.testfile 1029 newfile = self.testfile
601 1030
@@ -620,14 +1049,42 @@ class RecipetoolAppendsrcBase(RecipetoolBase):
620 else: 1049 else:
621 destpath = '.' + os.sep 1050 destpath = '.' + os.sep
622 1051
623 expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', 1052 expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n',
624 '\n'] 1053 '\n']
1054
1055 override = ""
1056 if machine:
1057 options += ' -m %s' % machine
1058 override = ':append:%s' % machine
1059 expectedlines.extend(['PACKAGE_ARCH = "${MACHINE_ARCH}"\n',
1060 '\n'])
1061
1062 if remove:
1063 for entry in remove:
1064 if machine:
1065 entry_remove_line = 'SRC_URI:remove:%s = " %s"\n' % (machine, entry)
1066 else:
1067 entry_remove_line = 'SRC_URI:remove = "%s"\n' % entry
1068
1069 expectedlines.extend([entry_remove_line,
1070 '\n'])
1071
625 if has_src_uri: 1072 if has_src_uri:
626 uri = 'file://%s' % filename 1073 uri = 'file://%s' % filename
627 if expected_subdir: 1074 if expected_subdir:
628 uri += ';subdir=%s' % expected_subdir 1075 uri += ';subdir=%s' % expected_subdir
629 expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri, 1076 if machine:
630 '\n'] 1077 src_uri_line = 'SRC_URI%s = " %s"\n' % (override, uri)
1078 else:
1079 src_uri_line = 'SRC_URI += "%s"\n' % uri
1080
1081 expectedlines.extend([src_uri_line, '\n'])
1082
1083 with open("/tmp/tmp.txt", "w") as file:
1084 print(expectedlines, file=file)
1085
1086 if machine:
1087 filename = '%s/%s' % (machine, filename)
631 1088
632 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename]) 1089 return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename])
633 1090
@@ -674,34 +1131,62 @@ class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase):
674 1131
675 def test_recipetool_appendsrcfile_srcdir_basic(self): 1132 def test_recipetool_appendsrcfile_srcdir_basic(self):
676 testrecipe = 'bash' 1133 testrecipe = 'bash'
677 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) 1134 bb_vars = get_bb_vars(['S', 'UNPACKDIR'], testrecipe)
678 srcdir = bb_vars['S'] 1135 srcdir = bb_vars['S']
679 workdir = bb_vars['WORKDIR'] 1136 unpackdir = bb_vars['UNPACKDIR']
680 subdir = os.path.relpath(srcdir, workdir) 1137 subdir = os.path.relpath(srcdir, unpackdir)
681 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir) 1138 self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir)
682 1139
683 def test_recipetool_appendsrcfile_existing_in_src_uri(self): 1140 def test_recipetool_appendsrcfile_existing_in_src_uri(self):
684 testrecipe = 'base-files' 1141 testrecipe = 'base-files'
685 filepath = self._get_first_file_uri(testrecipe) 1142 filepath,_ = self._get_first_file_uri(testrecipe)
686 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) 1143 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
687 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False) 1144 self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False)
688 1145
689 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self): 1146 def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self, machine=None):
690 testrecipe = 'base-files' 1147 testrecipe = 'base-files'
691 subdir = 'tmp' 1148 subdir = 'tmp'
692 filepath = self._get_first_file_uri(testrecipe) 1149 filepath, srcuri_entry = self._get_first_file_uri(testrecipe)
693 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) 1150 self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe)
694 1151
695 output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False) 1152 self._test_appendsrcfile(testrecipe, filepath, subdir, machine=machine, remove=[srcuri_entry])
696 self.assertTrue(any('with different parameters' in l for l in output)) 1153
1154 def test_recipetool_appendsrcfile_machine(self):
1155 # A very basic test
1156 self._test_appendsrcfile('base-files', 'a-file', machine='mymachine')
1157
1158 # Force cleaning the output of previous test
1159 self.tearDownLocal()
1160
1161 # A more complex test: existing entry in src_uri with different param
1162 self.test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(machine='mymachine')
1163
1164 def test_recipetool_appendsrcfile_update_recipe_basic(self):
1165 testrecipe = "mtd-utils-selftest"
1166 recipefile = get_bb_var('FILE', testrecipe)
1167 self.assertIn('meta-selftest', recipefile, 'This test expect %s recipe to be in meta-selftest')
1168 cmd = 'recipetool appendsrcfile -W -u meta-selftest %s %s' % (testrecipe, self.testfile)
1169 result = runCmd(cmd)
1170 self.assertNotIn('Traceback', result.output)
1171 self.add_command_to_tearDown('cd %s; rm -f %s/%s; git checkout .' % (os.path.dirname(recipefile), testrecipe, os.path.basename(self.testfile)))
1172
1173 expected_status = [(' M', '.*/%s$' % os.path.basename(recipefile)),
1174 ('??', '.*/%s/%s$' % (testrecipe, os.path.basename(self.testfile)))]
1175 self._check_repo_status(os.path.dirname(recipefile), expected_status)
1176 result = runCmd('git diff %s' % os.path.basename(recipefile), cwd=os.path.dirname(recipefile))
1177 removelines = []
1178 addlines = [
1179 'file://%s \\\\' % os.path.basename(self.testfile),
1180 ]
1181 self._check_diff(result.output, addlines, removelines)
697 1182
698 def test_recipetool_appendsrcfile_replace_file_srcdir(self): 1183 def test_recipetool_appendsrcfile_replace_file_srcdir(self):
699 testrecipe = 'bash' 1184 testrecipe = 'bash'
700 filepath = 'Makefile.in' 1185 filepath = 'Makefile.in'
701 bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) 1186 bb_vars = get_bb_vars(['S', 'UNPACKDIR'], testrecipe)
702 srcdir = bb_vars['S'] 1187 srcdir = bb_vars['S']
703 workdir = bb_vars['WORKDIR'] 1188 unpackdir = bb_vars['UNPACKDIR']
704 subdir = os.path.relpath(srcdir, workdir) 1189 subdir = os.path.relpath(srcdir, unpackdir)
705 1190
706 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir) 1191 self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir)
707 bitbake('%s:do_unpack' % testrecipe) 1192 bitbake('%s:do_unpack' % testrecipe)