Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 1 | # |
Patrick Williams | 92b42cb | 2022-09-03 06:53:57 -0500 | [diff] [blame] | 2 | # Copyright OpenEmbedded Contributors |
| 3 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | # SPDX-License-Identifier: MIT |
| 5 | # |
| 6 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 7 | import os |
| 8 | import shutil |
| 9 | import tempfile |
| 10 | import urllib.parse |
| 11 | |
| 12 | from oeqa.utils.commands import runCmd, bitbake, get_bb_var |
| 13 | from oeqa.utils.commands import get_bb_vars, create_temp_layer |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 14 | from oeqa.selftest.cases import devtool |
| 15 | |
| 16 | templayerdir = None |
| 17 | |
| 18 | def setUpModule(): |
| 19 | global templayerdir |
| 20 | templayerdir = tempfile.mkdtemp(prefix='recipetoolqa') |
| 21 | create_temp_layer(templayerdir, 'selftestrecipetool') |
| 22 | runCmd('bitbake-layers add-layer %s' % templayerdir) |
| 23 | |
| 24 | |
| 25 | def tearDownModule(): |
| 26 | runCmd('bitbake-layers remove-layer %s' % templayerdir, ignore_status=True) |
| 27 | runCmd('rm -rf %s' % templayerdir) |
| 28 | |
| 29 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 30 | class RecipetoolBase(devtool.DevtoolTestCase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 31 | |
| 32 | def setUpLocal(self): |
| 33 | super(RecipetoolBase, self).setUpLocal() |
| 34 | self.templayerdir = templayerdir |
| 35 | self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa') |
| 36 | self.track_for_cleanup(self.tempdir) |
| 37 | self.testfile = os.path.join(self.tempdir, 'testfile') |
| 38 | with open(self.testfile, 'w') as f: |
| 39 | f.write('Test file\n') |
| 40 | |
| 41 | def tearDownLocal(self): |
| 42 | runCmd('rm -rf %s/recipes-*' % self.templayerdir) |
| 43 | super(RecipetoolBase, self).tearDownLocal() |
| 44 | |
| 45 | def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None): |
| 46 | result = runCmd(cmd) |
| 47 | self.assertNotIn('Traceback', result.output) |
| 48 | |
| 49 | # Check the bbappend was created and applies properly |
| 50 | recipefile = get_bb_var('FILE', testrecipe) |
| 51 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) |
| 52 | |
| 53 | # Check the bbappend contents |
| 54 | if expectedlines is not None: |
| 55 | with open(bbappendfile, 'r') as f: |
| 56 | self.assertEqual(expectedlines, f.readlines(), "Expected lines are not present in %s" % bbappendfile) |
| 57 | |
| 58 | # Check file was copied |
| 59 | filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe) |
| 60 | for expectedfile in expectedfiles: |
| 61 | self.assertTrue(os.path.isfile(os.path.join(filesdir, expectedfile)), 'Expected file %s to be copied next to bbappend, but it wasn\'t' % expectedfile) |
| 62 | |
| 63 | # Check no other files created |
| 64 | createdfiles = [] |
| 65 | for root, _, files in os.walk(filesdir): |
| 66 | for f in files: |
| 67 | createdfiles.append(os.path.relpath(os.path.join(root, f), filesdir)) |
| 68 | self.assertTrue(sorted(createdfiles), sorted(expectedfiles)) |
| 69 | |
| 70 | return bbappendfile, result.output |
| 71 | |
| 72 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 73 | class RecipetoolAppendTests(RecipetoolBase): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 74 | |
| 75 | @classmethod |
| 76 | def setUpClass(cls): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 77 | super(RecipetoolAppendTests, cls).setUpClass() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 78 | # Ensure we have the right data in shlibs/pkgdata |
| 79 | cls.logger.info('Running bitbake to generate pkgdata') |
| 80 | bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile') |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 81 | bb_vars = get_bb_vars(['COREBASE']) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 82 | cls.corebase = bb_vars['COREBASE'] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 83 | |
| 84 | def _try_recipetool_appendfile(self, testrecipe, destfile, newfile, options, expectedlines, expectedfiles): |
| 85 | cmd = 'recipetool appendfile %s %s %s %s' % (self.templayerdir, destfile, newfile, options) |
| 86 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) |
| 87 | |
| 88 | def _try_recipetool_appendfile_fail(self, destfile, newfile, checkerror): |
| 89 | cmd = 'recipetool appendfile %s %s %s' % (self.templayerdir, destfile, newfile) |
| 90 | result = runCmd(cmd, ignore_status=True) |
| 91 | self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd) |
| 92 | self.assertNotIn('Traceback', result.output) |
| 93 | for errorstr in checkerror: |
| 94 | self.assertIn(errorstr, result.output) |
| 95 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 96 | def test_recipetool_appendfile_basic(self): |
| 97 | # Basic test |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 98 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 99 | '\n'] |
| 100 | _, output = self._try_recipetool_appendfile('base-files', '/etc/motd', self.testfile, '', expectedlines, ['motd']) |
| 101 | self.assertNotIn('WARNING: ', output) |
| 102 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 103 | def test_recipetool_appendfile_invalid(self): |
| 104 | # Test some commands that should error |
| 105 | self._try_recipetool_appendfile_fail('/etc/passwd', self.testfile, ['ERROR: /etc/passwd cannot be handled by this tool', 'useradd', 'extrausers']) |
| 106 | self._try_recipetool_appendfile_fail('/etc/timestamp', self.testfile, ['ERROR: /etc/timestamp cannot be handled by this tool']) |
| 107 | self._try_recipetool_appendfile_fail('/dev/console', self.testfile, ['ERROR: /dev/console cannot be handled by this tool']) |
| 108 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 109 | def test_recipetool_appendfile_alternatives(self): |
| 110 | # Now try with a file we know should be an alternative |
| 111 | # (this is very much a fake example, but one we know is reliably an alternative) |
| 112 | self._try_recipetool_appendfile_fail('/bin/ls', self.testfile, ['ERROR: File /bin/ls is an alternative possibly provided by the following recipes:', 'coreutils', 'busybox']) |
| 113 | # Need a test file - should be executable |
| 114 | testfile2 = os.path.join(self.corebase, 'oe-init-build-env') |
| 115 | testfile2name = os.path.basename(testfile2) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 116 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 117 | '\n', |
| 118 | 'SRC_URI += "file://%s"\n' % testfile2name, |
| 119 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 120 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 121 | ' install -d ${D}${base_bindir}\n', |
| 122 | ' install -m 0755 ${WORKDIR}/%s ${D}${base_bindir}/ls\n' % testfile2name, |
| 123 | '}\n'] |
| 124 | self._try_recipetool_appendfile('coreutils', '/bin/ls', testfile2, '-r coreutils', expectedlines, [testfile2name]) |
| 125 | # Now try bbappending the same file again, contents should not change |
| 126 | bbappendfile, _ = self._try_recipetool_appendfile('coreutils', '/bin/ls', self.testfile, '-r coreutils', expectedlines, [testfile2name]) |
| 127 | # But file should have |
| 128 | copiedfile = os.path.join(os.path.dirname(bbappendfile), 'coreutils', testfile2name) |
| 129 | result = runCmd('diff -q %s %s' % (testfile2, copiedfile), ignore_status=True) |
| 130 | self.assertNotEqual(result.status, 0, 'New file should have been copied but was not %s' % result.output) |
| 131 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 132 | def test_recipetool_appendfile_binary(self): |
| 133 | # Try appending a binary file |
| 134 | # /bin/ls can be a symlink to /usr/bin/ls |
| 135 | ls = os.path.realpath("/bin/ls") |
| 136 | result = runCmd('recipetool appendfile %s /bin/ls %s -r coreutils' % (self.templayerdir, ls)) |
| 137 | self.assertIn('WARNING: ', result.output) |
| 138 | self.assertIn('is a binary', result.output) |
| 139 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 140 | def test_recipetool_appendfile_add(self): |
| 141 | # Try arbitrary file add to a recipe |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 142 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 143 | '\n', |
| 144 | 'SRC_URI += "file://testfile"\n', |
| 145 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 146 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 147 | ' install -d ${D}${datadir}\n', |
| 148 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', |
| 149 | '}\n'] |
| 150 | self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase', expectedlines, ['testfile']) |
| 151 | # Try adding another file, this time where the source file is executable |
| 152 | # (so we're testing that, plus modifying an existing bbappend) |
| 153 | testfile2 = os.path.join(self.corebase, 'oe-init-build-env') |
| 154 | testfile2name = os.path.basename(testfile2) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 155 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 156 | '\n', |
| 157 | 'SRC_URI += "file://testfile \\\n', |
| 158 | ' file://%s \\\n' % testfile2name, |
| 159 | ' "\n', |
| 160 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 161 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 162 | ' install -d ${D}${datadir}\n', |
| 163 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', |
| 164 | ' install -m 0755 ${WORKDIR}/%s ${D}${datadir}/scriptname\n' % testfile2name, |
| 165 | '}\n'] |
| 166 | self._try_recipetool_appendfile('netbase', '/usr/share/scriptname', testfile2, '-r netbase', expectedlines, ['testfile', testfile2name]) |
| 167 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 168 | def test_recipetool_appendfile_add_bindir(self): |
| 169 | # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 170 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 171 | '\n', |
| 172 | 'SRC_URI += "file://testfile"\n', |
| 173 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 174 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 175 | ' install -d ${D}${bindir}\n', |
| 176 | ' install -m 0755 ${WORKDIR}/testfile ${D}${bindir}/selftest-recipetool-testbin\n', |
| 177 | '}\n'] |
| 178 | _, output = self._try_recipetool_appendfile('netbase', '/usr/bin/selftest-recipetool-testbin', self.testfile, '-r netbase', expectedlines, ['testfile']) |
| 179 | self.assertNotIn('WARNING: ', output) |
| 180 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 181 | def test_recipetool_appendfile_add_machine(self): |
| 182 | # Try arbitrary file add to a recipe, this time to a location such that should be installed as executable |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 183 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 184 | '\n', |
| 185 | 'PACKAGE_ARCH = "${MACHINE_ARCH}"\n', |
| 186 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 187 | 'SRC_URI:append:mymachine = " file://testfile"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 188 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 189 | 'do_install:append:mymachine() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 190 | ' install -d ${D}${datadir}\n', |
| 191 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/something\n', |
| 192 | '}\n'] |
| 193 | _, output = self._try_recipetool_appendfile('netbase', '/usr/share/something', self.testfile, '-r netbase -m mymachine', expectedlines, ['mymachine/testfile']) |
| 194 | self.assertNotIn('WARNING: ', output) |
| 195 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 196 | def test_recipetool_appendfile_orig(self): |
| 197 | # A file that's in SRC_URI and in do_install with the same name |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 198 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 199 | '\n'] |
| 200 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-orig', self.testfile, '', expectedlines, ['selftest-replaceme-orig']) |
| 201 | self.assertNotIn('WARNING: ', output) |
| 202 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 203 | def test_recipetool_appendfile_todir(self): |
| 204 | # A file that's in SRC_URI and in do_install with destination directory rather than file |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 205 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 206 | '\n'] |
| 207 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-todir', self.testfile, '', expectedlines, ['selftest-replaceme-todir']) |
| 208 | self.assertNotIn('WARNING: ', output) |
| 209 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 210 | def test_recipetool_appendfile_renamed(self): |
| 211 | # A file that's in SRC_URI with a different name to the destination file |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 212 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 213 | '\n'] |
| 214 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-renamed', self.testfile, '', expectedlines, ['file1']) |
| 215 | self.assertNotIn('WARNING: ', output) |
| 216 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 217 | def test_recipetool_appendfile_subdir(self): |
| 218 | # A file that's in SRC_URI in a subdir |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 219 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 220 | '\n', |
| 221 | 'SRC_URI += "file://testfile"\n', |
| 222 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 223 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 224 | ' install -d ${D}${datadir}\n', |
| 225 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-subdir\n', |
| 226 | '}\n'] |
| 227 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-subdir', self.testfile, '', expectedlines, ['testfile']) |
| 228 | self.assertNotIn('WARNING: ', output) |
| 229 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 230 | def test_recipetool_appendfile_inst_glob(self): |
| 231 | # A file that's in do_install as a glob |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 232 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 233 | '\n'] |
| 234 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-globfile']) |
| 235 | self.assertNotIn('WARNING: ', output) |
| 236 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 237 | def test_recipetool_appendfile_inst_todir_glob(self): |
| 238 | # A file that's in do_install as a glob with destination as a directory |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 239 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 240 | '\n'] |
| 241 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-todir-globfile', self.testfile, '', expectedlines, ['selftest-replaceme-inst-todir-globfile']) |
| 242 | self.assertNotIn('WARNING: ', output) |
| 243 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 244 | def test_recipetool_appendfile_patch(self): |
| 245 | # A file that's added by a patch in SRC_URI |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 246 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 247 | '\n', |
| 248 | 'SRC_URI += "file://testfile"\n', |
| 249 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 250 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 251 | ' install -d ${D}${sysconfdir}\n', |
| 252 | ' install -m 0644 ${WORKDIR}/testfile ${D}${sysconfdir}/selftest-replaceme-patched\n', |
| 253 | '}\n'] |
| 254 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/etc/selftest-replaceme-patched', self.testfile, '', expectedlines, ['testfile']) |
| 255 | for line in output.splitlines(): |
| 256 | if 'WARNING: ' in line: |
| 257 | self.assertIn('add-file.patch', line, 'Unexpected warning found in output:\n%s' % line) |
| 258 | break |
| 259 | else: |
| 260 | self.fail('Patch warning not found in output:\n%s' % output) |
| 261 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 262 | def test_recipetool_appendfile_script(self): |
| 263 | # Now, a file that's in SRC_URI but installed by a script (so no mention in do_install) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 264 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 265 | '\n', |
| 266 | 'SRC_URI += "file://testfile"\n', |
| 267 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 268 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 269 | ' install -d ${D}${datadir}\n', |
| 270 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-scripted\n', |
| 271 | '}\n'] |
| 272 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-scripted', self.testfile, '', expectedlines, ['testfile']) |
| 273 | self.assertNotIn('WARNING: ', output) |
| 274 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 275 | def test_recipetool_appendfile_inst_func(self): |
| 276 | # A file that's installed from a function called by do_install |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 277 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 278 | '\n'] |
| 279 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-inst-func', self.testfile, '', expectedlines, ['selftest-replaceme-inst-func']) |
| 280 | self.assertNotIn('WARNING: ', output) |
| 281 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 282 | def test_recipetool_appendfile_postinstall(self): |
| 283 | # A file that's created by a postinstall script (and explicitly mentioned in it) |
| 284 | # First try without specifying recipe |
| 285 | 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']) |
| 286 | # Now specify recipe |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 287 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 288 | '\n', |
| 289 | 'SRC_URI += "file://testfile"\n', |
| 290 | '\n', |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 291 | 'do_install:append() {\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 292 | ' install -d ${D}${datadir}\n', |
| 293 | ' install -m 0644 ${WORKDIR}/testfile ${D}${datadir}/selftest-replaceme-postinst\n', |
| 294 | '}\n'] |
| 295 | _, output = self._try_recipetool_appendfile('selftest-recipetool-appendfile', '/usr/share/selftest-replaceme-postinst', self.testfile, '-r selftest-recipetool-appendfile', expectedlines, ['testfile']) |
| 296 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 297 | def test_recipetool_appendfile_extlayer(self): |
| 298 | # Try creating a bbappend in a layer that's not in bblayers.conf and has a different structure |
| 299 | exttemplayerdir = os.path.join(self.tempdir, 'extlayer') |
| 300 | self._create_temp_layer(exttemplayerdir, False, 'oeselftestextlayer', recipepathspec='metadata/recipes/recipes-*/*') |
| 301 | result = runCmd('recipetool appendfile %s /usr/share/selftest-replaceme-orig %s' % (exttemplayerdir, self.testfile)) |
| 302 | self.assertNotIn('Traceback', result.output) |
| 303 | createdfiles = [] |
| 304 | for root, _, files in os.walk(exttemplayerdir): |
| 305 | for f in files: |
| 306 | createdfiles.append(os.path.relpath(os.path.join(root, f), exttemplayerdir)) |
| 307 | createdfiles.remove('conf/layer.conf') |
| 308 | expectedfiles = ['metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile.bbappend', |
| 309 | 'metadata/recipes/recipes-test/selftest-recipetool-appendfile/selftest-recipetool-appendfile/selftest-replaceme-orig'] |
| 310 | self.assertEqual(sorted(createdfiles), sorted(expectedfiles)) |
| 311 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 312 | def test_recipetool_appendfile_wildcard(self): |
| 313 | |
| 314 | def try_appendfile_wc(options): |
| 315 | result = runCmd('recipetool appendfile %s /etc/profile %s %s' % (self.templayerdir, self.testfile, options)) |
| 316 | self.assertNotIn('Traceback', result.output) |
| 317 | bbappendfile = None |
| 318 | for root, _, files in os.walk(self.templayerdir): |
| 319 | for f in files: |
| 320 | if f.endswith('.bbappend'): |
| 321 | bbappendfile = f |
| 322 | break |
| 323 | if not bbappendfile: |
| 324 | self.fail('No bbappend file created') |
| 325 | runCmd('rm -rf %s/recipes-*' % self.templayerdir) |
| 326 | return bbappendfile |
| 327 | |
| 328 | # Check without wildcard option |
| 329 | recipefn = os.path.basename(get_bb_var('FILE', 'base-files')) |
| 330 | filename = try_appendfile_wc('') |
| 331 | self.assertEqual(filename, recipefn.replace('.bb', '.bbappend')) |
| 332 | # Now check with wildcard option |
| 333 | filename = try_appendfile_wc('-w') |
| 334 | self.assertEqual(filename, recipefn.split('_')[0] + '_%.bbappend') |
| 335 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 336 | |
| 337 | class RecipetoolCreateTests(RecipetoolBase): |
| 338 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 339 | def test_recipetool_create(self): |
| 340 | # Try adding a recipe |
| 341 | tempsrc = os.path.join(self.tempdir, 'srctree') |
| 342 | os.makedirs(tempsrc) |
| 343 | recipefile = os.path.join(self.tempdir, 'logrotate_3.12.3.bb') |
| 344 | srcuri = 'https://github.com/logrotate/logrotate/releases/download/3.12.3/logrotate-3.12.3.tar.xz' |
| 345 | result = runCmd('recipetool create -o %s %s -x %s' % (recipefile, srcuri, tempsrc)) |
| 346 | self.assertTrue(os.path.isfile(recipefile)) |
| 347 | checkvars = {} |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 348 | checkvars['LICENSE'] = 'GPL-2.0-only' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 349 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263' |
| 350 | checkvars['SRC_URI'] = 'https://github.com/logrotate/logrotate/releases/download/${PV}/logrotate-${PV}.tar.xz' |
| 351 | checkvars['SRC_URI[md5sum]'] = 'a560c57fac87c45b2fc17406cdf79288' |
| 352 | checkvars['SRC_URI[sha256sum]'] = '2e6a401cac9024db2288297e3be1a8ab60e7401ba8e91225218aaf4a27e82a07' |
| 353 | self._test_recipe_contents(recipefile, checkvars, []) |
| 354 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 355 | def test_recipetool_create_autotools(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 356 | if 'x11' not in get_bb_var('DISTRO_FEATURES'): |
| 357 | self.skipTest('Test requires x11 as distro feature') |
| 358 | # Ensure we have the right data in shlibs/pkgdata |
| 359 | bitbake('libpng pango libx11 libxext jpeg libcheck') |
| 360 | # Try adding a recipe |
| 361 | tempsrc = os.path.join(self.tempdir, 'srctree') |
| 362 | os.makedirs(tempsrc) |
| 363 | recipefile = os.path.join(self.tempdir, 'libmatchbox.bb') |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 364 | srcuri = 'git://git.yoctoproject.org/libmatchbox;protocol=https' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 365 | result = runCmd(['recipetool', 'create', '-o', recipefile, srcuri + ";rev=9f7cf8895ae2d39c465c04cc78e918c157420269", '-x', tempsrc]) |
| 366 | self.assertTrue(os.path.isfile(recipefile), 'recipetool did not create recipe file; output:\n%s' % result.output) |
| 367 | checkvars = {} |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 368 | checkvars['LICENSE'] = 'LGPL-2.1-only' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 369 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7fbc338309ac38fefcd64b04bb903e34' |
| 370 | checkvars['S'] = '${WORKDIR}/git' |
Andrew Geissler | 5082cc7 | 2023-09-11 08:41:39 -0400 | [diff] [blame] | 371 | checkvars['PV'] = '1.11+git' |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 372 | checkvars['SRC_URI'] = srcuri + ';branch=master' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 373 | checkvars['DEPENDS'] = set(['libcheck', 'libjpeg-turbo', 'libpng', 'libx11', 'libxext', 'pango']) |
| 374 | inherits = ['autotools', 'pkgconfig'] |
| 375 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 376 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 377 | def test_recipetool_create_simple(self): |
| 378 | # Try adding a recipe |
| 379 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 380 | os.makedirs(temprecipe) |
Andrew Geissler | 5f35090 | 2021-07-23 13:09:54 -0400 | [diff] [blame] | 381 | pv = '1.7.4.1' |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 382 | srcuri = 'http://www.dest-unreach.org/socat/download/Archive/socat-%s.tar.bz2' % pv |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 383 | result = runCmd('recipetool create %s -o %s' % (srcuri, temprecipe)) |
| 384 | dirlist = os.listdir(temprecipe) |
| 385 | if len(dirlist) > 1: |
| 386 | self.fail('recipetool created more than just one file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist))) |
| 387 | if len(dirlist) < 1 or not os.path.isfile(os.path.join(temprecipe, dirlist[0])): |
| 388 | self.fail('recipetool did not create recipe file; output:\n%s\ndirlist:\n%s' % (result.output, str(dirlist))) |
| 389 | self.assertEqual(dirlist[0], 'socat_%s.bb' % pv, 'Recipe file incorrectly named') |
| 390 | checkvars = {} |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 391 | checkvars['LICENSE'] = set(['Unknown', 'GPL-2.0-only']) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 392 | checkvars['LIC_FILES_CHKSUM'] = set(['file://COPYING.OpenSSL;md5=5c9bccc77f67a8328ef4ebaf468116f4', 'file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263']) |
| 393 | # We don't check DEPENDS since they are variable for this recipe depending on what's in the sysroot |
| 394 | checkvars['S'] = None |
| 395 | checkvars['SRC_URI'] = srcuri.replace(pv, '${PV}') |
| 396 | inherits = ['autotools'] |
| 397 | self._test_recipe_contents(os.path.join(temprecipe, dirlist[0]), checkvars, inherits) |
| 398 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 399 | def test_recipetool_create_cmake(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 400 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 401 | os.makedirs(temprecipe) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 402 | recipefile = os.path.join(temprecipe, 'taglib_1.11.1.bb') |
| 403 | srcuri = 'http://taglib.github.io/releases/taglib-1.11.1.tar.gz' |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 404 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 405 | self.assertTrue(os.path.isfile(recipefile)) |
| 406 | checkvars = {} |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 407 | checkvars['LICENSE'] = set(['LGPL-2.1-only', 'MPL-1.1-only']) |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 408 | checkvars['SRC_URI'] = 'http://taglib.github.io/releases/taglib-${PV}.tar.gz' |
| 409 | checkvars['SRC_URI[md5sum]'] = 'cee7be0ccfc892fa433d6c837df9522a' |
| 410 | checkvars['SRC_URI[sha256sum]'] = 'b6d1a5a610aae6ff39d93de5efd0fdc787aa9e9dc1e7026fa4c961b26563526b' |
| 411 | checkvars['DEPENDS'] = set(['boost', 'zlib']) |
| 412 | inherits = ['cmake'] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 413 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 414 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 415 | def test_recipetool_create_npm(self): |
Andrew Geissler | f034379 | 2020-11-18 10:42:21 -0600 | [diff] [blame] | 416 | collections = get_bb_var('BBFILE_COLLECTIONS').split() |
| 417 | if "openembedded-layer" not in collections: |
| 418 | self.skipTest("Test needs meta-oe for nodejs") |
| 419 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 420 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 421 | os.makedirs(temprecipe) |
| 422 | recipefile = os.path.join(temprecipe, 'savoirfairelinux-node-server-example_1.0.0.bb') |
| 423 | shrinkwrap = os.path.join(temprecipe, 'savoirfairelinux-node-server-example', 'npm-shrinkwrap.json') |
| 424 | srcuri = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 425 | result = runCmd('recipetool create -o %s \'%s\'' % (temprecipe, srcuri)) |
| 426 | self.assertTrue(os.path.isfile(recipefile)) |
| 427 | self.assertTrue(os.path.isfile(shrinkwrap)) |
| 428 | checkvars = {} |
| 429 | checkvars['SUMMARY'] = 'Node Server Example' |
| 430 | checkvars['HOMEPAGE'] = 'https://github.com/savoirfairelinux/node-server-example#readme' |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 431 | checkvars['LICENSE'] = 'BSD-3-Clause & ISC & MIT & Unknown' |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 432 | urls = [] |
| 433 | urls.append('npm://registry.npmjs.org/;package=@savoirfairelinux/node-server-example;version=${PV}') |
| 434 | urls.append('npmsw://${THISDIR}/${BPN}/npm-shrinkwrap.json') |
| 435 | checkvars['SRC_URI'] = set(urls) |
| 436 | checkvars['S'] = '${WORKDIR}/npm' |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 437 | checkvars['LICENSE:${PN}'] = 'MIT' |
| 438 | checkvars['LICENSE:${PN}-base64'] = 'Unknown' |
| 439 | checkvars['LICENSE:${PN}-accepts'] = 'MIT' |
| 440 | checkvars['LICENSE:${PN}-inherits'] = 'ISC' |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 441 | inherits = ['npm'] |
| 442 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 443 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 444 | def test_recipetool_create_github(self): |
| 445 | # Basic test to see if github URL mangling works |
| 446 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 447 | os.makedirs(temprecipe) |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame^] | 448 | recipefile = os.path.join(temprecipe, 'python3-meson_git.bb') |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 449 | srcuri = 'https://github.com/mesonbuild/meson;rev=0.32.0' |
| 450 | result = runCmd(['recipetool', 'create', '-o', temprecipe, srcuri]) |
| 451 | self.assertTrue(os.path.isfile(recipefile)) |
| 452 | checkvars = {} |
| 453 | checkvars['LICENSE'] = set(['Apache-2.0']) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 454 | checkvars['SRC_URI'] = 'git://github.com/mesonbuild/meson;protocol=https;branch=master' |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 455 | inherits = ['setuptools3'] |
| 456 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 457 | |
| 458 | def test_recipetool_create_python3_setuptools(self): |
| 459 | # Test creating python3 package from tarball (using setuptools3 class) |
| 460 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 461 | os.makedirs(temprecipe) |
| 462 | pn = 'python-magic' |
| 463 | pv = '0.4.15' |
| 464 | recipefile = os.path.join(temprecipe, '%s_%s.bb' % (pn, pv)) |
| 465 | srcuri = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-%s.tar.gz' % pv |
| 466 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 467 | self.assertTrue(os.path.isfile(recipefile)) |
| 468 | checkvars = {} |
| 469 | checkvars['LICENSE'] = set(['MIT']) |
| 470 | checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=16a934f165e8c3245f241e77d401bb88' |
| 471 | checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/84/30/80932401906eaf787f2e9bd86dc458f1d2e75b064b4c187341f29516945c/python-magic-${PV}.tar.gz' |
| 472 | checkvars['SRC_URI[md5sum]'] = 'e384c95a47218f66c6501cd6dd45ff59' |
| 473 | checkvars['SRC_URI[sha256sum]'] = 'f3765c0f582d2dfc72c15f3b5a82aecfae9498bd29ca840d72f37d7bd38bfcd5' |
| 474 | inherits = ['setuptools3'] |
| 475 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 476 | |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame^] | 477 | def test_recipetool_create_python3_pep517_setuptools_build_meta(self): |
| 478 | # This test require python 3.11 or above for the tomllib module |
| 479 | # or tomli module to be installed |
| 480 | try: |
| 481 | import tomllib |
| 482 | except ImportError: |
| 483 | try: |
| 484 | import tomli |
| 485 | except ImportError: |
| 486 | self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module') |
| 487 | |
| 488 | # Test creating python3 package from tarball (using setuptools.build_meta class) |
| 489 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 490 | os.makedirs(temprecipe) |
| 491 | pn = 'webcolors' |
| 492 | pv = '1.13' |
| 493 | recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv)) |
| 494 | srcuri = 'https://files.pythonhosted.org/packages/a1/fb/f95560c6a5d4469d9c49e24cf1b5d4d21ffab5608251c6020a965fb7791c/%s-%s.tar.gz' % (pn, pv) |
| 495 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 496 | self.assertTrue(os.path.isfile(recipefile)) |
| 497 | checkvars = {} |
| 498 | checkvars['SUMMARY'] = 'A library for working with the color formats defined by HTML and CSS.' |
| 499 | checkvars['LICENSE'] = set(['BSD-3-Clause']) |
| 500 | checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=702b1ef12cf66832a88f24c8f2ee9c19' |
| 501 | checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/a1/fb/f95560c6a5d4469d9c49e24cf1b5d4d21ffab5608251c6020a965fb7791c/webcolors-${PV}.tar.gz' |
| 502 | checkvars['SRC_URI[md5sum]'] = 'c9be30c5b0cf1cad32e4cbacbb2229e9' |
| 503 | checkvars['SRC_URI[sha1sum]'] = 'c90b84fb65eed9b4c9dea7f08c657bfac0e820a5' |
| 504 | checkvars['SRC_URI[sha256sum]'] = 'c225b674c83fa923be93d235330ce0300373d02885cef23238813b0d5668304a' |
| 505 | checkvars['SRC_URI[sha384sum]'] = '45652af349660f19f68d01361dd5bda287789e5ea63608f52a8cea526ac04465614db2ea236103fb8456b1fcaea96ed7' |
| 506 | checkvars['SRC_URI[sha512sum]'] = '074aaf135ac6b0025b88b731d1d6dfa4c539b4fff7195658cc58a4326bb9f0449a231685d312b4a1ec48ca535a838bfa5c680787fe0e61473a2a092c448937d0' |
| 507 | inherits = ['python_setuptools_build_meta'] |
| 508 | |
| 509 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 510 | |
| 511 | def test_recipetool_create_python3_pep517_poetry_core_masonry_api(self): |
| 512 | # This test require python 3.11 or above for the tomllib module |
| 513 | # or tomli module to be installed |
| 514 | try: |
| 515 | import tomllib |
| 516 | except ImportError: |
| 517 | try: |
| 518 | import tomli |
| 519 | except ImportError: |
| 520 | self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module') |
| 521 | |
| 522 | # Test creating python3 package from tarball (using poetry.core.masonry.api class) |
| 523 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 524 | os.makedirs(temprecipe) |
| 525 | pn = 'iso8601' |
| 526 | pv = '2.1.0' |
| 527 | recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv)) |
| 528 | srcuri = 'https://files.pythonhosted.org/packages/b9/f3/ef59cee614d5e0accf6fd0cbba025b93b272e626ca89fb70a3e9187c5d15/%s-%s.tar.gz' % (pn, pv) |
| 529 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 530 | self.assertTrue(os.path.isfile(recipefile)) |
| 531 | checkvars = {} |
| 532 | checkvars['SUMMARY'] = 'Simple module to parse ISO 8601 dates' |
| 533 | checkvars['LICENSE'] = set(['MIT']) |
| 534 | checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=aab31f2ef7ba214a5a341eaa47a7f367' |
| 535 | checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/b9/f3/ef59cee614d5e0accf6fd0cbba025b93b272e626ca89fb70a3e9187c5d15/iso8601-${PV}.tar.gz' |
| 536 | checkvars['SRC_URI[md5sum]'] = '6e33910eba87066b3be7fcf3d59d16b5' |
| 537 | checkvars['SRC_URI[sha1sum]'] = 'efd225b2c9fa7d9e4a1ec6ad94f3295cee982e61' |
| 538 | checkvars['SRC_URI[sha256sum]'] = '6b1d3829ee8921c4301998c909f7829fa9ed3cbdac0d3b16af2d743aed1ba8df' |
| 539 | checkvars['SRC_URI[sha384sum]'] = '255002433fe65c19adfd6b91494271b613cb25ef6a35ac77436de1e03d60cc07bf89fd716451b917f1435e4384860ef6' |
| 540 | checkvars['SRC_URI[sha512sum]'] = 'db57ab2a25ef91e3bc479c8539d27e853cf1fbf60986820b8999ae15d7e566425a1e0cfba47d0f3b23aa703db0576db368e6c110ba2a2f46c9a34e8ee3611fb7' |
| 541 | inherits = ['python_poetry_core'] |
| 542 | |
| 543 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 544 | |
| 545 | def test_recipetool_create_python3_pep517_flit_core_buildapi(self): |
| 546 | # This test require python 3.11 or above for the tomllib module |
| 547 | # or tomli module to be installed |
| 548 | try: |
| 549 | import tomllib |
| 550 | except ImportError: |
| 551 | try: |
| 552 | import tomli |
| 553 | except ImportError: |
| 554 | self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module') |
| 555 | |
| 556 | # Test creating python3 package from tarball (using flit_core.buildapi class) |
| 557 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 558 | os.makedirs(temprecipe) |
| 559 | pn = 'typing-extensions' |
| 560 | pv = '4.8.0' |
| 561 | recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv)) |
| 562 | srcuri = 'https://files.pythonhosted.org/packages/1f/7a/8b94bb016069caa12fc9f587b28080ac33b4fbb8ca369b98bc0a4828543e/typing_extensions-%s.tar.gz' % pv |
| 563 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 564 | self.assertTrue(os.path.isfile(recipefile)) |
| 565 | checkvars = {} |
| 566 | checkvars['SUMMARY'] = 'Backported and Experimental Type Hints for Python 3.8+' |
| 567 | checkvars['LICENSE'] = set(['PSF-2.0']) |
| 568 | checkvars['LIC_FILES_CHKSUM'] = 'file://LICENSE;md5=fcf6b249c2641540219a727f35d8d2c2' |
| 569 | checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/1f/7a/8b94bb016069caa12fc9f587b28080ac33b4fbb8ca369b98bc0a4828543e/typing_extensions-${PV}.tar.gz' |
| 570 | checkvars['SRC_URI[md5sum]'] = '74bafe841fbd1c27324afdeb099babdf' |
| 571 | checkvars['SRC_URI[sha1sum]'] = 'f8bed69cbad4a57a1a67bf8a31b62b657b47f7a3' |
| 572 | checkvars['SRC_URI[sha256sum]'] = 'df8e4339e9cb77357558cbdbceca33c303714cf861d1eef15e1070055ae8b7ef' |
| 573 | checkvars['SRC_URI[sha384sum]'] = '0bd0112234134d965c6884f3c1f95d27b6ae49cfb08108101158e31dff33c2dce729331628b69818850f1acb68f6c8d0' |
| 574 | checkvars['SRC_URI[sha512sum]'] = '5fbff10e085fbf3ac2e35d08d913608d8c8bca66903435ede91cdc7776d775689a53d64f5f0615fe687c6c228ac854c8651d99eb1cb96ec61c56b7ca01fdd440' |
| 575 | inherits = ['python_flit_core'] |
| 576 | |
| 577 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 578 | |
| 579 | def test_recipetool_create_python3_pep517_hatchling(self): |
| 580 | # This test require python 3.11 or above for the tomllib module |
| 581 | # or tomli module to be installed |
| 582 | try: |
| 583 | import tomllib |
| 584 | except ImportError: |
| 585 | try: |
| 586 | import tomli |
| 587 | except ImportError: |
| 588 | self.skipTest('Test requires python 3.11 or above for tomllib module or tomli module') |
| 589 | |
| 590 | # Test creating python3 package from tarball (using hatchling class) |
| 591 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 592 | os.makedirs(temprecipe) |
| 593 | pn = 'jsonschema' |
| 594 | pv = '4.19.1' |
| 595 | recipefile = os.path.join(temprecipe, 'python3-%s_%s.bb' % (pn, pv)) |
| 596 | srcuri = 'https://files.pythonhosted.org/packages/e4/43/087b24516db11722c8687e0caf0f66c7785c0b1c51b0ab951dfde924e3f5/jsonschema-%s.tar.gz' % pv |
| 597 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 598 | self.assertTrue(os.path.isfile(recipefile)) |
| 599 | checkvars = {} |
| 600 | checkvars['SUMMARY'] = 'An implementation of JSON Schema validation for Python' |
| 601 | checkvars['HOMEPAGE'] = 'https://github.com/python-jsonschema/jsonschema' |
| 602 | checkvars['LICENSE'] = set(['MIT']) |
| 603 | checkvars['LIC_FILES_CHKSUM'] = 'file://COPYING;md5=7a60a81c146ec25599a3e1dabb8610a8 file://json/LICENSE;md5=9d4de43111d33570c8fe49b4cb0e01af' |
| 604 | checkvars['SRC_URI'] = 'https://files.pythonhosted.org/packages/e4/43/087b24516db11722c8687e0caf0f66c7785c0b1c51b0ab951dfde924e3f5/jsonschema-${PV}.tar.gz' |
| 605 | checkvars['SRC_URI[md5sum]'] = '4d6667ce76f820c35082c2d60a4896ab' |
| 606 | checkvars['SRC_URI[sha1sum]'] = '9173714cb88964d07f3a3f4fcaaef638b8ceac0c' |
| 607 | checkvars['SRC_URI[sha256sum]'] = 'ec84cc37cfa703ef7cd4928db24f9cb31428a5d0fa77747b8b51a847458e0bbf' |
| 608 | checkvars['SRC_URI[sha384sum]'] = '7a53181f0e679aa3dc3eb4d05a420877b7b9bff2d02e81f5c289a37ed1127d6c0cca1f5a5f9e4e166f089ab36bcc2be9' |
| 609 | checkvars['SRC_URI[sha512sum]'] = '60fa769faf6e3fc2c14eb9acd189c86e9d366b157230a5681d36552af0c159cb1ad33fd920668a36afdab98bc97253f91501704c5c07b5009fdaf9d29b52060d' |
| 610 | inherits = ['python_hatchling'] |
| 611 | |
| 612 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 613 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 614 | def test_recipetool_create_github_tarball(self): |
| 615 | # Basic test to ensure github URL mangling doesn't apply to release tarballs |
| 616 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 617 | os.makedirs(temprecipe) |
| 618 | pv = '0.32.0' |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame^] | 619 | recipefile = os.path.join(temprecipe, 'python3-meson_%s.bb' % pv) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 620 | srcuri = 'https://github.com/mesonbuild/meson/releases/download/%s/meson-%s.tar.gz' % (pv, pv) |
| 621 | result = runCmd('recipetool create -o %s %s' % (temprecipe, srcuri)) |
| 622 | self.assertTrue(os.path.isfile(recipefile)) |
| 623 | checkvars = {} |
| 624 | checkvars['LICENSE'] = set(['Apache-2.0']) |
| 625 | 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] | 626 | inherits = ['setuptools3'] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 627 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 628 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 629 | def _test_recipetool_create_git(self, srcuri, branch=None): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 630 | # Basic test to check http git URL mangling works |
| 631 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 632 | os.makedirs(temprecipe) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 633 | name = srcuri.split(';')[0].split('/')[-1] |
| 634 | recipefile = os.path.join(temprecipe, name + '_git.bb') |
| 635 | options = ' -B %s' % branch if branch else '' |
| 636 | result = runCmd('recipetool create -o %s%s "%s"' % (temprecipe, options, srcuri)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 637 | self.assertTrue(os.path.isfile(recipefile)) |
| 638 | checkvars = {} |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 639 | checkvars['SRC_URI'] = srcuri |
| 640 | for scheme in ['http', 'https']: |
| 641 | if srcuri.startswith(scheme + ":"): |
| 642 | checkvars['SRC_URI'] = 'git%s;protocol=%s' % (srcuri[len(scheme):], scheme) |
| 643 | if ';branch=' not in srcuri: |
| 644 | checkvars['SRC_URI'] += ';branch=' + (branch or 'master') |
| 645 | self._test_recipe_contents(recipefile, checkvars, []) |
| 646 | |
| 647 | def test_recipetool_create_git_http(self): |
| 648 | self._test_recipetool_create_git('http://git.yoctoproject.org/git/matchbox-keyboard') |
| 649 | |
| 650 | def test_recipetool_create_git_srcuri_master(self): |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 651 | self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=master;protocol=https') |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 652 | |
| 653 | def test_recipetool_create_git_srcuri_branch(self): |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 654 | self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;branch=matchbox-keyboard-0-1;protocol=https') |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 655 | |
| 656 | def test_recipetool_create_git_srcbranch(self): |
Andrew Geissler | 028142b | 2023-05-05 11:29:21 -0500 | [diff] [blame] | 657 | self._test_recipetool_create_git('git://git.yoctoproject.org/matchbox-keyboard;protocol=https', 'matchbox-keyboard-0-1') |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 658 | |
| 659 | |
| 660 | class RecipetoolTests(RecipetoolBase): |
| 661 | |
| 662 | @classmethod |
| 663 | def setUpClass(cls): |
| 664 | import sys |
| 665 | |
| 666 | super(RecipetoolTests, cls).setUpClass() |
| 667 | bb_vars = get_bb_vars(['BBPATH']) |
| 668 | cls.bbpath = bb_vars['BBPATH'] |
| 669 | libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool') |
| 670 | sys.path.insert(0, libpath) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 671 | |
Patrick Williams | ac13d5f | 2023-11-24 18:59:46 -0600 | [diff] [blame^] | 672 | def test_recipetool_create_go(self): |
| 673 | # Basic test to check go recipe generation |
| 674 | def urifiy(url, version, modulepath = None, pathmajor = None, subdir = None): |
| 675 | modulepath = ",path='%s'" % modulepath if len(modulepath) else '' |
| 676 | pathmajor = ",pathmajor='%s'" % pathmajor if len(pathmajor) else '' |
| 677 | subdir = ",subdir='%s'" % subdir if len(subdir) else '' |
| 678 | return "${@go_src_uri('%s','%s'%s%s%s)}" % (url, version, modulepath, pathmajor, subdir) |
| 679 | |
| 680 | temprecipe = os.path.join(self.tempdir, 'recipe') |
| 681 | os.makedirs(temprecipe) |
| 682 | |
| 683 | recipefile = os.path.join(temprecipe, 'edgex-go_git.bb') |
| 684 | deps_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-modules.inc') |
| 685 | lics_require_file = os.path.join(temprecipe, 'edgex-go', 'edgex-go-licenses.inc') |
| 686 | modules_txt_file = os.path.join(temprecipe, 'edgex-go', 'modules.txt') |
| 687 | |
| 688 | srcuri = 'https://github.com/edgexfoundry/edgex-go.git' |
| 689 | srcrev = "v3.0.0" |
| 690 | srcbranch = "main" |
| 691 | |
| 692 | result = runCmd('recipetool create -o %s %s -S %s -B %s' % (temprecipe, srcuri, srcrev, srcbranch)) |
| 693 | |
| 694 | self.maxDiff = None |
| 695 | inherits = ['go-vendor'] |
| 696 | |
| 697 | checkvars = {} |
| 698 | checkvars['GO_IMPORT'] = "github.com/edgexfoundry/edgex-go" |
| 699 | checkvars['SRC_URI'] = {'git://${GO_IMPORT};destsuffix=git/src/${GO_IMPORT};nobranch=1;name=${BPN};protocol=https', |
| 700 | 'file://modules.txt'} |
| 701 | checkvars['LIC_FILES_CHKSUM'] = {'file://src/${GO_IMPORT}/LICENSE;md5=8f8bc924cf73f6a32381e5fd4c58d603'} |
| 702 | |
| 703 | self.assertTrue(os.path.isfile(recipefile)) |
| 704 | self._test_recipe_contents(recipefile, checkvars, inherits) |
| 705 | |
| 706 | checkvars = {} |
| 707 | checkvars['VENDORED_LIC_FILES_CHKSUM'] = set( |
| 708 | ['file://src/${GO_IMPORT}/vendor/github.com/Microsoft/go-winio/LICENSE;md5=69205ff73858f2c22b2ca135b557e8ef', |
| 709 | 'file://src/${GO_IMPORT}/vendor/github.com/armon/go-metrics/LICENSE;md5=d2d77030c0183e3d1e66d26dc1f243be', |
| 710 | 'file://src/${GO_IMPORT}/vendor/github.com/cenkalti/backoff/LICENSE;md5=1571d94433e3f3aa05267efd4dbea68b', |
| 711 | 'file://src/${GO_IMPORT}/vendor/github.com/davecgh/go-spew/LICENSE;md5=c06795ed54b2a35ebeeb543cd3a73e56', |
| 712 | 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/LICENSE;md5=dcdb33474b60c38efd27356d8f2edec7', |
| 713 | 'file://src/${GO_IMPORT}/vendor/github.com/eclipse/paho.mqtt.golang/edl-v10;md5=3adfcc70f5aeb7a44f3f9b495aa1fbf3', |
| 714 | 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-bootstrap/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff', |
| 715 | 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-configuration/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff', |
| 716 | 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-core-contracts/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff', |
| 717 | 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-messaging/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff', |
| 718 | 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-registry/v3/LICENSE;md5=0d6dae39976133b2851fba4c1e1275ff', |
| 719 | 'file://src/${GO_IMPORT}/vendor/github.com/edgexfoundry/go-mod-secrets/v3/LICENSE;md5=f9fa2f4f8e0ef8cc7b5dd150963eb457', |
| 720 | 'file://src/${GO_IMPORT}/vendor/github.com/fatih/color/LICENSE.md;md5=316e6d590bdcde7993fb175662c0dd5a', |
| 721 | 'file://src/${GO_IMPORT}/vendor/github.com/fxamacker/cbor/v2/LICENSE;md5=827f5a2fa861382d35a3943adf9ebb86', |
| 722 | 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57', |
| 723 | 'file://src/${GO_IMPORT}/vendor/github.com/go-jose/go-jose/v3/json/LICENSE;md5=591778525c869cdde0ab5a1bf283cd81', |
| 724 | 'file://src/${GO_IMPORT}/vendor/github.com/go-kit/log/LICENSE;md5=5b7c15ad5fffe2ff6e9d58a6c161f082', |
| 725 | 'file://src/${GO_IMPORT}/vendor/github.com/go-logfmt/logfmt/LICENSE;md5=98e39517c38127f969de33057067091e', |
| 726 | 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/locales/LICENSE;md5=3ccbda375ee345400ad1da85ba522301', |
| 727 | 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/universal-translator/LICENSE;md5=2e2b21ef8f61057977d27c727c84bef1', |
| 728 | 'file://src/${GO_IMPORT}/vendor/github.com/go-playground/validator/v10/LICENSE;md5=a718a0f318d76f7c5d510cbae84f0b60', |
| 729 | 'file://src/${GO_IMPORT}/vendor/github.com/go-redis/redis/v7/LICENSE;md5=58103aa5ea1ee9b7a369c9c4a95ef9b5', |
| 730 | 'file://src/${GO_IMPORT}/vendor/github.com/golang/protobuf/LICENSE;md5=939cce1ec101726fa754e698ac871622', |
| 731 | 'file://src/${GO_IMPORT}/vendor/github.com/gomodule/redigo/LICENSE;md5=2ee41112a44fe7014dce33e26468ba93', |
| 732 | 'file://src/${GO_IMPORT}/vendor/github.com/google/uuid/LICENSE;md5=88073b6dd8ec00fe09da59e0b6dfded1', |
| 733 | 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/mux/LICENSE;md5=33fa1116c45f9e8de714033f99edde13', |
| 734 | 'file://src/${GO_IMPORT}/vendor/github.com/gorilla/websocket/LICENSE;md5=c007b54a1743d596f46b2748d9f8c044', |
| 735 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/consul/api/LICENSE;md5=b8a277a612171b7526e9be072f405ef4', |
| 736 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/errwrap/LICENSE;md5=b278a92d2c1509760384428817710378', |
| 737 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-cleanhttp/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea', |
| 738 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-hclog/LICENSE;md5=ec7f605b74b9ad03347d0a93a5cc7eb8', |
| 739 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-immutable-radix/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea', |
| 740 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-multierror/LICENSE;md5=d44fdeb607e2d2614db9464dbedd4094', |
| 741 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/go-rootcerts/LICENSE;md5=65d26fcc2f35ea6a181ac777e42db1ea', |
| 742 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/golang-lru/LICENSE;md5=f27a50d2e878867827842f2c60e30bfc', |
| 743 | 'file://src/${GO_IMPORT}/vendor/github.com/hashicorp/serf/LICENSE;md5=b278a92d2c1509760384428817710378', |
| 744 | 'file://src/${GO_IMPORT}/vendor/github.com/leodido/go-urn/LICENSE;md5=8f50db5538ec1148a9b3d14ed96c3418', |
| 745 | 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-colorable/LICENSE;md5=24ce168f90aec2456a73de1839037245', |
| 746 | 'file://src/${GO_IMPORT}/vendor/github.com/mattn/go-isatty/LICENSE;md5=f509beadd5a11227c27b5d2ad6c9f2c6', |
| 747 | 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/consulstructure/LICENSE;md5=96ada10a9e51c98c4656f2cede08c673', |
| 748 | 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/copystructure/LICENSE;md5=56da355a12d4821cda57b8f23ec34bc4', |
| 749 | 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/go-homedir/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd', |
| 750 | 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/mapstructure/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd', |
| 751 | 'file://src/${GO_IMPORT}/vendor/github.com/mitchellh/reflectwalk/LICENSE;md5=3f7765c3d4f58e1f84c4313cecf0f5bd', |
| 752 | 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nats.go/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327', |
| 753 | 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nkeys/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327', |
| 754 | 'file://src/${GO_IMPORT}/vendor/github.com/nats-io/nuid/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327', |
| 755 | 'file://src/${GO_IMPORT}/vendor/github.com/pmezard/go-difflib/LICENSE;md5=e9a2ebb8de779a07500ddecca806145e', |
| 756 | 'file://src/${GO_IMPORT}/vendor/github.com/rcrowley/go-metrics/LICENSE;md5=1bdf5d819f50f141366dabce3be1460f', |
| 757 | 'file://src/${GO_IMPORT}/vendor/github.com/spiffe/go-spiffe/v2/LICENSE;md5=86d3f3a95c324c9479bd8986968f4327', |
| 758 | 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/objx/LICENSE;md5=d023fd31d3ca39ec61eec65a91732735', |
| 759 | 'file://src/${GO_IMPORT}/vendor/github.com/stretchr/testify/LICENSE;md5=188f01994659f3c0d310612333d2a26f', |
| 760 | 'file://src/${GO_IMPORT}/vendor/github.com/x448/float16/LICENSE;md5=de8f8e025d57fe7ee0b67f30d571323b', |
| 761 | 'file://src/${GO_IMPORT}/vendor/github.com/zeebo/errs/LICENSE;md5=84914ab36fc0eb48edbaa53e66e8d326', |
| 762 | 'file://src/${GO_IMPORT}/vendor/golang.org/x/crypto/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707', |
| 763 | 'file://src/${GO_IMPORT}/vendor/golang.org/x/mod/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707', |
| 764 | 'file://src/${GO_IMPORT}/vendor/golang.org/x/net/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707', |
| 765 | 'file://src/${GO_IMPORT}/vendor/golang.org/x/sync/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707', |
| 766 | 'file://src/${GO_IMPORT}/vendor/golang.org/x/sys/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707', |
| 767 | 'file://src/${GO_IMPORT}/vendor/golang.org/x/text/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707', |
| 768 | 'file://src/${GO_IMPORT}/vendor/golang.org/x/tools/LICENSE;md5=5d4950ecb7b26d2c5e4e7b4e0dd74707', |
| 769 | 'file://src/${GO_IMPORT}/vendor/google.golang.org/genproto/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57', |
| 770 | 'file://src/${GO_IMPORT}/vendor/google.golang.org/grpc/LICENSE;md5=3b83ef96387f14655fc854ddc3c6bd57', |
| 771 | 'file://src/${GO_IMPORT}/vendor/google.golang.org/protobuf/LICENSE;md5=02d4002e9171d41a8fad93aa7faf3956', |
| 772 | 'file://src/${GO_IMPORT}/vendor/gopkg.in/eapache/queue.v1/LICENSE;md5=1bfd4408d3de090ef6b908b0cc45a316', |
| 773 | 'file://src/${GO_IMPORT}/vendor/gopkg.in/yaml.v3/LICENSE;md5=3c91c17266710e16afdbb2b6d15c761c']) |
| 774 | |
| 775 | self.assertTrue(os.path.isfile(lics_require_file)) |
| 776 | self._test_recipe_contents(lics_require_file, checkvars, []) |
| 777 | |
| 778 | dependencies = \ |
| 779 | [ ('github.com/eclipse/paho.mqtt.golang','v1.4.2', '', '', ''), |
| 780 | ('github.com/edgexfoundry/go-mod-bootstrap','v3.0.1','github.com/edgexfoundry/go-mod-bootstrap/v3','/v3', ''), |
| 781 | ('github.com/edgexfoundry/go-mod-configuration','v3.0.0','github.com/edgexfoundry/go-mod-configuration/v3','/v3', ''), |
| 782 | ('github.com/edgexfoundry/go-mod-core-contracts','v3.0.0','github.com/edgexfoundry/go-mod-core-contracts/v3','/v3', ''), |
| 783 | ('github.com/edgexfoundry/go-mod-messaging','v3.0.0','github.com/edgexfoundry/go-mod-messaging/v3','/v3', ''), |
| 784 | ('github.com/edgexfoundry/go-mod-secrets','v3.0.1','github.com/edgexfoundry/go-mod-secrets/v3','/v3', ''), |
| 785 | ('github.com/fxamacker/cbor','v2.4.0','github.com/fxamacker/cbor/v2','/v2', ''), |
| 786 | ('github.com/gomodule/redigo','v1.8.9', '', '', ''), |
| 787 | ('github.com/google/uuid','v1.3.0', '', '', ''), |
| 788 | ('github.com/gorilla/mux','v1.8.0', '', '', ''), |
| 789 | ('github.com/rcrowley/go-metrics','v0.0.0-20201227073835-cf1acfcdf475', '', '', ''), |
| 790 | ('github.com/spiffe/go-spiffe','v2.1.4','github.com/spiffe/go-spiffe/v2','/v2', ''), |
| 791 | ('github.com/stretchr/testify','v1.8.2', '', '', ''), |
| 792 | ('go.googlesource.com/crypto','v0.8.0','golang.org/x/crypto', '', ''), |
| 793 | ('gopkg.in/eapache/queue.v1','v1.1.0', '', '', ''), |
| 794 | ('gopkg.in/yaml.v3','v3.0.1', '', '', ''), |
| 795 | ('github.com/microsoft/go-winio','v0.6.0','github.com/Microsoft/go-winio', '', ''), |
| 796 | ('github.com/hashicorp/go-metrics','v0.3.10','github.com/armon/go-metrics', '', ''), |
| 797 | ('github.com/cenkalti/backoff','v2.2.1+incompatible', '', '', ''), |
| 798 | ('github.com/davecgh/go-spew','v1.1.1', '', '', ''), |
| 799 | ('github.com/edgexfoundry/go-mod-registry','v3.0.0','github.com/edgexfoundry/go-mod-registry/v3','/v3', ''), |
| 800 | ('github.com/fatih/color','v1.9.0', '', '', ''), |
| 801 | ('github.com/go-jose/go-jose','v3.0.0','github.com/go-jose/go-jose/v3','/v3', ''), |
| 802 | ('github.com/go-kit/log','v0.2.1', '', '', ''), |
| 803 | ('github.com/go-logfmt/logfmt','v0.5.1', '', '', ''), |
| 804 | ('github.com/go-playground/locales','v0.14.1', '', '', ''), |
| 805 | ('github.com/go-playground/universal-translator','v0.18.1', '', '', ''), |
| 806 | ('github.com/go-playground/validator','v10.13.0','github.com/go-playground/validator/v10','/v10', ''), |
| 807 | ('github.com/go-redis/redis','v7.3.0','github.com/go-redis/redis/v7','/v7', ''), |
| 808 | ('github.com/golang/protobuf','v1.5.2', '', '', ''), |
| 809 | ('github.com/gorilla/websocket','v1.4.2', '', '', ''), |
| 810 | ('github.com/hashicorp/consul','v1.20.0','github.com/hashicorp/consul/api', '', 'api'), |
| 811 | ('github.com/hashicorp/errwrap','v1.0.0', '', '', ''), |
| 812 | ('github.com/hashicorp/go-cleanhttp','v0.5.1', '', '', ''), |
| 813 | ('github.com/hashicorp/go-hclog','v0.14.1', '', '', ''), |
| 814 | ('github.com/hashicorp/go-immutable-radix','v1.3.0', '', '', ''), |
| 815 | ('github.com/hashicorp/go-multierror','v1.1.1', '', '', ''), |
| 816 | ('github.com/hashicorp/go-rootcerts','v1.0.2', '', '', ''), |
| 817 | ('github.com/hashicorp/golang-lru','v0.5.4', '', '', ''), |
| 818 | ('github.com/hashicorp/serf','v0.10.1', '', '', ''), |
| 819 | ('github.com/leodido/go-urn','v1.2.3', '', '', ''), |
| 820 | ('github.com/mattn/go-colorable','v0.1.12', '', '', ''), |
| 821 | ('github.com/mattn/go-isatty','v0.0.14', '', '', ''), |
| 822 | ('github.com/mitchellh/consulstructure','v0.0.0-20190329231841-56fdc4d2da54', '', '', ''), |
| 823 | ('github.com/mitchellh/copystructure','v1.2.0', '', '', ''), |
| 824 | ('github.com/mitchellh/go-homedir','v1.1.0', '', '', ''), |
| 825 | ('github.com/mitchellh/mapstructure','v1.5.0', '', '', ''), |
| 826 | ('github.com/mitchellh/reflectwalk','v1.0.2', '', '', ''), |
| 827 | ('github.com/nats-io/nats.go','v1.25.0', '', '', ''), |
| 828 | ('github.com/nats-io/nkeys','v0.4.4', '', '', ''), |
| 829 | ('github.com/nats-io/nuid','v1.0.1', '', '', ''), |
| 830 | ('github.com/pmezard/go-difflib','v1.0.0', '', '', ''), |
| 831 | ('github.com/stretchr/objx','v0.5.0', '', '', ''), |
| 832 | ('github.com/x448/float16','v0.8.4', '', '', ''), |
| 833 | ('github.com/zeebo/errs','v1.3.0', '', '', ''), |
| 834 | ('go.googlesource.com/mod','v0.8.0','golang.org/x/mod', '', ''), |
| 835 | ('go.googlesource.com/net','v0.9.0','golang.org/x/net', '', ''), |
| 836 | ('go.googlesource.com/sync','v0.1.0','golang.org/x/sync', '', ''), |
| 837 | ('go.googlesource.com/sys','v0.7.0','golang.org/x/sys', '', ''), |
| 838 | ('go.googlesource.com/text','v0.9.0','golang.org/x/text', '', ''), |
| 839 | ('go.googlesource.com/tools','v0.6.0','golang.org/x/tools', '', ''), |
| 840 | ('github.com/googleapis/go-genproto','v0.0.0-20230223222841-637eb2293923','google.golang.org/genproto', '', ''), |
| 841 | ('github.com/grpc/grpc-go','v1.53.0','google.golang.org/grpc', '', ''), |
| 842 | ('go.googlesource.com/protobuf','v1.28.1','google.golang.org/protobuf', '', ''), |
| 843 | ] |
| 844 | |
| 845 | src_uri = set() |
| 846 | for d in dependencies: |
| 847 | src_uri.add(urifiy(*d)) |
| 848 | |
| 849 | checkvars = {} |
| 850 | checkvars['GO_DEPENDENCIES_SRC_URI'] = src_uri |
| 851 | |
| 852 | self.assertTrue(os.path.isfile(deps_require_file)) |
| 853 | self._test_recipe_contents(deps_require_file, checkvars, []) |
| 854 | |
| 855 | |
| 856 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 857 | def _copy_file_with_cleanup(self, srcfile, basedstdir, *paths): |
| 858 | dstdir = basedstdir |
| 859 | self.assertTrue(os.path.exists(dstdir)) |
| 860 | for p in paths: |
| 861 | dstdir = os.path.join(dstdir, p) |
| 862 | if not os.path.exists(dstdir): |
| 863 | os.makedirs(dstdir) |
Andrew Geissler | 475cb72 | 2020-07-10 16:00:51 -0500 | [diff] [blame] | 864 | if p == "lib": |
| 865 | # Can race with other tests |
| 866 | self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir) |
| 867 | else: |
| 868 | self.track_for_cleanup(dstdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 869 | dstfile = os.path.join(dstdir, os.path.basename(srcfile)) |
| 870 | if srcfile != dstfile: |
| 871 | shutil.copy(srcfile, dstfile) |
| 872 | self.track_for_cleanup(dstfile) |
| 873 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 874 | def test_recipetool_load_plugin(self): |
| 875 | """Test that recipetool loads only the first found plugin in BBPATH.""" |
| 876 | |
| 877 | recipetool = runCmd("which recipetool") |
| 878 | fromname = runCmd("recipetool --quiet pluginfile") |
| 879 | srcfile = fromname.output |
| 880 | searchpath = self.bbpath.split(':') + [os.path.dirname(recipetool.output)] |
| 881 | plugincontent = [] |
| 882 | with open(srcfile) as fh: |
| 883 | plugincontent = fh.readlines() |
| 884 | try: |
| 885 | self.assertIn('meta-selftest', srcfile, 'wrong bbpath plugin found') |
| 886 | for path in searchpath: |
| 887 | self._copy_file_with_cleanup(srcfile, path, 'lib', 'recipetool') |
| 888 | result = runCmd("recipetool --quiet count") |
| 889 | self.assertEqual(result.output, '1') |
| 890 | result = runCmd("recipetool --quiet multiloaded") |
| 891 | self.assertEqual(result.output, "no") |
| 892 | for path in searchpath: |
| 893 | result = runCmd("recipetool --quiet bbdir") |
| 894 | self.assertEqual(result.output, path) |
| 895 | os.unlink(os.path.join(result.output, 'lib', 'recipetool', 'bbpath.py')) |
| 896 | finally: |
| 897 | with open(srcfile, 'w') as fh: |
| 898 | fh.writelines(plugincontent) |
| 899 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 900 | def test_recipetool_handle_license_vars(self): |
| 901 | from create import handle_license_vars |
| 902 | from unittest.mock import Mock |
| 903 | |
| 904 | commonlicdir = get_bb_var('COMMON_LICENSE_DIR') |
| 905 | |
Andrew Geissler | fc113ea | 2023-03-31 09:59:46 -0500 | [diff] [blame] | 906 | class DataConnectorCopy(bb.tinfoil.TinfoilDataStoreConnector): |
| 907 | pass |
| 908 | |
| 909 | d = DataConnectorCopy |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 910 | d.getVar = Mock(return_value=commonlicdir) |
| 911 | |
| 912 | srctree = tempfile.mkdtemp(prefix='recipetoolqa') |
| 913 | self.track_for_cleanup(srctree) |
| 914 | |
| 915 | # Multiple licenses |
| 916 | licenses = ['MIT', 'ISC', 'BSD-3-Clause', 'Apache-2.0'] |
| 917 | for licence in licenses: |
| 918 | shutil.copy(os.path.join(commonlicdir, licence), os.path.join(srctree, 'LICENSE.' + licence)) |
| 919 | # Duplicate license |
| 920 | shutil.copy(os.path.join(commonlicdir, 'MIT'), os.path.join(srctree, 'LICENSE')) |
| 921 | |
| 922 | extravalues = { |
| 923 | # Duplicate and missing licenses |
| 924 | 'LICENSE': 'Zlib & BSD-2-Clause & Zlib', |
| 925 | 'LIC_FILES_CHKSUM': [ |
| 926 | 'file://README.md;md5=0123456789abcdef0123456789abcd' |
| 927 | ] |
| 928 | } |
| 929 | lines_before = [] |
| 930 | handled = [] |
| 931 | licvalues = handle_license_vars(srctree, lines_before, handled, extravalues, d) |
| 932 | expected_lines_before = [ |
| 933 | '# WARNING: the following LICENSE and LIC_FILES_CHKSUM values are best guesses - it is', |
| 934 | '# your responsibility to verify that the values are complete and correct.', |
| 935 | '# NOTE: Original package / source metadata indicates license is: BSD-2-Clause & Zlib', |
| 936 | '#', |
| 937 | '# NOTE: multiple licenses have been detected; they have been separated with &', |
| 938 | '# in the LICENSE value for now since it is a reasonable assumption that all', |
| 939 | '# of the licenses apply. If instead there is a choice between the multiple', |
| 940 | '# licenses then you should change the value to separate the licenses with |', |
| 941 | '# instead of &. If there is any doubt, check the accompanying documentation', |
| 942 | '# to determine which situation is applicable.', |
| 943 | 'LICENSE = "Apache-2.0 & BSD-2-Clause & BSD-3-Clause & ISC & MIT & Zlib"', |
| 944 | 'LIC_FILES_CHKSUM = "file://LICENSE;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n' |
| 945 | ' file://LICENSE.Apache-2.0;md5=89aea4e17d99a7cacdbeed46a0096b10 \\\n' |
| 946 | ' file://LICENSE.BSD-3-Clause;md5=550794465ba0ec5312d6919e203a55f9 \\\n' |
| 947 | ' file://LICENSE.ISC;md5=f3b90e78ea0cffb20bf5cca7947a896d \\\n' |
| 948 | ' file://LICENSE.MIT;md5=0835ade698e0bcf8506ecda2f7b4f302 \\\n' |
| 949 | ' file://README.md;md5=0123456789abcdef0123456789abcd"', |
| 950 | '' |
| 951 | ] |
| 952 | self.assertEqual(lines_before, expected_lines_before) |
| 953 | expected_licvalues = [ |
| 954 | ('MIT', 'LICENSE', '0835ade698e0bcf8506ecda2f7b4f302'), |
| 955 | ('Apache-2.0', 'LICENSE.Apache-2.0', '89aea4e17d99a7cacdbeed46a0096b10'), |
| 956 | ('BSD-3-Clause', 'LICENSE.BSD-3-Clause', '550794465ba0ec5312d6919e203a55f9'), |
| 957 | ('ISC', 'LICENSE.ISC', 'f3b90e78ea0cffb20bf5cca7947a896d'), |
| 958 | ('MIT', 'LICENSE.MIT', '0835ade698e0bcf8506ecda2f7b4f302') |
| 959 | ] |
| 960 | self.assertEqual(handled, [('license', expected_licvalues)]) |
| 961 | self.assertEqual(extravalues, {}) |
| 962 | self.assertEqual(licvalues, expected_licvalues) |
| 963 | |
| 964 | |
| 965 | def test_recipetool_split_pkg_licenses(self): |
| 966 | from create import split_pkg_licenses |
| 967 | licvalues = [ |
| 968 | # Duplicate licenses |
| 969 | ('BSD-2-Clause', 'x/COPYING', None), |
| 970 | ('BSD-2-Clause', 'x/LICENSE', None), |
| 971 | # Multiple licenses |
| 972 | ('MIT', 'x/a/LICENSE.MIT', None), |
| 973 | ('ISC', 'x/a/LICENSE.ISC', None), |
| 974 | # Alternative licenses |
| 975 | ('(MIT | ISC)', 'x/b/LICENSE', None), |
| 976 | # Alternative licenses without brackets |
| 977 | ('MIT | BSD-2-Clause', 'x/c/LICENSE', None), |
| 978 | # Multi licenses with alternatives |
| 979 | ('MIT', 'x/d/COPYING', None), |
| 980 | ('MIT | BSD-2-Clause', 'x/d/LICENSE', None), |
| 981 | # Multi licenses with alternatives and brackets |
| 982 | ('Apache-2.0 & ((MIT | ISC) & BSD-3-Clause)', 'x/e/LICENSE', None) |
| 983 | ] |
| 984 | packages = { |
| 985 | '${PN}': '', |
| 986 | 'a': 'x/a', |
| 987 | 'b': 'x/b', |
| 988 | 'c': 'x/c', |
| 989 | 'd': 'x/d', |
| 990 | 'e': 'x/e', |
| 991 | 'f': 'x/f', |
| 992 | 'g': 'x/g', |
| 993 | } |
| 994 | fallback_licenses = { |
| 995 | # Ignored |
| 996 | 'a': 'BSD-3-Clause', |
| 997 | # Used |
| 998 | 'f': 'BSD-3-Clause' |
| 999 | } |
| 1000 | outlines = [] |
| 1001 | outlicenses = split_pkg_licenses(licvalues, packages, outlines, fallback_licenses) |
| 1002 | expected_outlicenses = { |
| 1003 | '${PN}': ['BSD-2-Clause'], |
| 1004 | 'a': ['ISC', 'MIT'], |
| 1005 | 'b': ['(ISC | MIT)'], |
| 1006 | 'c': ['(BSD-2-Clause | MIT)'], |
| 1007 | 'd': ['(BSD-2-Clause | MIT)', 'MIT'], |
| 1008 | 'e': ['(ISC | MIT)', 'Apache-2.0', 'BSD-3-Clause'], |
| 1009 | 'f': ['BSD-3-Clause'], |
| 1010 | 'g': ['Unknown'] |
| 1011 | } |
| 1012 | self.assertEqual(outlicenses, expected_outlicenses) |
| 1013 | expected_outlines = [ |
| 1014 | 'LICENSE:${PN} = "BSD-2-Clause"', |
| 1015 | 'LICENSE:a = "ISC & MIT"', |
| 1016 | 'LICENSE:b = "(ISC | MIT)"', |
| 1017 | 'LICENSE:c = "(BSD-2-Clause | MIT)"', |
| 1018 | 'LICENSE:d = "(BSD-2-Clause | MIT) & MIT"', |
| 1019 | 'LICENSE:e = "(ISC | MIT) & Apache-2.0 & BSD-3-Clause"', |
| 1020 | 'LICENSE:f = "BSD-3-Clause"', |
| 1021 | 'LICENSE:g = "Unknown"' |
| 1022 | ] |
| 1023 | self.assertEqual(outlines, expected_outlines) |
| 1024 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1025 | |
| 1026 | class RecipetoolAppendsrcBase(RecipetoolBase): |
| 1027 | def _try_recipetool_appendsrcfile(self, testrecipe, newfile, destfile, options, expectedlines, expectedfiles): |
| 1028 | cmd = 'recipetool appendsrcfile %s %s %s %s %s' % (options, self.templayerdir, testrecipe, newfile, destfile) |
| 1029 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) |
| 1030 | |
| 1031 | def _try_recipetool_appendsrcfiles(self, testrecipe, newfiles, expectedlines=None, expectedfiles=None, destdir=None, options=''): |
| 1032 | |
| 1033 | if destdir: |
| 1034 | options += ' -D %s' % destdir |
| 1035 | |
| 1036 | if expectedfiles is None: |
| 1037 | expectedfiles = [os.path.basename(f) for f in newfiles] |
| 1038 | |
| 1039 | cmd = 'recipetool appendsrcfiles %s %s %s %s' % (options, self.templayerdir, testrecipe, ' '.join(newfiles)) |
| 1040 | return self._try_recipetool_appendcmd(cmd, testrecipe, expectedfiles, expectedlines) |
| 1041 | |
| 1042 | def _try_recipetool_appendsrcfile_fail(self, testrecipe, newfile, destfile, checkerror): |
| 1043 | cmd = 'recipetool appendsrcfile %s %s %s %s' % (self.templayerdir, testrecipe, newfile, destfile or '') |
| 1044 | result = runCmd(cmd, ignore_status=True) |
| 1045 | self.assertNotEqual(result.status, 0, 'Command "%s" should have failed but didn\'t' % cmd) |
| 1046 | self.assertNotIn('Traceback', result.output) |
| 1047 | for errorstr in checkerror: |
| 1048 | self.assertIn(errorstr, result.output) |
| 1049 | |
| 1050 | @staticmethod |
| 1051 | def _get_first_file_uri(recipe): |
| 1052 | '''Return the first file:// in SRC_URI for the specified recipe.''' |
| 1053 | src_uri = get_bb_var('SRC_URI', recipe).split() |
| 1054 | for uri in src_uri: |
| 1055 | p = urllib.parse.urlparse(uri) |
| 1056 | if p.scheme == 'file': |
| 1057 | return p.netloc + p.path |
| 1058 | |
| 1059 | def _test_appendsrcfile(self, testrecipe, filename=None, destdir=None, has_src_uri=True, srcdir=None, newfile=None, options=''): |
| 1060 | if newfile is None: |
| 1061 | newfile = self.testfile |
| 1062 | |
| 1063 | if srcdir: |
| 1064 | if destdir: |
| 1065 | expected_subdir = os.path.join(srcdir, destdir) |
| 1066 | else: |
| 1067 | expected_subdir = srcdir |
| 1068 | else: |
| 1069 | options += " -W" |
| 1070 | expected_subdir = destdir |
| 1071 | |
| 1072 | if filename: |
| 1073 | if destdir: |
| 1074 | destpath = os.path.join(destdir, filename) |
| 1075 | else: |
| 1076 | destpath = filename |
| 1077 | else: |
| 1078 | filename = os.path.basename(newfile) |
| 1079 | if destdir: |
| 1080 | destpath = destdir + os.sep |
| 1081 | else: |
| 1082 | destpath = '.' + os.sep |
| 1083 | |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 1084 | expectedlines = ['FILESEXTRAPATHS:prepend := "${THISDIR}/${PN}:"\n', |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1085 | '\n'] |
| 1086 | if has_src_uri: |
| 1087 | uri = 'file://%s' % filename |
| 1088 | if expected_subdir: |
| 1089 | uri += ';subdir=%s' % expected_subdir |
| 1090 | expectedlines[0:0] = ['SRC_URI += "%s"\n' % uri, |
| 1091 | '\n'] |
| 1092 | |
| 1093 | return self._try_recipetool_appendsrcfile(testrecipe, newfile, destpath, options, expectedlines, [filename]) |
| 1094 | |
| 1095 | def _test_appendsrcfiles(self, testrecipe, newfiles, expectedfiles=None, destdir=None, options=''): |
| 1096 | if expectedfiles is None: |
| 1097 | expectedfiles = [os.path.basename(n) for n in newfiles] |
| 1098 | |
| 1099 | self._try_recipetool_appendsrcfiles(testrecipe, newfiles, expectedfiles=expectedfiles, destdir=destdir, options=options) |
| 1100 | |
| 1101 | bb_vars = get_bb_vars(['SRC_URI', 'FILE', 'FILESEXTRAPATHS'], testrecipe) |
| 1102 | src_uri = bb_vars['SRC_URI'].split() |
| 1103 | for f in expectedfiles: |
| 1104 | if destdir: |
| 1105 | self.assertIn('file://%s;subdir=%s' % (f, destdir), src_uri) |
| 1106 | else: |
| 1107 | self.assertIn('file://%s' % f, src_uri) |
| 1108 | |
| 1109 | recipefile = bb_vars['FILE'] |
| 1110 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) |
| 1111 | filesdir = os.path.join(os.path.dirname(bbappendfile), testrecipe) |
| 1112 | filesextrapaths = bb_vars['FILESEXTRAPATHS'].split(':') |
| 1113 | self.assertIn(filesdir, filesextrapaths) |
| 1114 | |
| 1115 | |
| 1116 | |
| 1117 | |
| 1118 | class RecipetoolAppendsrcTests(RecipetoolAppendsrcBase): |
| 1119 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1120 | def test_recipetool_appendsrcfile_basic(self): |
| 1121 | self._test_appendsrcfile('base-files', 'a-file') |
| 1122 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1123 | def test_recipetool_appendsrcfile_basic_wildcard(self): |
| 1124 | testrecipe = 'base-files' |
| 1125 | self._test_appendsrcfile(testrecipe, 'a-file', options='-w') |
| 1126 | recipefile = get_bb_var('FILE', testrecipe) |
| 1127 | bbappendfile = self._check_bbappend(testrecipe, recipefile, self.templayerdir) |
| 1128 | self.assertEqual(os.path.basename(bbappendfile), '%s_%%.bbappend' % testrecipe) |
| 1129 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1130 | def test_recipetool_appendsrcfile_subdir_basic(self): |
| 1131 | self._test_appendsrcfile('base-files', 'a-file', 'tmp') |
| 1132 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1133 | def test_recipetool_appendsrcfile_subdir_basic_dirdest(self): |
| 1134 | self._test_appendsrcfile('base-files', destdir='tmp') |
| 1135 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1136 | def test_recipetool_appendsrcfile_srcdir_basic(self): |
| 1137 | testrecipe = 'bash' |
| 1138 | bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) |
| 1139 | srcdir = bb_vars['S'] |
| 1140 | workdir = bb_vars['WORKDIR'] |
| 1141 | subdir = os.path.relpath(srcdir, workdir) |
| 1142 | self._test_appendsrcfile(testrecipe, 'a-file', srcdir=subdir) |
| 1143 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1144 | def test_recipetool_appendsrcfile_existing_in_src_uri(self): |
| 1145 | testrecipe = 'base-files' |
| 1146 | filepath = self._get_first_file_uri(testrecipe) |
| 1147 | self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) |
| 1148 | self._test_appendsrcfile(testrecipe, filepath, has_src_uri=False) |
| 1149 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1150 | def test_recipetool_appendsrcfile_existing_in_src_uri_diff_params(self): |
| 1151 | testrecipe = 'base-files' |
| 1152 | subdir = 'tmp' |
| 1153 | filepath = self._get_first_file_uri(testrecipe) |
| 1154 | self.assertTrue(filepath, 'Unable to test, no file:// uri found in SRC_URI for %s' % testrecipe) |
| 1155 | |
| 1156 | output = self._test_appendsrcfile(testrecipe, filepath, subdir, has_src_uri=False) |
| 1157 | self.assertTrue(any('with different parameters' in l for l in output)) |
| 1158 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1159 | def test_recipetool_appendsrcfile_replace_file_srcdir(self): |
| 1160 | testrecipe = 'bash' |
| 1161 | filepath = 'Makefile.in' |
| 1162 | bb_vars = get_bb_vars(['S', 'WORKDIR'], testrecipe) |
| 1163 | srcdir = bb_vars['S'] |
| 1164 | workdir = bb_vars['WORKDIR'] |
| 1165 | subdir = os.path.relpath(srcdir, workdir) |
| 1166 | |
| 1167 | self._test_appendsrcfile(testrecipe, filepath, srcdir=subdir) |
| 1168 | bitbake('%s:do_unpack' % testrecipe) |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 1169 | with open(self.testfile, 'r') as testfile: |
| 1170 | with open(os.path.join(srcdir, filepath), 'r') as makefilein: |
| 1171 | self.assertEqual(testfile.read(), makefilein.read()) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1172 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1173 | def test_recipetool_appendsrcfiles_basic(self, destdir=None): |
| 1174 | newfiles = [self.testfile] |
| 1175 | for i in range(1, 5): |
| 1176 | testfile = os.path.join(self.tempdir, 'testfile%d' % i) |
| 1177 | with open(testfile, 'w') as f: |
| 1178 | f.write('Test file %d\n' % i) |
| 1179 | newfiles.append(testfile) |
| 1180 | self._test_appendsrcfiles('gcc', newfiles, destdir=destdir, options='-W') |
| 1181 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1182 | def test_recipetool_appendsrcfiles_basic_subdir(self): |
| 1183 | self.test_recipetool_appendsrcfiles_basic(destdir='testdir') |