Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
| 2 | # SPDX-License-Identifier: MIT |
| 3 | # |
| 4 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 5 | import os |
| 6 | import shutil |
| 7 | import tempfile |
| 8 | import urllib.parse |
| 9 | |
| 10 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var |
| 11 | from oeqa.utils.commands import get_bb_vars, create_temp_layer |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 12 | from oeqa.selftest.cases import devtool |
| 13 | |
| 14 | templayerdir = None |
| 15 | |
| 16 | def setUpModule(): |
| 17 | global templayerdir |
| 18 | templayerdir = tempfile.mkdtemp(prefix='recipetoolqa') |
| 19 | create_temp_layer(templayerdir, 'selftestrecipetool') |
| 20 | runCmd('bitbake-layers add-layer %s' % templayerdir) |
| 21 | |
| 22 | |
| 23 | def tearDownModule(): |
| 24 | runCmd('bitbake-layers remove-layer %s' % templayerdir, ignore_status=True) |
| 25 | runCmd('rm -rf %s' % templayerdir) |
| 26 | |
| 27 | |
| 28 | class RecipetoolBase(devtool.DevtoolBase): |
| 29 | |
| 30 | def setUpLocal(self): |
| 31 | super(RecipetoolBase, self).setUpLocal() |
| 32 | self.templayerdir = templayerdir |
| 33 | self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa') |
| 34 | self.track_for_cleanup(self.tempdir) |
| 35 | self.testfile = os.path.join(self.tempdir, 'testfile') |
| 36 | with open(self.testfile, 'w') as f: |
| 37 | f.write('Test file\n') |
| 38 | |
| 39 | def tearDownLocal(self): |
| 40 | runCmd('rm -rf %s/recipes-*' % self.templayerdir) |
| 41 | super(RecipetoolBase, self).tearDownLocal() |
| 42 | |
| 43 | def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None): |
| 44 | result = runCmd(cmd) |
| 45 | self.assertNotIn('Traceback', result.output) |
| 46 | |
| 47 | # Check the bbappend was created and applies properly |
| 48 | recipefile = get_bb_var('FILE', testrecipe) |
| 49 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) |
| 50 | |
| 51 | # Check the bbappend contents |
| 52 | if expectedlines is not None: |
| 53 | with open(bbappendfile, 'r') as f: |
| 54 | self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile) |
| 55 | |
| 56 | # Check file was copied |
| 57 | filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe) |
| 58 | for expectedfile in expectedfiles: |
| 59 | self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile) |
| 60 | |
| 61 | # Check no other files created |
| 62 | createdfiles = [] |
| 63 | for root, _, files in os.walk(filesdir): |
| 64 | for f in files: |
| 65 | createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir)) |
| 66 | self.assertTrue(sorted(createdfiles), sorted(expectedfiles)) |
| 67 | |
| 68 | return bbappendfile, result.output |
| 69 | |
| 70 | |
| 71 | class RecipetoolTests(RecipetoolBase): |
| 72 | |
| 73 | @classmethod |
| 74 | def setUpClass(cls): |
| 75 | super(RecipetoolTests, cls).setUpClass() |
| 76 | # Ensure we have the right data in shlibs/pkgdata |
| 77 | cls.logger.info('Running bitbake to generate pkgdata') |
| 78 | bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile') |
| 79 | bb_vars = get_bb_vars(['COREBASE', 'BBPATH']) |
| 80 | cls.corebase = bb_vars['COREBASE'] |
| 81 | cls.bbpath = bb_vars['BBPATH'] |
| 82 | |
| 83 | def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles): |
| 84 | cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options) |
| 85 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) |
| 86 | |
| 87 | def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror): |
| 88 | cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile) |
| 89 | result = runCmd(cmd, ignore_status=True) |
| 90 | self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd) |
| 91 | self.assertNotIn('Traceback', result.output) |
| 92 | for errorstr in checkerror: |
| 93 | self.assertIn(errorstr, result.output) |
| 94 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 95 | def test_recipetool_appendfile_basic(self): |
| 96 | # Basic test |
| 97 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 98 | '\n'] |
| 99 | _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd']) |
| 100 | self.assertNotIn('WARNING: ', output) |
| 101 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 102 | def test_recipetool_appendfile_invalid(self): |
| 103 | # Test some commands that should error |
| 104 | self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers']) |
| 105 | self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool']) |
| 106 | self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool']) |
| 107 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 108 | def test_recipetool_appendfile_alternatives(self): |
| 109 | # 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) |
| 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']) |
| 112 | # Need a test file - should be executable |
| 113 | testfile2 = os.path.join(self.corebase, 'oe-init-build-env') |
| 114 | testfile2name = os.path.basename(testfile2) |
| 115 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 116 | '\n', |
| 117 | 'SRC_URI += "file://%s"\n' % testfile2name, |
| 118 | '\n', |
| 119 | 'do_install_append() {\n', |
| 120 | ' install -d ${D}${base_bindir}\n', |
| 121 | ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name, |
| 122 | '}\n'] |
| 123 | self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name]) |
| 124 | # 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]) |
| 126 | # But file should have |
| 127 | copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name) |
| 128 | result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True) |
| 129 | self.assertNotEqual(result.status, 0, 'New file should have been copied but was not %s' % result.output) |
| 130 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 131 | def test_recipetool_appendfile_binary(self): |
| 132 | # Try appending a binary file |
| 133 | # /bin/ls can be a symlink to /usr/bin/ls |
| 134 | ls = os.path.realpath("/bin/ls") |
| 135 | result = runCmd('recipetool appendfile %s /bin/ls %s -r coreutils' % (self.templayerdir, ls)) |
| 136 | self.assertIn('WARNING: ', result.output) |
| 137 | self.assertIn('is a binary', result.output) |
| 138 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 139 | def test_recipetool_appendfile_add(self): |
| 140 | # Try arbitrary file add to a recipe |
| 141 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 142 | '\n', |
| 143 | 'SRC_URI += "file://testfile"\n', |
| 144 | '\n', |
| 145 | 'do_install_append() {\n', |
| 146 | ' install -d ${D}${datadir}\n', |
| 147 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', |
| 148 | '}\n'] |
| 149 | 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 |
| 151 | # (so we're testing that, plus modifying an existing bbappend) |
| 152 | testfile2 = os.path.join(self.corebase, 'oe-init-build-env') |
| 153 | testfile2name = os.path.basename(testfile2) |
| 154 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 155 | '\n', |
| 156 | 'SRC_URI += "file://testfile \\\n', |
| 157 | ' file://%s \\\n' % testfile2name, |
| 158 | ' "\n', |
| 159 | '\n', |
| 160 | 'do_install_append() {\n', |
| 161 | ' install -d ${D}${datadir}\n', |
| 162 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', |
| 163 | ' install -m 0755 ${WORKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name, |
| 164 | '}\n'] |
| 165 | self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name]) |
| 166 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 167 | 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 |
| 169 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 170 | '\n', |
| 171 | 'SRC_URI += "file://testfile"\n', |
| 172 | '\n', |
| 173 | 'do_install_append() {\n', |
| 174 | ' install -d ${D}${bindir}\n', |
| 175 | ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n', |
| 176 | '}\n'] |
| 177 | _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile']) |
| 178 | self.assertNotIn('WARNING: ', output) |
| 179 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 180 | 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 |
| 182 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 183 | '\n', |
| 184 | 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n', |
| 185 | '\n', |
| 186 | 'SRC_URI_append_mymachine = " file://testfile"\n', |
| 187 | '\n', |
| 188 | 'do_install_append_mymachine() {\n', |
| 189 | ' install -d ${D}${datadir}\n', |
| 190 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', |
| 191 | '}\n'] |
| 192 | _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile']) |
| 193 | self.assertNotIn('WARNING: ', output) |
| 194 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 195 | def test_recipetool_appendfile_orig(self): |
| 196 | # A file that's in SRC_URI and in do_install with the same name |
| 197 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 198 | '\n'] |
| 199 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig']) |
| 200 | self.assertNotIn('WARNING: ', output) |
| 201 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 202 | def test_recipetool_appendfile_todir(self): |
| 203 | # A file that's in SRC_URI and in do_install with destination directory rather than file |
| 204 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 205 | '\n'] |
| 206 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir']) |
| 207 | self.assertNotIn('WARNING: ', output) |
| 208 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 209 | def test_recipetool_appendfile_renamed(self): |
| 210 | # A file that's in SRC_URI with a different name to the destination file |
| 211 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 212 | '\n'] |
| 213 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1']) |
| 214 | self.assertNotIn('WARNING: ', output) |
| 215 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 216 | def test_recipetool_appendfile_subdir(self): |
| 217 | # A file that's in SRC_URI in a subdir |
| 218 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 219 | '\n', |
| 220 | 'SRC_URI += "file://testfile"\n', |
| 221 | '\n', |
| 222 | 'do_install_append() {\n', |
| 223 | ' install -d ${D}${datadir}\n', |
| 224 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n', |
| 225 | '}\n'] |
| 226 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile']) |
| 227 | self.assertNotIn('WARNING: ', output) |
| 228 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 229 | def test_recipetool_appendfile_inst_glob(self): |
| 230 | # A file that's in do_install as a glob |
| 231 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 232 | '\n'] |
| 233 | _, 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) |
| 235 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 236 | def test_recipetool_appendfile_inst_todir_glob(self): |
| 237 | # A file that's in do_install as a glob with destination as a directory |
| 238 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 239 | '\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']) |
| 241 | self.assertNotIn('WARNING: ', output) |
| 242 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 243 | def test_recipetool_appendfile_patch(self): |
| 244 | # A file that's added by a patch in SRC_URI |
| 245 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 246 | '\n', |
| 247 | 'SRC_URI += "file://testfile"\n', |
| 248 | '\n', |
| 249 | 'do_install_append() {\n', |
| 250 | ' install -d ${D}${sysconfdir}\n', |
| 251 | ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n', |
| 252 | '}\n'] |
| 253 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile']) |
| 254 | for line in output.splitlines(): |
| 255 | if 'WARNING: ' in line: |
| 256 | self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line) |
| 257 | break |
| 258 | else: |
| 259 | self.fail('Patch warning not found in output:\n%s' % output) |
| 260 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 261 | 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) |
| 263 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 264 | '\n', |
| 265 | 'SRC_URI += "file://testfile"\n', |
| 266 | '\n', |
| 267 | 'do_install_append() {\n', |
| 268 | ' install -d ${D}${datadir}\n', |
| 269 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n', |
| 270 | '}\n'] |
| 271 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile']) |
| 272 | self.assertNotIn('WARNING: ', output) |
| 273 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 274 | def test_recipetool_appendfile_inst_func(self): |
| 275 | # A file that's installed from a function called by do_install |
| 276 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 277 | '\n'] |
| 278 | _, 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) |
| 280 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 281 | def test_recipetool_appendfile_postinstall(self): |
| 282 | # A file that's created by a postinstall script (and explicitly mentioned in it) |
| 283 | # 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']) |
| 285 | # Now specify recipe |
| 286 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 287 | '\n', |
| 288 | 'SRC_URI += "file://testfile"\n', |
| 289 | '\n', |
| 290 | 'do_install_append() {\n', |
| 291 | ' install -d ${D}${datadir}\n', |
| 292 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n', |
| 293 | '}\n'] |
| 294 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile']) |
| 295 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 296 | def test_recipetool_appendfile_extlayer(self): |
| 297 | # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure |
| 298 | exttemplayerdir = os.path.join(self.tempdir, 'extlayer') |
| 299 | self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*') |
| 300 | result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile)) |
| 301 | self.assertNotIn('Traceback', result.output) |
| 302 | createdfiles = [] |
| 303 | for root, _, files in os.walk(exttemplayerdir): |
| 304 | for f in files: |
| 305 | createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir)) |
| 306 | createdfiles.remove('conf/layer.conf') |
| 307 | expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend', |
| 308 | 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig'] |
| 309 | self.assertEqual(sorted(createdfiles), sorted(expectedfiles)) |
| 310 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 311 | def test_recipetool_appendfile_wildcard(self): |
| 312 | |
| 313 | def try_appendfile_wc(options): |
| 314 | result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options)) |
| 315 | self.assertNotIn('Traceback', result.output) |
| 316 | bbappendfile = None |
| 317 | for root, _, files in os.walk(self.templayerdir): |
| 318 | for f in files: |
| 319 | if f.endswith('.bbappend'): |
| 320 | bbappendfile = f |
| 321 | break |
| 322 | if not bbappendfile: |
| 323 | self.fail('No bbappend file created') |
| 324 | runCmd('rm -rf %s/recipes-*' % self.templayerdir) |
| 325 | return bbappendfile |
| 326 | |
| 327 | # Check without wildcard option |
| 328 | recipefn = os.path.basename(get_bb_var('FILE', 'base-files')) |
| 329 | filename = try_appendfile_wc('') |
| 330 | self.assertEqual(filename, recipefn.replace('.bb', '.bbappend')) |
| 331 | # Now check with wildcard option |
| 332 | filename = try_appendfile_wc('-w') |
| 333 | self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend') |
| 334 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 335 | def test_recipetool_create(self): |
| 336 | # Try adding a recipe |
| 337 | tempsrc = os.path.join(self.tempdir, 'srctree') |
| 338 | os.makedirs(tempsrc) |
| 339 | recipefile = os.path.join(self.tempdir, 'logrotate_3.12.3.bb') |
| 340 | srcuri = 'https://github.com/logrotate/logrotate/releases/download/3.12.3/logrotate-3.12.3.tar.xz' |
| 341 | result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc)) |
| 342 | self.assertTrue(os.path.isfile(recipefile)) |
| 343 | checkvars = {} |
| 344 | checkvars['LICENSE'] = 'GPLv2' |
| 345 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263' |
| 346 | 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' |
| 349 | self._test_recipe_contents(recipefile, checkvars, []) |
| 350 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 351 | def test_recipetool_create_git(self): |
| 352 | if 'x11' not in get_bb_var('DISTRO_FEATURES'): |
| 353 | self.skipTest('Test requires x11 as distro feature') |
| 354 | # Ensure we have the right data in shlibs/pkgdata |
| 355 | bitbake('libpng pango libx11 libxext jpeg libcheck') |
| 356 | # Try adding a recipe |
| 357 | tempsrc = os.path.join(self.tempdir, 'srctree') |
| 358 | os.makedirs(tempsrc) |
| 359 | recipefile = os.path.join(self.tempdir, 'libmatchbox.bb') |
| 360 | srcuri = 'git://git.yoctoproject.org/libmatchbox' |
| 361 | 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) |
| 363 | checkvars = {} |
| 364 | checkvars['LICENSE'] = 'LGPLv2.1' |
| 365 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34' |
| 366 | checkvars['S'] = '${WORKDIR}/git' |
| 367 | checkvars['PV'] = '1.11+git${SRCPV}' |
| 368 | checkvars['SRC_URI'] = srcuri |
| 369 | checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango']) |
| 370 | inherits = ['autotools', 'pkgconfig'] |
| 371 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 372 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 373 | def test_recipetool_create_simple(self): |
| 374 | # Try adding a recipe |
| 375 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 376 | os.makedirs(temprecipe) |
| 377 | pv = '1.7.3.0' |
| 378 | srcuri = 'http://www.dest-unreach.org/socat/download/socat-%s.tar.bz2' % pv |
| 379 | result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe)) |
| 380 | dirlist = os.listdir(temprecipe) |
| 381 | if len(dirlist) > 1: |
| 382 | self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist))) |
| 383 | if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])): |
| 384 | 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') |
| 386 | checkvars = {} |
| 387 | checkvars['LICENSE'] = set(['Unknown', 'GPLv2']) |
| 388 | 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 |
| 390 | checkvars['S'] = None |
| 391 | checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}') |
| 392 | inherits = ['autotools'] |
| 393 | self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits) |
| 394 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 395 | def test_recipetool_create_cmake(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 396 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 397 | os.makedirs(temprecipe) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 398 | recipefile = os.path.join(temprecipe, 'taglib_1.11.1.bb') |
| 399 | srcuri = 'http://taglib.github.io/releases/taglib-1.11.1.tar.gz' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 400 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 401 | self.assertTrue(os.path.isfile(recipefile)) |
| 402 | checkvars = {} |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 403 | checkvars['LICENSE'] = set(['LGPLv2.1', 'MPL-1.1']) |
| 404 | checkvars['SRC_URI'] = 'http://taglib.github.io/releases/taglib-${PV}.tar.gz' |
| 405 | checkvars['SRC_URI[md5sum]'] = 'cee7be0ccfc892fa433d6c837df9522a' |
| 406 | checkvars['SRC_URI[sha256sum]'] = 'b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b' |
| 407 | checkvars['DEPENDS'] = set(['boost', 'zlib']) |
| 408 | inherits = ['cmake'] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 409 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 410 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 411 | def test_recipetool_create_npm(self): |
| 412 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 413 | os.makedirs(temprecipe) |
| 414 | recipefile = os.path.join(temprecipe, 'savoirfairelinux-node-server-example_1.0.0.bb') |
| 415 | shrinkwrap = os.path.join(temprecipe, 'savoirfairelinux-node-server-example', 'npm-shrinkwrap.json') |
| 416 | srcuri = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 417 | result = runCmd('recipetool create -o %s \'%s\'' % (temprecipe, srcuri)) |
| 418 | self.assertTrue(os.path.isfile(recipefile)) |
| 419 | self.assertTrue(os.path.isfile(shrinkwrap)) |
| 420 | checkvars = {} |
| 421 | checkvars['SUMMARY'] = 'Node Server Example' |
| 422 | checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme' |
| 423 | checkvars['LICENSE'] = set(['MIT', 'ISC', 'Unknown']) |
| 424 | urls = [] |
| 425 | urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}') |
| 426 | urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json') |
| 427 | checkvars['SRC_URI'] = set(urls) |
| 428 | checkvars['S'] = '${WORKDIR}/npm' |
| 429 | checkvars['LICENSE_${PN}'] = 'MIT' |
| 430 | checkvars['LICENSE_${PN}-base64'] = 'Unknown' |
| 431 | checkvars['LICENSE_${PN}-accepts'] = 'MIT' |
| 432 | checkvars['LICENSE_${PN}-inherits'] = 'ISC' |
| 433 | inherits = ['npm'] |
| 434 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 435 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 436 | def test_recipetool_create_github(self): |
| 437 | # Basic test to see if github URL mangling works |
| 438 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 439 | os.makedirs(temprecipe) |
| 440 | recipefile = os.path.join(temprecipe, 'meson_git.bb') |
| 441 | srcuri = 'https://github.com/mesonbuild/meson;rev=0.32.0' |
| 442 | result = runCmd(['recipetool', 'create', '-o', temprecipe, srcuri]) |
| 443 | self.assertTrue(os.path.isfile(recipefile)) |
| 444 | checkvars = {} |
| 445 | checkvars['LICENSE'] = set(['Apache-2.0']) |
| 446 | checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https' |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 447 | inherits = ['setuptools3'] |
| 448 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 449 | |
| 450 | def test_recipetool_create_python3_setuptools(self): |
| 451 | # Test creating python3 package from tarball (using setuptools3 class) |
| 452 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 453 | os.makedirs(temprecipe) |
| 454 | pn = 'python-magic' |
| 455 | pv = '0.4.15' |
| 456 | recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv)) |
| 457 | srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv |
| 458 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 459 | self.assertTrue(os.path.isfile(recipefile)) |
| 460 | checkvars = {} |
| 461 | checkvars['LICENSE'] = set(['MIT']) |
| 462 | checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88' |
| 463 | checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-${PV}.tar.gz' |
| 464 | checkvars['SRC_URI[md5sum]'] = 'e384c95a47218f66c6501cd6dd45ff59' |
| 465 | checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5' |
| 466 | inherits = ['setuptools3'] |
| 467 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 468 | |
| 469 | def test_recipetool_create_python3_distutils(self): |
| 470 | # Test creating python3 package from tarball (using distutils3 class) |
| 471 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 472 | os.makedirs(temprecipe) |
| 473 | pn = 'docutils' |
| 474 | pv = '0.14' |
| 475 | recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv)) |
| 476 | srcuri = 'https://files.pythonhosted.org/packages/84/f4/5771e41fdf52aabebbadecc9381d11dea0fa34e4759b4071244fa094804c/docutils-%s.tar.gz' % pv |
| 477 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 478 | self.assertTrue(os.path.isfile(recipefile)) |
| 479 | checkvars = {} |
| 480 | checkvars['LICENSE'] = set(['PSF', '&', 'BSD', 'GPL']) |
| 481 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING.txt;md5=35a23d42b615470583563132872c97d6' |
| 482 | checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/f4/5771e41fdf52aabebbadecc9381d11dea0fa34e4759b4071244fa094804c/docutils-${PV}.tar.gz' |
| 483 | checkvars['SRC_URI[md5sum]'] = 'c53768d63db3873b7d452833553469de' |
| 484 | checkvars['SRC_URI[sha256sum]'] = '51e64ef2ebfb29cae1faa133b3710143496eca21c530f3f71424d77687764274' |
| 485 | inherits = ['distutils3'] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 486 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 487 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 488 | def test_recipetool_create_github_tarball(self): |
| 489 | # Basic test to ensure github URL mangling doesn't apply to release tarballs |
| 490 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 491 | os.makedirs(temprecipe) |
| 492 | pv = '0.32.0' |
| 493 | recipefile = os.path.join(temprecipe, 'meson_%s.bb' % pv) |
| 494 | srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv) |
| 495 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 496 | self.assertTrue(os.path.isfile(recipefile)) |
| 497 | checkvars = {} |
| 498 | checkvars['LICENSE'] = set(['Apache-2.0']) |
| 499 | checkvars['SRC_URI'] = 'https://github.com/mesonbuild/meson/releases/download/${PV}/meson-${PV}.tar.gz' |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 500 | inherits = ['setuptools3'] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 501 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 502 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 503 | def test_recipetool_create_git_http(self): |
| 504 | # Basic test to check http git URL mangling works |
| 505 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 506 | os.makedirs(temprecipe) |
| 507 | recipefile = os.path.join(temprecipe, 'matchbox-terminal_git.bb') |
| 508 | srcuri = 'http://git.yoctoproject.org/git/matchbox-terminal' |
| 509 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 510 | self.assertTrue(os.path.isfile(recipefile)) |
| 511 | checkvars = {} |
| 512 | checkvars['LICENSE'] = set(['GPLv2']) |
| 513 | checkvars['SRC_URI'] = 'git://git.yoctoproject.org/git/matchbox-terminal;protocol=http' |
| 514 | inherits = ['pkgconfig', 'autotools'] |
| 515 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 516 | |
| 517 | def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths): |
| 518 | dstdir = basedstdir |
| 519 | self.assertTrue(os.path.exists(dstdir)) |
| 520 | for p in paths: |
| 521 | dstdir = os.path.join(dstdir, p) |
| 522 | if not os.path.exists(dstdir): |
| 523 | os.makedirs(dstdir) |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 524 | if p == "lib": |
| 525 | # Can race with other tests |
| 526 | self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir) |
| 527 | else: |
| 528 | self.track_for_cleanup(dstdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 529 | dstfile = os.path.join(dstdir, os.path.basename(srcfile)) |
| 530 | if srcfile != dstfile: |
| 531 | shutil.copy(srcfile, dstfile) |
| 532 | self.track_for_cleanup(dstfile) |
| 533 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 534 | def test_recipetool_load_plugin(self): |
| 535 | """Test that recipetool loads only the first found plugin in BBPATH.""" |
| 536 | |
| 537 | recipetool = runCmd("which recipetool") |
| 538 | fromname = runCmd("recipetool --quiet pluginfile") |
| 539 | srcfile = fromname.output |
| 540 | searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)] |
| 541 | plugincontent = [] |
| 542 | with open(srcfile) as fh: |
| 543 | plugincontent = fh.readlines() |
| 544 | try: |
| 545 | self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found') |
| 546 | for path in searchpath: |
| 547 | self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool') |
| 548 | result = runCmd("recipetool --quiet count") |
| 549 | self.assertEqual(result.output, '1') |
| 550 | result = runCmd("recipetool --quiet multiloaded") |
| 551 | self.assertEqual(result.output, "no") |
| 552 | for path in searchpath: |
| 553 | result = runCmd("recipetool --quiet bbdir") |
| 554 | self.assertEqual(result.output, path) |
| 555 | os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py')) |
| 556 | finally: |
| 557 | with open(srcfile, 'w') as fh: |
| 558 | fh.writelines(plugincontent) |
| 559 | |
| 560 | |
| 561 | class RecipetoolAppendsrcBase(RecipetoolBase): |
| 562 | def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles): |
| 563 | cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile) |
| 564 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) |
| 565 | |
| 566 | def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''): |
| 567 | |
| 568 | if destdir: |
| 569 | options += ' -D %s' % destdir |
| 570 | |
| 571 | if expectedfiles is None: |
| 572 | expectedfiles = [os.path.basename(f) for f in newfiles] |
| 573 | |
| 574 | cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles)) |
| 575 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) |
| 576 | |
| 577 | def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror): |
| 578 | cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '') |
| 579 | result = runCmd(cmd, ignore_status=True) |
| 580 | self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd) |
| 581 | self.assertNotIn('Traceback', result.output) |
| 582 | for errorstr in checkerror: |
| 583 | self.assertIn(errorstr, result.output) |
| 584 | |
| 585 | @staticmethod |
| 586 | def _get_first_file_uri(recipe): |
| 587 | '''Return the first file:// in SRC_URI for the specified recipe.''' |
| 588 | src_uri = get_bb_var('SRC_URI', recipe).split() |
| 589 | for uri in src_uri: |
| 590 | p = urllib.parse.urlparse(uri) |
| 591 | if p.scheme == 'file': |
| 592 | return p.netloc + p.path |
| 593 | |
| 594 | def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''): |
| 595 | if newfile is None: |
| 596 | newfile = self.testfile |
| 597 | |
| 598 | if srcdir: |
| 599 | if destdir: |
| 600 | expected_subdir = os.path.join(srcdir, destdir) |
| 601 | else: |
| 602 | expected_subdir = srcdir |
| 603 | else: |
| 604 | options += " -W" |
| 605 | expected_subdir = destdir |
| 606 | |
| 607 | if filename: |
| 608 | if destdir: |
| 609 | destpath = os.path.join(destdir, filename) |
| 610 | else: |
| 611 | destpath = filename |
| 612 | else: |
| 613 | filename = os.path.basename(newfile) |
| 614 | if destdir: |
| 615 | destpath = destdir + os.sep |
| 616 | else: |
| 617 | destpath = '.' + os.sep |
| 618 | |
| 619 | expectedlines = ['FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"\n', |
| 620 | '\n'] |
| 621 | if has_src_uri: |
| 622 | uri = 'file://%s' % filename |
| 623 | if expected_subdir: |
| 624 | uri += ';subdir=%s' % expected_subdir |
| 625 | expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri, |
| 626 | '\n'] |
| 627 | |
| 628 | return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename]) |
| 629 | |
| 630 | def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''): |
| 631 | if expectedfiles is None: |
| 632 | expectedfiles = [os.path.basename(n) for n in newfiles] |
| 633 | |
| 634 | self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options) |
| 635 | |
| 636 | bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe) |
| 637 | src_uri = bb_vars['SRC_URI'].split() |
| 638 | for f in expectedfiles: |
| 639 | if destdir: |
| 640 | self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri) |
| 641 | else: |
| 642 | self.assertIn('file://%s' % f, src_uri) |
| 643 | |
| 644 | recipefile = bb_vars['FILE'] |
| 645 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) |
| 646 | filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe) |
| 647 | filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':') |
| 648 | self.assertIn(filesdir, filesextrapaths) |
| 649 | |
| 650 | |
| 651 | |
| 652 | |
| 653 | class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase): |
| 654 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 655 | def test_recipetool_appendsrcfile_basic(self): |
| 656 | self._test_appendsrcfile('base-files', 'a-file') |
| 657 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 658 | def test_recipetool_appendsrcfile_basic_wildcard(self): |
| 659 | testrecipe = 'base-files' |
| 660 | self._test_appendsrcfile(testrecipe, 'a-file', options='-w') |
| 661 | recipefile = get_bb_var('FILE', testrecipe) |
| 662 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) |
| 663 | self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe) |
| 664 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 665 | def test_recipetool_appendsrcfile_subdir_basic(self): |
| 666 | self._test_appendsrcfile('base-files', 'a-file', 'tmp') |
| 667 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 668 | def test_recipetool_appendsrcfile_subdir_basic_dirdest(self): |
| 669 | self._test_appendsrcfile('base-files', destdir='tmp') |
| 670 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 671 | def test_recipetool_appendsrcfile_srcdir_basic(self): |
| 672 | testrecipe = 'bash' |
| 673 | bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) |
| 674 | srcdir = bb_vars['S'] |
| 675 | workdir = bb_vars['WORKDIR'] |
| 676 | subdir = os.path.relpath(srcdir, workdir) |
| 677 | self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir) |
| 678 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 679 | def test_recipetool_appendsrcfile_existing_in_src_uri(self): |
| 680 | testrecipe = 'base-files' |
| 681 | filepath = self._get_first_file_uri(testrecipe) |
| 682 | self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) |
| 683 | self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False) |
| 684 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 685 | def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self): |
| 686 | testrecipe = 'base-files' |
| 687 | subdir = 'tmp' |
| 688 | filepath = self._get_first_file_uri(testrecipe) |
| 689 | self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) |
| 690 | |
| 691 | output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False) |
| 692 | self.assertTrue(any('with different parameters' in l for l in output)) |
| 693 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 694 | def test_recipetool_appendsrcfile_replace_file_srcdir(self): |
| 695 | testrecipe = 'bash' |
| 696 | filepath = 'Makefile.in' |
| 697 | bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) |
| 698 | srcdir = bb_vars['S'] |
| 699 | workdir = bb_vars['WORKDIR'] |
| 700 | subdir = os.path.relpath(srcdir, workdir) |
| 701 | |
| 702 | self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir) |
| 703 | bitbake('%s:do_unpack' % testrecipe) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 704 | with open(self.testfile, 'r') as testfile: |
| 705 | with open(os.path.join(srcdir, filepath), 'r') as makefilein: |
| 706 | self.assertEqual(testfile.read(), makefilein.read()) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 707 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 708 | def test_recipetool_appendsrcfiles_basic(self, destdir=None): |
| 709 | newfiles = [self.testfile] |
| 710 | for i in range(1, 5): |
| 711 | testfile = os.path.join(self.tempdir, 'testfile%d' % i) |
| 712 | with open(testfile, 'w') as f: |
| 713 | f.write('Test file %d\n' % i) |
| 714 | newfiles.append(testfile) |
| 715 | self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W') |
| 716 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 717 | def test_recipetool_appendsrcfiles_basic_subdir(self): |
| 718 | self.test_recipetool_appendsrcfiles_basic(destdir='testdir') |