Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # BitBake Tests for the Fetcher (fetch2/) |
| 3 | # |
| 4 | # Copyright (C) 2012 Richard Purdie |
| 5 | # |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 6 | # SPDX-License-Identifier: GPL-2.0-only |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 7 | # |
| 8 | |
| 9 | import unittest |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 10 | import hashlib |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | import tempfile |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 12 | import collections |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 13 | import os |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 14 | import tarfile |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 15 | from bb.fetch2 import URI |
| 16 | from bb.fetch2 import FetchMethod |
| 17 | import bb |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 18 | from bb.tests.support.httpserver import HTTPService |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 19 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 20 | def skipIfNoNetwork(): |
| 21 | if os.environ.get("BB_SKIP_NETTESTS") == "yes": |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 22 | return unittest.skip("network test") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 23 | return lambda f: f |
| 24 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 25 | class URITest(unittest.TestCase): |
| 26 | test_uris = { |
| 27 | "http://www.google.com/index.html" : { |
| 28 | 'uri': 'http://www.google.com/index.html', |
| 29 | 'scheme': 'http', |
| 30 | 'hostname': 'www.google.com', |
| 31 | 'port': None, |
| 32 | 'hostport': 'www.google.com', |
| 33 | 'path': '/index.html', |
| 34 | 'userinfo': '', |
| 35 | 'username': '', |
| 36 | 'password': '', |
| 37 | 'params': {}, |
| 38 | 'query': {}, |
| 39 | 'relative': False |
| 40 | }, |
| 41 | "http://www.google.com/index.html;param1=value1" : { |
| 42 | 'uri': 'http://www.google.com/index.html;param1=value1', |
| 43 | 'scheme': 'http', |
| 44 | 'hostname': 'www.google.com', |
| 45 | 'port': None, |
| 46 | 'hostport': 'www.google.com', |
| 47 | 'path': '/index.html', |
| 48 | 'userinfo': '', |
| 49 | 'username': '', |
| 50 | 'password': '', |
| 51 | 'params': { |
| 52 | 'param1': 'value1' |
| 53 | }, |
| 54 | 'query': {}, |
| 55 | 'relative': False |
| 56 | }, |
| 57 | "http://www.example.org/index.html?param1=value1" : { |
| 58 | 'uri': 'http://www.example.org/index.html?param1=value1', |
| 59 | 'scheme': 'http', |
| 60 | 'hostname': 'www.example.org', |
| 61 | 'port': None, |
| 62 | 'hostport': 'www.example.org', |
| 63 | 'path': '/index.html', |
| 64 | 'userinfo': '', |
| 65 | 'username': '', |
| 66 | 'password': '', |
| 67 | 'params': {}, |
| 68 | 'query': { |
| 69 | 'param1': 'value1' |
| 70 | }, |
| 71 | 'relative': False |
| 72 | }, |
| 73 | "http://www.example.org/index.html?qparam1=qvalue1;param2=value2" : { |
| 74 | 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2', |
| 75 | 'scheme': 'http', |
| 76 | 'hostname': 'www.example.org', |
| 77 | 'port': None, |
| 78 | 'hostport': 'www.example.org', |
| 79 | 'path': '/index.html', |
| 80 | 'userinfo': '', |
| 81 | 'username': '', |
| 82 | 'password': '', |
| 83 | 'params': { |
| 84 | 'param2': 'value2' |
| 85 | }, |
| 86 | 'query': { |
| 87 | 'qparam1': 'qvalue1' |
| 88 | }, |
| 89 | 'relative': False |
| 90 | }, |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 91 | # Check that trailing semicolons are handled correctly |
| 92 | "http://www.example.org/index.html?qparam1=qvalue1;param2=value2;" : { |
| 93 | 'uri': 'http://www.example.org/index.html?qparam1=qvalue1;param2=value2', |
| 94 | 'scheme': 'http', |
| 95 | 'hostname': 'www.example.org', |
| 96 | 'port': None, |
| 97 | 'hostport': 'www.example.org', |
| 98 | 'path': '/index.html', |
| 99 | 'userinfo': '', |
| 100 | 'username': '', |
| 101 | 'password': '', |
| 102 | 'params': { |
| 103 | 'param2': 'value2' |
| 104 | }, |
| 105 | 'query': { |
| 106 | 'qparam1': 'qvalue1' |
| 107 | }, |
| 108 | 'relative': False |
| 109 | }, |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | "http://www.example.com:8080/index.html" : { |
| 111 | 'uri': 'http://www.example.com:8080/index.html', |
| 112 | 'scheme': 'http', |
| 113 | 'hostname': 'www.example.com', |
| 114 | 'port': 8080, |
| 115 | 'hostport': 'www.example.com:8080', |
| 116 | 'path': '/index.html', |
| 117 | 'userinfo': '', |
| 118 | 'username': '', |
| 119 | 'password': '', |
| 120 | 'params': {}, |
| 121 | 'query': {}, |
| 122 | 'relative': False |
| 123 | }, |
| 124 | "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : { |
| 125 | 'uri': 'cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg', |
| 126 | 'scheme': 'cvs', |
| 127 | 'hostname': 'cvs.handhelds.org', |
| 128 | 'port': None, |
| 129 | 'hostport': 'cvs.handhelds.org', |
| 130 | 'path': '/cvs', |
| 131 | 'userinfo': 'anoncvs', |
| 132 | 'username': 'anoncvs', |
| 133 | 'password': '', |
| 134 | 'params': { |
| 135 | 'module': 'familiar/dist/ipkg' |
| 136 | }, |
| 137 | 'query': {}, |
| 138 | 'relative': False |
| 139 | }, |
| 140 | "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg": { |
| 141 | 'uri': 'cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg', |
| 142 | 'scheme': 'cvs', |
| 143 | 'hostname': 'cvs.handhelds.org', |
| 144 | 'port': None, |
| 145 | 'hostport': 'cvs.handhelds.org', |
| 146 | 'path': '/cvs', |
| 147 | 'userinfo': 'anoncvs:anonymous', |
| 148 | 'username': 'anoncvs', |
| 149 | 'password': 'anonymous', |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 150 | 'params': collections.OrderedDict([ |
| 151 | ('tag', 'V0-99-81'), |
| 152 | ('module', 'familiar/dist/ipkg') |
| 153 | ]), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 154 | 'query': {}, |
| 155 | 'relative': False |
| 156 | }, |
| 157 | "file://example.diff": { # NOTE: Not RFC compliant! |
| 158 | 'uri': 'file:example.diff', |
| 159 | 'scheme': 'file', |
| 160 | 'hostname': '', |
| 161 | 'port': None, |
| 162 | 'hostport': '', |
| 163 | 'path': 'example.diff', |
| 164 | 'userinfo': '', |
| 165 | 'username': '', |
| 166 | 'password': '', |
| 167 | 'params': {}, |
| 168 | 'query': {}, |
| 169 | 'relative': True |
| 170 | }, |
| 171 | "file:example.diff": { # NOTE: RFC compliant version of the former |
| 172 | 'uri': 'file:example.diff', |
| 173 | 'scheme': 'file', |
| 174 | 'hostname': '', |
| 175 | 'port': None, |
| 176 | 'hostport': '', |
| 177 | 'path': 'example.diff', |
| 178 | 'userinfo': '', |
| 179 | 'userinfo': '', |
| 180 | 'username': '', |
| 181 | 'password': '', |
| 182 | 'params': {}, |
| 183 | 'query': {}, |
| 184 | 'relative': True |
| 185 | }, |
| 186 | "file:///tmp/example.diff": { |
| 187 | 'uri': 'file:///tmp/example.diff', |
| 188 | 'scheme': 'file', |
| 189 | 'hostname': '', |
| 190 | 'port': None, |
| 191 | 'hostport': '', |
| 192 | 'path': '/tmp/example.diff', |
| 193 | 'userinfo': '', |
| 194 | 'userinfo': '', |
| 195 | 'username': '', |
| 196 | 'password': '', |
| 197 | 'params': {}, |
| 198 | 'query': {}, |
| 199 | 'relative': False |
| 200 | }, |
| 201 | "git:///path/example.git": { |
| 202 | 'uri': 'git:///path/example.git', |
| 203 | 'scheme': 'git', |
| 204 | 'hostname': '', |
| 205 | 'port': None, |
| 206 | 'hostport': '', |
| 207 | 'path': '/path/example.git', |
| 208 | 'userinfo': '', |
| 209 | 'userinfo': '', |
| 210 | 'username': '', |
| 211 | 'password': '', |
| 212 | 'params': {}, |
| 213 | 'query': {}, |
| 214 | 'relative': False |
| 215 | }, |
| 216 | "git:path/example.git": { |
| 217 | 'uri': 'git:path/example.git', |
| 218 | 'scheme': 'git', |
| 219 | 'hostname': '', |
| 220 | 'port': None, |
| 221 | 'hostport': '', |
| 222 | 'path': 'path/example.git', |
| 223 | 'userinfo': '', |
| 224 | 'userinfo': '', |
| 225 | 'username': '', |
| 226 | 'password': '', |
| 227 | 'params': {}, |
| 228 | 'query': {}, |
| 229 | 'relative': True |
| 230 | }, |
| 231 | "git://example.net/path/example.git": { |
| 232 | 'uri': 'git://example.net/path/example.git', |
| 233 | 'scheme': 'git', |
| 234 | 'hostname': 'example.net', |
| 235 | 'port': None, |
| 236 | 'hostport': 'example.net', |
| 237 | 'path': '/path/example.git', |
| 238 | 'userinfo': '', |
| 239 | 'userinfo': '', |
| 240 | 'username': '', |
| 241 | 'password': '', |
| 242 | 'params': {}, |
| 243 | 'query': {}, |
| 244 | 'relative': False |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 245 | }, |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 246 | "git://tfs-example.org:22/tfs/example%20path/example.git": { |
| 247 | 'uri': 'git://tfs-example.org:22/tfs/example%20path/example.git', |
| 248 | 'scheme': 'git', |
| 249 | 'hostname': 'tfs-example.org', |
| 250 | 'port': 22, |
| 251 | 'hostport': 'tfs-example.org:22', |
| 252 | 'path': '/tfs/example path/example.git', |
| 253 | 'userinfo': '', |
| 254 | 'userinfo': '', |
| 255 | 'username': '', |
| 256 | 'password': '', |
| 257 | 'params': {}, |
| 258 | 'query': {}, |
| 259 | 'relative': False |
| 260 | }, |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 261 | "http://somesite.net;someparam=1": { |
| 262 | 'uri': 'http://somesite.net;someparam=1', |
| 263 | 'scheme': 'http', |
| 264 | 'hostname': 'somesite.net', |
| 265 | 'port': None, |
| 266 | 'hostport': 'somesite.net', |
| 267 | 'path': '', |
| 268 | 'userinfo': '', |
| 269 | 'userinfo': '', |
| 270 | 'username': '', |
| 271 | 'password': '', |
| 272 | 'params': {"someparam" : "1"}, |
| 273 | 'query': {}, |
| 274 | 'relative': False |
| 275 | }, |
| 276 | "file://somelocation;someparam=1": { |
| 277 | 'uri': 'file:somelocation;someparam=1', |
| 278 | 'scheme': 'file', |
| 279 | 'hostname': '', |
| 280 | 'port': None, |
| 281 | 'hostport': '', |
| 282 | 'path': 'somelocation', |
| 283 | 'userinfo': '', |
| 284 | 'userinfo': '', |
| 285 | 'username': '', |
| 286 | 'password': '', |
| 287 | 'params': {"someparam" : "1"}, |
| 288 | 'query': {}, |
| 289 | 'relative': True |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 290 | } |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 291 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | def test_uri(self): |
| 295 | for test_uri, ref in self.test_uris.items(): |
| 296 | uri = URI(test_uri) |
| 297 | |
| 298 | self.assertEqual(str(uri), ref['uri']) |
| 299 | |
| 300 | # expected attributes |
| 301 | self.assertEqual(uri.scheme, ref['scheme']) |
| 302 | |
| 303 | self.assertEqual(uri.userinfo, ref['userinfo']) |
| 304 | self.assertEqual(uri.username, ref['username']) |
| 305 | self.assertEqual(uri.password, ref['password']) |
| 306 | |
| 307 | self.assertEqual(uri.hostname, ref['hostname']) |
| 308 | self.assertEqual(uri.port, ref['port']) |
| 309 | self.assertEqual(uri.hostport, ref['hostport']) |
| 310 | |
| 311 | self.assertEqual(uri.path, ref['path']) |
| 312 | self.assertEqual(uri.params, ref['params']) |
| 313 | |
| 314 | self.assertEqual(uri.relative, ref['relative']) |
| 315 | |
| 316 | def test_dict(self): |
| 317 | for test in self.test_uris.values(): |
| 318 | uri = URI() |
| 319 | |
| 320 | self.assertEqual(uri.scheme, '') |
| 321 | self.assertEqual(uri.userinfo, '') |
| 322 | self.assertEqual(uri.username, '') |
| 323 | self.assertEqual(uri.password, '') |
| 324 | self.assertEqual(uri.hostname, '') |
| 325 | self.assertEqual(uri.port, None) |
| 326 | self.assertEqual(uri.path, '') |
| 327 | self.assertEqual(uri.params, {}) |
| 328 | |
| 329 | |
| 330 | uri.scheme = test['scheme'] |
| 331 | self.assertEqual(uri.scheme, test['scheme']) |
| 332 | |
| 333 | uri.userinfo = test['userinfo'] |
| 334 | self.assertEqual(uri.userinfo, test['userinfo']) |
| 335 | self.assertEqual(uri.username, test['username']) |
| 336 | self.assertEqual(uri.password, test['password']) |
| 337 | |
| 338 | # make sure changing the values doesn't do anything unexpected |
| 339 | uri.username = 'changeme' |
| 340 | self.assertEqual(uri.username, 'changeme') |
| 341 | self.assertEqual(uri.password, test['password']) |
| 342 | uri.password = 'insecure' |
| 343 | self.assertEqual(uri.username, 'changeme') |
| 344 | self.assertEqual(uri.password, 'insecure') |
| 345 | |
| 346 | # reset back after our trickery |
| 347 | uri.userinfo = test['userinfo'] |
| 348 | self.assertEqual(uri.userinfo, test['userinfo']) |
| 349 | self.assertEqual(uri.username, test['username']) |
| 350 | self.assertEqual(uri.password, test['password']) |
| 351 | |
| 352 | uri.hostname = test['hostname'] |
| 353 | self.assertEqual(uri.hostname, test['hostname']) |
| 354 | self.assertEqual(uri.hostport, test['hostname']) |
| 355 | |
| 356 | uri.port = test['port'] |
| 357 | self.assertEqual(uri.port, test['port']) |
| 358 | self.assertEqual(uri.hostport, test['hostport']) |
| 359 | |
| 360 | uri.path = test['path'] |
| 361 | self.assertEqual(uri.path, test['path']) |
| 362 | |
| 363 | uri.params = test['params'] |
| 364 | self.assertEqual(uri.params, test['params']) |
| 365 | |
| 366 | uri.query = test['query'] |
| 367 | self.assertEqual(uri.query, test['query']) |
| 368 | |
| 369 | self.assertEqual(str(uri), test['uri']) |
| 370 | |
| 371 | uri.params = {} |
| 372 | self.assertEqual(uri.params, {}) |
| 373 | self.assertEqual(str(uri), (str(uri).split(";"))[0]) |
| 374 | |
| 375 | class FetcherTest(unittest.TestCase): |
| 376 | |
| 377 | def setUp(self): |
| 378 | self.origdir = os.getcwd() |
| 379 | self.d = bb.data.init() |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 380 | self.tempdir = tempfile.mkdtemp(prefix="bitbake-fetch-") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 381 | self.dldir = os.path.join(self.tempdir, "download") |
| 382 | os.mkdir(self.dldir) |
| 383 | self.d.setVar("DL_DIR", self.dldir) |
| 384 | self.unpackdir = os.path.join(self.tempdir, "unpacked") |
| 385 | os.mkdir(self.unpackdir) |
| 386 | persistdir = os.path.join(self.tempdir, "persistdata") |
| 387 | self.d.setVar("PERSISTENT_DIR", persistdir) |
| 388 | |
| 389 | def tearDown(self): |
| 390 | os.chdir(self.origdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 391 | if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes": |
| 392 | print("Not cleaning up %s. Please remove manually." % self.tempdir) |
| 393 | else: |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 394 | bb.process.run('chmod u+rw -R %s' % self.tempdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 395 | bb.utils.prunedir(self.tempdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 396 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 397 | def git(self, cmd, cwd=None): |
| 398 | if isinstance(cmd, str): |
| 399 | cmd = 'git ' + cmd |
| 400 | else: |
| 401 | cmd = ['git'] + cmd |
| 402 | if cwd is None: |
| 403 | cwd = self.gitdir |
| 404 | return bb.process.run(cmd, cwd=cwd)[0] |
| 405 | |
| 406 | def git_init(self, cwd=None): |
| 407 | self.git('init', cwd=cwd) |
| 408 | if not self.git(['config', 'user.email'], cwd=cwd): |
| 409 | self.git(['config', 'user.email', 'you@example.com'], cwd=cwd) |
| 410 | if not self.git(['config', 'user.name'], cwd=cwd): |
| 411 | self.git(['config', 'user.name', 'Your Name'], cwd=cwd) |
| 412 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 413 | class MirrorUriTest(FetcherTest): |
| 414 | |
| 415 | replaceuris = { |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 416 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "http://somewhere.org/somedir/") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 417 | : "http://somewhere.org/somedir/git2_git.invalid.infradead.org.mtd-utils.git.tar.gz", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 418 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http") |
| 419 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", |
| 420 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/somedir/\\2;protocol=http") |
| 421 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", |
| 422 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/([^/]+/)*([^/]*)", "git://somewhere.org/\\2;protocol=http") |
| 423 | : "git://somewhere.org/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 424 | ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890", "git://someserver.org/bitbake", "git://git.openembedded.org/bitbake") |
| 425 | : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 426 | ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 427 | : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 428 | ("file://sstate-xyz.tgz", "file://.*", "file:///somewhere/1234/sstate-cache/") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 429 | : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 430 | ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/somedir3") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 431 | : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 432 | ("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 433 | : "http://somewhere2.org/somedir3/somefile_1.2.3.tar.gz", |
| 434 | ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://www.apache.org/dist", "http://archive.apache.org/dist") |
| 435 | : "http://archive.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", |
| 436 | ("http://www.apache.org/dist/subversion/subversion-1.7.1.tar.bz2", "http://.*/.*", "file:///somepath/downloads/") |
| 437 | : "file:///somepath/downloads/subversion-1.7.1.tar.bz2", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 438 | ("git://git.invalid.infradead.org/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http") |
| 439 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", |
| 440 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/BASENAME;protocol=http") |
| 441 | : "git://somewhere.org/somedir/mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", |
| 442 | ("git://git.invalid.infradead.org/foo/mtd-utils.git;tag=1234567890123456789012345678901234567890", "git://.*/.*", "git://somewhere.org/somedir/MIRRORNAME;protocol=http") |
| 443 | : "git://somewhere.org/somedir/git.invalid.infradead.org.foo.mtd-utils.git;tag=1234567890123456789012345678901234567890;protocol=http", |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 444 | ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org") |
| 445 | : "http://somewhere2.org/somefile_1.2.3.tar.gz", |
| 446 | ("http://somewhere.org/somedir1/somedir2/somefile_1.2.3.tar.gz", "http://.*/.*", "http://somewhere2.org/") |
| 447 | : "http://somewhere2.org/somefile_1.2.3.tar.gz", |
| 448 | ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://git.openembedded.org/bitbake;protocol=http") |
| 449 | : "git://git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http", |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 450 | ("git://user1@someserver.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master", "git://someserver.org/bitbake;branch=master", "git://user2@git.openembedded.org/bitbake;protocol=http") |
| 451 | : "git://user2@git.openembedded.org/bitbake;tag=1234567890123456789012345678901234567890;branch=master;protocol=http", |
| 452 | ("git://someserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=git;branch=master", "git://someserver.org/bitbake", "git://someotherserver.org/bitbake;protocol=https") |
| 453 | : "git://someotherserver.org/bitbake;tag=1234567890123456789012345678901234567890;protocol=https;branch=master", |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 454 | ("gitsm://git.qemu.org/git/seabios.git/;protocol=https;name=roms/seabios;subpath=roms/seabios;bareclone=1;nobranch=1;rev=1234567890123456789012345678901234567890", "gitsm://.*/.*", "http://petalinux.xilinx.com/sswreleases/rel-v${XILINX_VER_MAIN}/downloads") : "http://petalinux.xilinx.com/sswreleases/rel-v%24%7BXILINX_VER_MAIN%7D/downloads/git2_git.qemu.org.git.seabios.git..tar.gz", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 455 | ("https://somewhere.org/example/1.0.0/example;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/PATH") |
| 456 | : "file:///mirror/example/1.0.0/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", |
| 457 | ("https://somewhere.org/example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", "https://.*/.*", "file:///mirror/some-example-1.0.0.tgz") |
| 458 | : "file:///mirror/some-example-1.0.0.tgz;downloadfilename=some-example-1.0.0.tgz", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 459 | |
| 460 | #Renaming files doesn't work |
| 461 | #("http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere.org/somedir1/somefile_1.2.3.tar.gz", "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz") : "http://somewhere2.org/somedir3/somefile_2.3.4.tar.gz" |
| 462 | #("file://sstate-xyz.tgz", "file://.*/.*", "file:///somewhere/1234/sstate-cache") : "file:///somewhere/1234/sstate-cache/sstate-xyz.tgz", |
| 463 | } |
| 464 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 465 | mirrorvar = "http://.*/.* file:///somepath/downloads/ " \ |
| 466 | "git://someserver.org/bitbake git://git.openembedded.org/bitbake " \ |
| 467 | "https://.*/.* file:///someotherpath/downloads/ " \ |
| 468 | "http://.*/.* file:///someotherpath/downloads/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 469 | |
| 470 | def test_urireplace(self): |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 471 | self.d.setVar("FILESPATH", ".") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 472 | for k, v in self.replaceuris.items(): |
| 473 | ud = bb.fetch.FetchData(k[0], self.d) |
| 474 | ud.setup_localpath(self.d) |
| 475 | mirrors = bb.fetch2.mirror_from_string("%s %s" % (k[1], k[2])) |
| 476 | newuris, uds = bb.fetch2.build_mirroruris(ud, mirrors, self.d) |
| 477 | self.assertEqual([v], newuris) |
| 478 | |
| 479 | def test_urilist1(self): |
| 480 | fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) |
| 481 | mirrors = bb.fetch2.mirror_from_string(self.mirrorvar) |
| 482 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) |
| 483 | self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', 'file:///someotherpath/downloads/bitbake-1.0.tar.gz']) |
| 484 | |
| 485 | def test_urilist2(self): |
| 486 | # Catch https:// -> files:// bug |
| 487 | fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) |
| 488 | mirrors = bb.fetch2.mirror_from_string(self.mirrorvar) |
| 489 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) |
| 490 | self.assertEqual(uris, ['file:///someotherpath/downloads/bitbake-1.0.tar.gz']) |
| 491 | |
| 492 | def test_mirror_of_mirror(self): |
| 493 | # Test if mirror of a mirror works |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 494 | mirrorvar = self.mirrorvar + " http://.*/.* http://otherdownloads.yoctoproject.org/downloads/" |
| 495 | mirrorvar = mirrorvar + " http://otherdownloads.yoctoproject.org/.* http://downloads2.yoctoproject.org/downloads/" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 496 | fetcher = bb.fetch.FetchData("http://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) |
| 497 | mirrors = bb.fetch2.mirror_from_string(mirrorvar) |
| 498 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) |
| 499 | self.assertEqual(uris, ['file:///somepath/downloads/bitbake-1.0.tar.gz', |
| 500 | 'file:///someotherpath/downloads/bitbake-1.0.tar.gz', |
| 501 | 'http://otherdownloads.yoctoproject.org/downloads/bitbake-1.0.tar.gz', |
| 502 | 'http://downloads2.yoctoproject.org/downloads/bitbake-1.0.tar.gz']) |
| 503 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 504 | recmirrorvar = "https://.*/[^/]* http://AAAA/A/A/A/ " \ |
| 505 | "https://.*/[^/]* https://BBBB/B/B/B/" |
Patrick Williams | d7e9631 | 2015-09-22 08:09:05 -0500 | [diff] [blame] | 506 | |
| 507 | def test_recursive(self): |
| 508 | fetcher = bb.fetch.FetchData("https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", self.d) |
| 509 | mirrors = bb.fetch2.mirror_from_string(self.recmirrorvar) |
| 510 | uris, uds = bb.fetch2.build_mirroruris(fetcher, mirrors, self.d) |
| 511 | self.assertEqual(uris, ['http://AAAA/A/A/A/bitbake/bitbake-1.0.tar.gz', |
| 512 | 'https://BBBB/B/B/B/bitbake/bitbake-1.0.tar.gz', |
| 513 | 'http://AAAA/A/A/A/B/B/bitbake/bitbake-1.0.tar.gz']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 514 | |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 515 | |
| 516 | class GitDownloadDirectoryNamingTest(FetcherTest): |
| 517 | def setUp(self): |
| 518 | super(GitDownloadDirectoryNamingTest, self).setUp() |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 519 | self.recipe_url = "git://git.openembedded.org/bitbake;branch=master" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 520 | self.recipe_dir = "git.openembedded.org.bitbake" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 521 | self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 522 | self.mirror_dir = "github.com.openembedded.bitbake.git" |
| 523 | |
| 524 | self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40') |
| 525 | |
| 526 | def setup_mirror_rewrite(self): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 527 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 528 | |
| 529 | @skipIfNoNetwork() |
| 530 | def test_that_directory_is_named_after_recipe_url_when_no_mirroring_is_used(self): |
| 531 | self.setup_mirror_rewrite() |
| 532 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 533 | |
| 534 | fetcher.download() |
| 535 | |
| 536 | dir = os.listdir(self.dldir + "/git2") |
| 537 | self.assertIn(self.recipe_dir, dir) |
| 538 | |
| 539 | @skipIfNoNetwork() |
| 540 | def test_that_directory_exists_for_mirrored_url_and_recipe_url_when_mirroring_is_used(self): |
| 541 | self.setup_mirror_rewrite() |
| 542 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 543 | |
| 544 | fetcher.download() |
| 545 | |
| 546 | dir = os.listdir(self.dldir + "/git2") |
| 547 | self.assertIn(self.mirror_dir, dir) |
| 548 | self.assertIn(self.recipe_dir, dir) |
| 549 | |
| 550 | @skipIfNoNetwork() |
| 551 | def test_that_recipe_directory_and_mirrored_directory_exists_when_mirroring_is_used_and_the_mirrored_directory_already_exists(self): |
| 552 | self.setup_mirror_rewrite() |
| 553 | fetcher = bb.fetch.Fetch([self.mirror_url], self.d) |
| 554 | fetcher.download() |
| 555 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 556 | |
| 557 | fetcher.download() |
| 558 | |
| 559 | dir = os.listdir(self.dldir + "/git2") |
| 560 | self.assertIn(self.mirror_dir, dir) |
| 561 | self.assertIn(self.recipe_dir, dir) |
| 562 | |
| 563 | |
| 564 | class TarballNamingTest(FetcherTest): |
| 565 | def setUp(self): |
| 566 | super(TarballNamingTest, self).setUp() |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 567 | self.recipe_url = "git://git.openembedded.org/bitbake;branch=master" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 568 | self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 569 | self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 570 | self.mirror_tarball = "git2_github.com.openembedded.bitbake.git.tar.gz" |
| 571 | |
| 572 | self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1') |
| 573 | self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40') |
| 574 | |
| 575 | def setup_mirror_rewrite(self): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 576 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 577 | |
| 578 | @skipIfNoNetwork() |
| 579 | def test_that_the_recipe_tarball_is_created_when_no_mirroring_is_used(self): |
| 580 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 581 | |
| 582 | fetcher.download() |
| 583 | |
| 584 | dir = os.listdir(self.dldir) |
| 585 | self.assertIn(self.recipe_tarball, dir) |
| 586 | |
| 587 | @skipIfNoNetwork() |
| 588 | def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self): |
| 589 | self.setup_mirror_rewrite() |
| 590 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 591 | |
| 592 | fetcher.download() |
| 593 | |
| 594 | dir = os.listdir(self.dldir) |
| 595 | self.assertIn(self.mirror_tarball, dir) |
| 596 | |
| 597 | |
| 598 | class GitShallowTarballNamingTest(FetcherTest): |
| 599 | def setUp(self): |
| 600 | super(GitShallowTarballNamingTest, self).setUp() |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 601 | self.recipe_url = "git://git.openembedded.org/bitbake;branch=master" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 602 | self.recipe_tarball = "gitshallow_git.openembedded.org.bitbake_82ea737-1_master.tar.gz" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 603 | self.mirror_url = "git://github.com/openembedded/bitbake.git;protocol=https;branch=master" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 604 | self.mirror_tarball = "gitshallow_github.com.openembedded.bitbake.git_82ea737-1_master.tar.gz" |
| 605 | |
| 606 | self.d.setVar('BB_GIT_SHALLOW', '1') |
| 607 | self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1') |
| 608 | self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40') |
| 609 | |
| 610 | def setup_mirror_rewrite(self): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 611 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + self.mirror_url) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 612 | |
| 613 | @skipIfNoNetwork() |
| 614 | def test_that_the_tarball_is_named_after_recipe_url_when_no_mirroring_is_used(self): |
| 615 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 616 | |
| 617 | fetcher.download() |
| 618 | |
| 619 | dir = os.listdir(self.dldir) |
| 620 | self.assertIn(self.recipe_tarball, dir) |
| 621 | |
| 622 | @skipIfNoNetwork() |
| 623 | def test_that_the_mirror_tarball_is_created_when_mirroring_is_used(self): |
| 624 | self.setup_mirror_rewrite() |
| 625 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 626 | |
| 627 | fetcher.download() |
| 628 | |
| 629 | dir = os.listdir(self.dldir) |
| 630 | self.assertIn(self.mirror_tarball, dir) |
| 631 | |
| 632 | |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 633 | class CleanTarballTest(FetcherTest): |
| 634 | def setUp(self): |
| 635 | super(CleanTarballTest, self).setUp() |
| 636 | self.recipe_url = "git://git.openembedded.org/bitbake" |
| 637 | self.recipe_tarball = "git2_git.openembedded.org.bitbake.tar.gz" |
| 638 | |
| 639 | self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '1') |
| 640 | self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40') |
| 641 | |
| 642 | @skipIfNoNetwork() |
| 643 | def test_that_the_tarball_contents_does_not_leak_info(self): |
| 644 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 645 | |
| 646 | fetcher.download() |
| 647 | |
| 648 | fetcher.unpack(self.unpackdir) |
| 649 | mtime = bb.process.run('git log --all -1 --format=%ct', |
| 650 | cwd=os.path.join(self.unpackdir, 'git')) |
| 651 | self.assertEqual(len(mtime), 2) |
| 652 | mtime = int(mtime[0]) |
| 653 | |
| 654 | archive = tarfile.open(os.path.join(self.dldir, self.recipe_tarball)) |
| 655 | self.assertNotEqual(len(archive.members), 0) |
| 656 | for member in archive.members: |
Patrick Williams | 03907ee | 2022-05-01 06:28:52 -0500 | [diff] [blame] | 657 | self.assertEqual(member.uname, 'oe') |
| 658 | self.assertEqual(member.uid, 0) |
| 659 | self.assertEqual(member.gname, 'oe') |
| 660 | self.assertEqual(member.gid, 0) |
Andrew Geissler | 9aee500 | 2022-03-30 16:27:02 +0000 | [diff] [blame] | 661 | self.assertEqual(member.mtime, mtime) |
| 662 | |
| 663 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 664 | class FetcherLocalTest(FetcherTest): |
| 665 | def setUp(self): |
| 666 | def touch(fn): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 667 | with open(fn, 'a'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 668 | os.utime(fn, None) |
| 669 | |
| 670 | super(FetcherLocalTest, self).setUp() |
| 671 | self.localsrcdir = os.path.join(self.tempdir, 'localsrc') |
| 672 | os.makedirs(self.localsrcdir) |
| 673 | touch(os.path.join(self.localsrcdir, 'a')) |
| 674 | touch(os.path.join(self.localsrcdir, 'b')) |
| 675 | os.makedirs(os.path.join(self.localsrcdir, 'dir')) |
| 676 | touch(os.path.join(self.localsrcdir, 'dir', 'c')) |
| 677 | touch(os.path.join(self.localsrcdir, 'dir', 'd')) |
| 678 | os.makedirs(os.path.join(self.localsrcdir, 'dir', 'subdir')) |
| 679 | touch(os.path.join(self.localsrcdir, 'dir', 'subdir', 'e')) |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 680 | touch(os.path.join(self.localsrcdir, r'backslash\x2dsystemd-unit.device')) |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 681 | bb.process.run('tar cf archive.tar -C dir .', cwd=self.localsrcdir) |
| 682 | bb.process.run('tar czf archive.tar.gz -C dir .', cwd=self.localsrcdir) |
| 683 | bb.process.run('tar cjf archive.tar.bz2 -C dir .', cwd=self.localsrcdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 684 | self.d.setVar("FILESPATH", self.localsrcdir) |
| 685 | |
| 686 | def fetchUnpack(self, uris): |
| 687 | fetcher = bb.fetch.Fetch(uris, self.d) |
| 688 | fetcher.download() |
| 689 | fetcher.unpack(self.unpackdir) |
| 690 | flst = [] |
| 691 | for root, dirs, files in os.walk(self.unpackdir): |
| 692 | for f in files: |
| 693 | flst.append(os.path.relpath(os.path.join(root, f), self.unpackdir)) |
| 694 | flst.sort() |
| 695 | return flst |
| 696 | |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 697 | def test_local_checksum_fails_no_file(self): |
| 698 | self.d.setVar("SRC_URI", "file://404") |
| 699 | with self.assertRaises(bb.BBHandledException): |
| 700 | bb.fetch.get_checksum_file_list(self.d) |
| 701 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 702 | def test_local(self): |
| 703 | tree = self.fetchUnpack(['file://a', 'file://dir/c']) |
| 704 | self.assertEqual(tree, ['a', 'dir/c']) |
| 705 | |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 706 | def test_local_backslash(self): |
| 707 | tree = self.fetchUnpack([r'file://backslash\x2dsystemd-unit.device']) |
| 708 | self.assertEqual(tree, [r'backslash\x2dsystemd-unit.device']) |
| 709 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 710 | def test_local_wildcard(self): |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 711 | with self.assertRaises(bb.fetch2.ParameterError): |
| 712 | tree = self.fetchUnpack(['file://a', 'file://dir/*']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 713 | |
| 714 | def test_local_dir(self): |
| 715 | tree = self.fetchUnpack(['file://a', 'file://dir']) |
| 716 | self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e']) |
| 717 | |
| 718 | def test_local_subdir(self): |
| 719 | tree = self.fetchUnpack(['file://dir/subdir']) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 720 | self.assertEqual(tree, ['dir/subdir/e']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 721 | |
| 722 | def test_local_subdir_file(self): |
| 723 | tree = self.fetchUnpack(['file://dir/subdir/e']) |
| 724 | self.assertEqual(tree, ['dir/subdir/e']) |
| 725 | |
| 726 | def test_local_subdirparam(self): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 727 | tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo']) |
| 728 | self.assertEqual(tree, ['bar/a', 'foo/moo/dir/c', 'foo/moo/dir/d', 'foo/moo/dir/subdir/e']) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 729 | |
| 730 | def test_local_deepsubdirparam(self): |
| 731 | tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar']) |
| 732 | self.assertEqual(tree, ['bar/dir/subdir/e']) |
| 733 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 734 | def test_local_absolutedir(self): |
| 735 | # Unpacking to an absolute path that is a subdirectory of the root |
| 736 | # should work |
| 737 | tree = self.fetchUnpack(['file://a;subdir=%s' % os.path.join(self.unpackdir, 'bar')]) |
| 738 | |
| 739 | # Unpacking to an absolute path outside of the root should fail |
| 740 | with self.assertRaises(bb.fetch2.UnpackError): |
| 741 | self.fetchUnpack(['file://a;subdir=/bin/sh']) |
| 742 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 743 | def test_local_striplevel(self): |
| 744 | tree = self.fetchUnpack(['file://archive.tar;subdir=bar;striplevel=1']) |
| 745 | self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e']) |
| 746 | |
| 747 | def test_local_striplevel_gzip(self): |
| 748 | tree = self.fetchUnpack(['file://archive.tar.gz;subdir=bar;striplevel=1']) |
| 749 | self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e']) |
| 750 | |
| 751 | def test_local_striplevel_bzip2(self): |
| 752 | tree = self.fetchUnpack(['file://archive.tar.bz2;subdir=bar;striplevel=1']) |
| 753 | self.assertEqual(tree, ['bar/c', 'bar/d', 'bar/subdir/e']) |
| 754 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 755 | def dummyGitTest(self, suffix): |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 756 | # Create dummy local Git repo |
| 757 | src_dir = tempfile.mkdtemp(dir=self.tempdir, |
| 758 | prefix='gitfetch_localusehead_') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 759 | self.gitdir = os.path.abspath(src_dir) |
| 760 | self.git_init() |
| 761 | self.git(['commit', '--allow-empty', '-m', 'Dummy commit']) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 762 | # Use other branch than master |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 763 | self.git(['checkout', '-b', 'my-devel']) |
| 764 | self.git(['commit', '--allow-empty', '-m', 'Dummy commit 2']) |
| 765 | orig_rev = self.git(['rev-parse', 'HEAD']).strip() |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 766 | |
| 767 | # Fetch and check revision |
| 768 | self.d.setVar("SRCREV", "AUTOINC") |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 769 | self.d.setVar("__BBSEENSRCREV", "1") |
| 770 | url = "git://" + self.gitdir + ";branch=master;protocol=file;" + suffix |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 771 | fetcher = bb.fetch.Fetch([url], self.d) |
| 772 | fetcher.download() |
| 773 | fetcher.unpack(self.unpackdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 774 | unpack_rev = self.git(['rev-parse', 'HEAD'], |
| 775 | cwd=os.path.join(self.unpackdir, 'git')).strip() |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 776 | self.assertEqual(orig_rev, unpack_rev) |
| 777 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 778 | def test_local_gitfetch_usehead(self): |
| 779 | self.dummyGitTest("usehead=1") |
| 780 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 781 | def test_local_gitfetch_usehead_withname(self): |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 782 | self.dummyGitTest("usehead=1;name=newName") |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 783 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 784 | def test_local_gitfetch_shared(self): |
| 785 | self.dummyGitTest("usehead=1;name=sharedName") |
| 786 | alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates') |
| 787 | self.assertTrue(os.path.exists(alt)) |
| 788 | |
| 789 | def test_local_gitfetch_noshared(self): |
| 790 | self.d.setVar('BB_GIT_NOSHARED', '1') |
| 791 | self.unpackdir += '_noshared' |
| 792 | self.dummyGitTest("usehead=1;name=noSharedName") |
| 793 | alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates') |
| 794 | self.assertFalse(os.path.exists(alt)) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 795 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 796 | class FetcherNoNetworkTest(FetcherTest): |
| 797 | def setUp(self): |
| 798 | super().setUp() |
| 799 | # all test cases are based on not having network |
| 800 | self.d.setVar("BB_NO_NETWORK", "1") |
| 801 | |
| 802 | def test_missing(self): |
| 803 | string = "this is a test file\n".encode("utf-8") |
| 804 | self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest()) |
| 805 | self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest()) |
| 806 | |
| 807 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 808 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 809 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d) |
| 810 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 811 | fetcher.download() |
| 812 | |
| 813 | def test_valid_missing_donestamp(self): |
| 814 | # create the file in the download directory with correct hash |
| 815 | string = "this is a test file\n".encode("utf-8") |
| 816 | with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb") as f: |
| 817 | f.write(string) |
| 818 | |
| 819 | self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest()) |
| 820 | self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest()) |
| 821 | |
| 822 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 823 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 824 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d) |
| 825 | fetcher.download() |
| 826 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 827 | |
| 828 | def test_invalid_missing_donestamp(self): |
| 829 | # create an invalid file in the download directory with incorrect hash |
| 830 | string = "this is a test file\n".encode("utf-8") |
| 831 | with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"): |
| 832 | pass |
| 833 | |
| 834 | self.d.setVarFlag("SRC_URI", "md5sum", hashlib.md5(string).hexdigest()) |
| 835 | self.d.setVarFlag("SRC_URI", "sha256sum", hashlib.sha256(string).hexdigest()) |
| 836 | |
| 837 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 838 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 839 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/test-file.tar.gz"], self.d) |
| 840 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 841 | fetcher.download() |
| 842 | # the existing file should not exist or should have be moved to "bad-checksum" |
| 843 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 844 | |
| 845 | def test_nochecksums_missing(self): |
| 846 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 847 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 848 | # ssh fetch does not support checksums |
| 849 | fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d) |
| 850 | # attempts to download with missing donestamp |
| 851 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 852 | fetcher.download() |
| 853 | |
| 854 | def test_nochecksums_missing_donestamp(self): |
| 855 | # create a file in the download directory |
| 856 | with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"): |
| 857 | pass |
| 858 | |
| 859 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 860 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 861 | # ssh fetch does not support checksums |
| 862 | fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d) |
| 863 | # attempts to download with missing donestamp |
| 864 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 865 | fetcher.download() |
| 866 | |
| 867 | def test_nochecksums_has_donestamp(self): |
| 868 | # create a file in the download directory with the donestamp |
| 869 | with open(os.path.join(self.dldir, "test-file.tar.gz"), "wb"): |
| 870 | pass |
| 871 | with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"): |
| 872 | pass |
| 873 | |
| 874 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 875 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 876 | # ssh fetch does not support checksums |
| 877 | fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d) |
| 878 | # should not fetch |
| 879 | fetcher.download() |
| 880 | # both files should still exist |
| 881 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 882 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 883 | |
| 884 | def test_nochecksums_missing_has_donestamp(self): |
| 885 | # create a file in the download directory with the donestamp |
| 886 | with open(os.path.join(self.dldir, "test-file.tar.gz.done"), "wb"): |
| 887 | pass |
| 888 | |
| 889 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 890 | self.assertTrue(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 891 | # ssh fetch does not support checksums |
| 892 | fetcher = bb.fetch.Fetch(["ssh://invalid@invalid.yoctoproject.org/test-file.tar.gz"], self.d) |
| 893 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 894 | fetcher.download() |
| 895 | # both files should still exist |
| 896 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz"))) |
| 897 | self.assertFalse(os.path.exists(os.path.join(self.dldir, "test-file.tar.gz.done"))) |
| 898 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 899 | class FetcherNetworkTest(FetcherTest): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 900 | @skipIfNoNetwork() |
| 901 | def test_fetch(self): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 902 | fetcher = bb.fetch.Fetch(["https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 903 | fetcher.download() |
| 904 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 905 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.1.tar.gz"), 57892) |
| 906 | self.d.setVar("BB_NO_NETWORK", "1") |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 907 | fetcher = bb.fetch.Fetch(["https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz", "https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz"], self.d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 908 | fetcher.download() |
| 909 | fetcher.unpack(self.unpackdir) |
| 910 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.0/")), 9) |
| 911 | self.assertEqual(len(os.listdir(self.unpackdir + "/bitbake-1.1/")), 9) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 912 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 913 | @skipIfNoNetwork() |
| 914 | def test_fetch_mirror(self): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 915 | self.d.setVar("MIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 916 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) |
| 917 | fetcher.download() |
| 918 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 919 | |
| 920 | @skipIfNoNetwork() |
| 921 | def test_fetch_mirror_of_mirror(self): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 922 | self.d.setVar("MIRRORS", "http://.*/.* http://invalid2.yoctoproject.org/ http://invalid2.yoctoproject.org/.* https://downloads.yoctoproject.org/releases/bitbake") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 923 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) |
| 924 | fetcher.download() |
| 925 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 926 | |
| 927 | @skipIfNoNetwork() |
| 928 | def test_fetch_file_mirror_of_mirror(self): |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 929 | self.d.setVar("FILESPATH", ".") |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 930 | self.d.setVar("MIRRORS", "http://.*/.* file:///some1where/ file:///some1where/.* file://some2where/ file://some2where/.* https://downloads.yoctoproject.org/releases/bitbake") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 931 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) |
| 932 | os.mkdir(self.dldir + "/some2where") |
| 933 | fetcher.download() |
| 934 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 935 | |
| 936 | @skipIfNoNetwork() |
| 937 | def test_fetch_premirror(self): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 938 | self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 939 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz"], self.d) |
| 940 | fetcher.download() |
| 941 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 942 | |
| 943 | @skipIfNoNetwork() |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 944 | def test_fetch_specify_downloadfilename(self): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 945 | fetcher = bb.fetch.Fetch(["https://downloads.yoctoproject.org/releases/bitbake/bitbake-1.0.tar.gz;downloadfilename=bitbake-v1.0.0.tar.gz"], self.d) |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 946 | fetcher.download() |
| 947 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-v1.0.0.tar.gz"), 57749) |
| 948 | |
| 949 | @skipIfNoNetwork() |
| 950 | def test_fetch_premirror_specify_downloadfilename_regex_uri(self): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 951 | self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake/") |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 952 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/1.0.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d) |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 953 | fetcher.download() |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 954 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 955 | |
| 956 | @skipIfNoNetwork() |
| 957 | # BZ13039 |
| 958 | def test_fetch_premirror_specify_downloadfilename_specific_uri(self): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 959 | self.d.setVar("PREMIRRORS", "http://invalid.yoctoproject.org/releases/bitbake https://downloads.yoctoproject.org/releases/bitbake") |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 960 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/1.0.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d) |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 961 | fetcher.download() |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 962 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
| 963 | |
| 964 | @skipIfNoNetwork() |
| 965 | def test_fetch_premirror_use_downloadfilename_to_fetch(self): |
| 966 | # Ensure downloadfilename is used when fetching from premirror. |
| 967 | self.d.setVar("PREMIRRORS", "http://.*/.* https://downloads.yoctoproject.org/releases/bitbake") |
| 968 | fetcher = bb.fetch.Fetch(["http://invalid.yoctoproject.org/releases/bitbake/bitbake-1.1.tar.gz;downloadfilename=bitbake-1.0.tar.gz"], self.d) |
| 969 | fetcher.download() |
| 970 | self.assertEqual(os.path.getsize(self.dldir + "/bitbake-1.0.tar.gz"), 57749) |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 971 | |
| 972 | @skipIfNoNetwork() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 973 | def gitfetcher(self, url1, url2): |
| 974 | def checkrevision(self, fetcher): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 975 | fetcher.unpack(self.unpackdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 976 | revision = self.git(['rev-parse', 'HEAD'], |
| 977 | cwd=os.path.join(self.unpackdir, 'git')).strip() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 978 | self.assertEqual(revision, "270a05b0b4ba0959fe0624d2a4885d7b70426da5") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 979 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 980 | self.d.setVar("BB_GENERATE_MIRROR_TARBALLS", "1") |
| 981 | self.d.setVar("SRCREV", "270a05b0b4ba0959fe0624d2a4885d7b70426da5") |
| 982 | fetcher = bb.fetch.Fetch([url1], self.d) |
| 983 | fetcher.download() |
| 984 | checkrevision(self, fetcher) |
| 985 | # Wipe out the dldir clone and the unpacked source, turn off the network and check mirror tarball works |
| 986 | bb.utils.prunedir(self.dldir + "/git2/") |
| 987 | bb.utils.prunedir(self.unpackdir) |
| 988 | self.d.setVar("BB_NO_NETWORK", "1") |
| 989 | fetcher = bb.fetch.Fetch([url2], self.d) |
| 990 | fetcher.download() |
| 991 | checkrevision(self, fetcher) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 992 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 993 | @skipIfNoNetwork() |
| 994 | def test_gitfetch(self): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 995 | url1 = url2 = "git://git.openembedded.org/bitbake;branch=master" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 996 | self.gitfetcher(url1, url2) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 997 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 998 | @skipIfNoNetwork() |
| 999 | def test_gitfetch_goodsrcrev(self): |
| 1000 | # SRCREV is set but matches rev= parameter |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1001 | url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1002 | self.gitfetcher(url1, url2) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1003 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1004 | @skipIfNoNetwork() |
| 1005 | def test_gitfetch_badsrcrev(self): |
| 1006 | # SRCREV is set but does not match rev= parameter |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1007 | url1 = url2 = "git://git.openembedded.org/bitbake;rev=dead05b0b4ba0959fe0624d2a4885d7b70426da5;branch=master" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1008 | self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1009 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1010 | @skipIfNoNetwork() |
| 1011 | def test_gitfetch_tagandrev(self): |
| 1012 | # SRCREV is set but does not match rev= parameter |
| 1013 | url1 = url2 = "git://git.openembedded.org/bitbake;rev=270a05b0b4ba0959fe0624d2a4885d7b70426da5;tag=270a05b0b4ba0959fe0624d2a4885d7b70426da5" |
| 1014 | self.assertRaises(bb.fetch.FetchError, self.gitfetcher, url1, url2) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1015 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1016 | @skipIfNoNetwork() |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1017 | def test_gitfetch_usehead(self): |
| 1018 | # Since self.gitfetcher() sets SRCREV we expect this to override |
| 1019 | # `usehead=1' and instead fetch the specified SRCREV. See |
| 1020 | # test_local_gitfetch_usehead() for a positive use of the usehead |
| 1021 | # feature. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1022 | url = "git://git.openembedded.org/bitbake;usehead=1;branch=master" |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1023 | self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1024 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1025 | @skipIfNoNetwork() |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 1026 | def test_gitfetch_usehead_withname(self): |
| 1027 | # Since self.gitfetcher() sets SRCREV we expect this to override |
| 1028 | # `usehead=1' and instead fetch the specified SRCREV. See |
| 1029 | # test_local_gitfetch_usehead() for a positive use of the usehead |
| 1030 | # feature. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1031 | url = "git://git.openembedded.org/bitbake;usehead=1;name=newName;branch=master" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1032 | self.assertRaises(bb.fetch.ParameterError, self.gitfetcher, url, url) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1033 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1034 | @skipIfNoNetwork() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1035 | def test_gitfetch_finds_local_tarball_for_mirrored_url_when_previous_downloaded_by_the_recipe_url(self): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1036 | recipeurl = "git://git.openembedded.org/bitbake;branch=master" |
| 1037 | mirrorurl = "git://someserver.org/bitbake;branch=master" |
| 1038 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1039 | self.gitfetcher(recipeurl, mirrorurl) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1040 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1041 | @skipIfNoNetwork() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1042 | def test_gitfetch_finds_local_tarball_when_previous_downloaded_from_a_premirror(self): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1043 | recipeurl = "git://someserver.org/bitbake;branch=master" |
| 1044 | self.d.setVar("PREMIRRORS", "git://someserver.org/bitbake git://git.openembedded.org/bitbake") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1045 | self.gitfetcher(recipeurl, recipeurl) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1046 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1047 | @skipIfNoNetwork() |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1048 | def test_gitfetch_finds_local_repository_when_premirror_rewrites_the_recipe_url(self): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1049 | realurl = "git://git.openembedded.org/bitbake" |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1050 | recipeurl = "git://someserver.org/bitbake" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1051 | self.sourcedir = self.unpackdir.replace("unpacked", "sourcemirror.git") |
| 1052 | os.chdir(self.tempdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1053 | self.git(['clone', realurl, self.sourcedir], cwd=self.tempdir) |
| 1054 | self.d.setVar("PREMIRRORS", "%s git://%s;protocol=file" % (recipeurl, self.sourcedir)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1055 | self.gitfetcher(recipeurl, recipeurl) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1056 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1057 | @skipIfNoNetwork() |
| 1058 | def test_git_submodule(self): |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1059 | # URL with ssh submodules |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1060 | url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=ssh-gitsm-tests;rev=049da4a6cb198d7c0302e9e8b243a1443cb809a7;branch=master" |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1061 | # Original URL (comment this if you have ssh access to git.yoctoproject.org) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1062 | url = "gitsm://git.yoctoproject.org/git-submodule-test;branch=master;rev=a2885dd7d25380d23627e7544b7bbb55014b16ee;branch=master" |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1063 | fetcher = bb.fetch.Fetch([url], self.d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1064 | fetcher.download() |
| 1065 | # Previous cwd has been deleted |
| 1066 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1067 | fetcher.unpack(self.unpackdir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1068 | |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1069 | repo_path = os.path.join(self.tempdir, 'unpacked', 'git') |
| 1070 | self.assertTrue(os.path.exists(repo_path), msg='Unpacked repository missing') |
| 1071 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake')), msg='bitbake submodule missing') |
| 1072 | self.assertFalse(os.path.exists(os.path.join(repo_path, 'na')), msg='uninitialized submodule present') |
| 1073 | |
| 1074 | # Only when we're running the extended test with a submodule's submodule, can we check this. |
| 1075 | if os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1')): |
| 1076 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'bitbake-gitsm-test1', 'bitbake')), msg='submodule of submodule missing') |
| 1077 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1078 | @skipIfNoNetwork() |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1079 | def test_git_submodule_dbus_broker(self): |
| 1080 | # The following external repositories have show failures in fetch and unpack operations |
| 1081 | # We want to avoid regressions! |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1082 | url = "gitsm://github.com/bus1/dbus-broker;protocol=https;rev=fc874afa0992d0c75ec25acb43d344679f0ee7d2;branch=main" |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1083 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1084 | fetcher.download() |
| 1085 | # Previous cwd has been deleted |
| 1086 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1087 | fetcher.unpack(self.unpackdir) |
| 1088 | |
| 1089 | repo_path = os.path.join(self.tempdir, 'unpacked', 'git') |
| 1090 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-dvar/config')), msg='Missing submodule config "subprojects/c-dvar"') |
| 1091 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-list/config')), msg='Missing submodule config "subprojects/c-list"') |
| 1092 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-rbtree/config')), msg='Missing submodule config "subprojects/c-rbtree"') |
| 1093 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-sundry/config')), msg='Missing submodule config "subprojects/c-sundry"') |
| 1094 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/subprojects/c-utf8/config')), msg='Missing submodule config "subprojects/c-utf8"') |
| 1095 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1096 | @skipIfNoNetwork() |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1097 | def test_git_submodule_CLI11(self): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1098 | url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=bd4dc911847d0cde7a6b41dfa626a85aab213baf;branch=main" |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1099 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1100 | fetcher.download() |
| 1101 | # Previous cwd has been deleted |
| 1102 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1103 | fetcher.unpack(self.unpackdir) |
| 1104 | |
| 1105 | repo_path = os.path.join(self.tempdir, 'unpacked', 'git') |
| 1106 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"') |
| 1107 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"') |
| 1108 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"') |
| 1109 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1110 | @skipIfNoNetwork() |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1111 | def test_git_submodule_update_CLI11(self): |
| 1112 | """ Prevent regression on update detection not finding missing submodule, or modules without needed commits """ |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1113 | url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=cf6a99fa69aaefe477cc52e3ef4a7d2d7fa40714;branch=main" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1114 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1115 | fetcher.download() |
| 1116 | |
| 1117 | # CLI11 that pulls in a newer nlohmann-json |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1118 | url = "gitsm://github.com/CLIUtils/CLI11;protocol=https;rev=49ac989a9527ee9bb496de9ded7b4872c2e0e5ca;branch=main" |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1119 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1120 | fetcher.download() |
| 1121 | # Previous cwd has been deleted |
| 1122 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1123 | fetcher.unpack(self.unpackdir) |
| 1124 | |
| 1125 | repo_path = os.path.join(self.tempdir, 'unpacked', 'git') |
| 1126 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/googletest/config')), msg='Missing submodule config "extern/googletest"') |
| 1127 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/json/config')), msg='Missing submodule config "extern/json"') |
| 1128 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/extern/sanitizers/config')), msg='Missing submodule config "extern/sanitizers"') |
| 1129 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1130 | @skipIfNoNetwork() |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1131 | def test_git_submodule_aktualizr(self): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1132 | url = "gitsm://github.com/advancedtelematic/aktualizr;branch=master;protocol=https;rev=d00d1a04cc2366d1a5f143b84b9f507f8bd32c44" |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1133 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1134 | fetcher.download() |
| 1135 | # Previous cwd has been deleted |
| 1136 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1137 | fetcher.unpack(self.unpackdir) |
| 1138 | |
| 1139 | repo_path = os.path.join(self.tempdir, 'unpacked', 'git') |
| 1140 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/partial/extern/isotp-c/config')), msg='Missing submodule config "partial/extern/isotp-c/config"') |
| 1141 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/partial/extern/isotp-c/modules/deps/bitfield-c/config')), msg='Missing submodule config "partial/extern/isotp-c/modules/deps/bitfield-c/config"') |
| 1142 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'partial/extern/isotp-c/deps/bitfield-c/.git')), msg="Submodule of submodule isotp-c did not unpack properly") |
| 1143 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/tests/tuf-test-vectors/config')), msg='Missing submodule config "tests/tuf-test-vectors/config"') |
| 1144 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/googletest/config')), msg='Missing submodule config "third_party/googletest/config"') |
| 1145 | self.assertTrue(os.path.exists(os.path.join(repo_path, '.git/modules/third_party/HdrHistogram_c/config')), msg='Missing submodule config "third_party/HdrHistogram_c/config"') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1146 | |
Brad Bishop | 96ff198 | 2019-08-19 13:50:42 -0400 | [diff] [blame] | 1147 | @skipIfNoNetwork() |
Brad Bishop | 393846f | 2019-05-20 12:24:11 -0400 | [diff] [blame] | 1148 | def test_git_submodule_iotedge(self): |
| 1149 | """ Prevent regression on deeply nested submodules not being checked out properly, even though they were fetched. """ |
| 1150 | |
| 1151 | # This repository also has submodules where the module (name), path and url do not align |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1152 | url = "gitsm://github.com/azure/iotedge.git;protocol=https;rev=d76e0316c6f324345d77c48a83ce836d09392699;branch=main" |
Brad Bishop | 393846f | 2019-05-20 12:24:11 -0400 | [diff] [blame] | 1153 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1154 | fetcher.download() |
| 1155 | # Previous cwd has been deleted |
| 1156 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1157 | fetcher.unpack(self.unpackdir) |
| 1158 | |
| 1159 | repo_path = os.path.join(self.tempdir, 'unpacked', 'git') |
| 1160 | |
| 1161 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/README.md')), msg='Missing submodule checkout') |
| 1162 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/ctest/README.md')), msg='Missing submodule checkout') |
| 1163 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/testrunner/readme.md')), msg='Missing submodule checkout') |
| 1164 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/readme.md')), msg='Missing submodule checkout') |
| 1165 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/deps/ctest/README.md')), msg='Missing submodule checkout') |
| 1166 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/c-shared/testtools/umock-c/deps/testrunner/readme.md')), msg='Missing submodule checkout') |
| 1167 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/README.md')), msg='Missing submodule checkout') |
| 1168 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/README.md')), msg='Missing submodule checkout') |
| 1169 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/ctest/README.md')), msg='Missing submodule checkout') |
| 1170 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/testrunner/readme.md')), msg='Missing submodule checkout') |
| 1171 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/readme.md')), msg='Missing submodule checkout') |
| 1172 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/ctest/README.md')), msg='Missing submodule checkout') |
| 1173 | self.assertTrue(os.path.exists(os.path.join(repo_path, 'edgelet/hsm-sys/azure-iot-hsm-c/deps/utpm/deps/c-utility/testtools/umock-c/deps/testrunner/readme.md')), msg='Missing submodule checkout') |
| 1174 | |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1175 | class SVNTest(FetcherTest): |
| 1176 | def skipIfNoSvn(): |
| 1177 | import shutil |
| 1178 | if not shutil.which("svn"): |
| 1179 | return unittest.skip("svn not installed, tests being skipped") |
| 1180 | |
| 1181 | if not shutil.which("svnadmin"): |
| 1182 | return unittest.skip("svnadmin not installed, tests being skipped") |
| 1183 | |
| 1184 | return lambda f: f |
| 1185 | |
| 1186 | @skipIfNoSvn() |
| 1187 | def setUp(self): |
| 1188 | """ Create a local repository """ |
| 1189 | |
| 1190 | super(SVNTest, self).setUp() |
| 1191 | |
| 1192 | # Create something we can fetch |
| 1193 | src_dir = tempfile.mkdtemp(dir=self.tempdir, |
| 1194 | prefix='svnfetch_srcdir_') |
| 1195 | src_dir = os.path.abspath(src_dir) |
| 1196 | bb.process.run("echo readme > README.md", cwd=src_dir) |
| 1197 | |
| 1198 | # Store it in a local SVN repository |
| 1199 | repo_dir = tempfile.mkdtemp(dir=self.tempdir, |
| 1200 | prefix='svnfetch_localrepo_') |
| 1201 | repo_dir = os.path.abspath(repo_dir) |
| 1202 | bb.process.run("svnadmin create project", cwd=repo_dir) |
| 1203 | |
| 1204 | self.repo_url = "file://%s/project" % repo_dir |
| 1205 | bb.process.run("svn import --non-interactive -m 'Initial import' %s %s/trunk" % (src_dir, self.repo_url), |
| 1206 | cwd=repo_dir) |
| 1207 | |
| 1208 | bb.process.run("svn co %s svnfetch_co" % self.repo_url, cwd=self.tempdir) |
| 1209 | # Github will emulate SVN. Use this to check if we're downloding... |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1210 | bb.process.run("svn propset svn:externals 'bitbake https://github.com/PhilipHazel/pcre2.git' .", |
Brad Bishop | 15ae250 | 2019-06-18 21:44:24 -0400 | [diff] [blame] | 1211 | cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk')) |
| 1212 | bb.process.run("svn commit --non-interactive -m 'Add external'", |
| 1213 | cwd=os.path.join(self.tempdir, 'svnfetch_co', 'trunk')) |
| 1214 | |
| 1215 | self.src_dir = src_dir |
| 1216 | self.repo_dir = repo_dir |
| 1217 | |
| 1218 | @skipIfNoSvn() |
| 1219 | def tearDown(self): |
| 1220 | os.chdir(self.origdir) |
| 1221 | if os.environ.get("BB_TMPDIR_NOCLEAN") == "yes": |
| 1222 | print("Not cleaning up %s. Please remove manually." % self.tempdir) |
| 1223 | else: |
| 1224 | bb.utils.prunedir(self.tempdir) |
| 1225 | |
| 1226 | @skipIfNoSvn() |
| 1227 | @skipIfNoNetwork() |
| 1228 | def test_noexternal_svn(self): |
| 1229 | # Always match the rev count from setUp (currently rev 2) |
| 1230 | url = "svn://%s;module=trunk;protocol=file;rev=2" % self.repo_url.replace('file://', '') |
| 1231 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1232 | fetcher.download() |
| 1233 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1234 | fetcher.unpack(self.unpackdir) |
| 1235 | |
| 1236 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk") |
| 1237 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents") |
| 1238 | self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should NOT exist") |
| 1239 | self.assertFalse(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should NOT exit") |
| 1240 | |
| 1241 | @skipIfNoSvn() |
| 1242 | def test_external_svn(self): |
| 1243 | # Always match the rev count from setUp (currently rev 2) |
| 1244 | url = "svn://%s;module=trunk;protocol=file;externals=allowed;rev=2" % self.repo_url.replace('file://', '') |
| 1245 | fetcher = bb.fetch.Fetch([url], self.d) |
| 1246 | fetcher.download() |
| 1247 | os.chdir(os.path.dirname(self.unpackdir)) |
| 1248 | fetcher.unpack(self.unpackdir) |
| 1249 | |
| 1250 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk')), msg="Missing trunk") |
| 1251 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk', 'README.md')), msg="Missing contents") |
| 1252 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk')), msg="External dir should exist") |
| 1253 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'trunk/bitbake/trunk', 'README')), msg="External README should exit") |
| 1254 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1255 | class TrustedNetworksTest(FetcherTest): |
| 1256 | def test_trusted_network(self): |
| 1257 | # Ensure trusted_network returns False when the host IS in the list. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1258 | url = "git://Someserver.org/foo;rev=1;branch=master" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1259 | self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org someserver.org server2.org server3.org") |
| 1260 | self.assertTrue(bb.fetch.trusted_network(self.d, url)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1261 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1262 | def test_wild_trusted_network(self): |
| 1263 | # Ensure trusted_network returns true when the *.host IS in the list. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1264 | url = "git://Someserver.org/foo;rev=1;branch=master" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1265 | self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org") |
| 1266 | self.assertTrue(bb.fetch.trusted_network(self.d, url)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1267 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1268 | def test_prefix_wild_trusted_network(self): |
| 1269 | # Ensure trusted_network returns true when the prefix matches *.host. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1270 | url = "git://git.Someserver.org/foo;rev=1;branch=master" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1271 | self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org") |
| 1272 | self.assertTrue(bb.fetch.trusted_network(self.d, url)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1273 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1274 | def test_two_prefix_wild_trusted_network(self): |
| 1275 | # Ensure trusted_network returns true when the prefix matches *.host. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1276 | url = "git://something.git.Someserver.org/foo;rev=1;branch=master" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1277 | self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org *.someserver.org server2.org server3.org") |
| 1278 | self.assertTrue(bb.fetch.trusted_network(self.d, url)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1279 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1280 | def test_port_trusted_network(self): |
| 1281 | # Ensure trusted_network returns True, even if the url specifies a port. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1282 | url = "git://someserver.org:8080/foo;rev=1;branch=master" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1283 | self.d.setVar("BB_ALLOWED_NETWORKS", "someserver.org") |
| 1284 | self.assertTrue(bb.fetch.trusted_network(self.d, url)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1285 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1286 | def test_untrusted_network(self): |
| 1287 | # Ensure trusted_network returns False when the host is NOT in the list. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1288 | url = "git://someserver.org/foo;rev=1;branch=master" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1289 | self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org") |
| 1290 | self.assertFalse(bb.fetch.trusted_network(self.d, url)) |
| 1291 | |
| 1292 | def test_wild_untrusted_network(self): |
| 1293 | # Ensure trusted_network returns False when the host is NOT in the list. |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1294 | url = "git://*.someserver.org/foo;rev=1;branch=master" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1295 | self.d.setVar("BB_ALLOWED_NETWORKS", "server1.org server2.org server3.org") |
| 1296 | self.assertFalse(bb.fetch.trusted_network(self.d, url)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1297 | |
| 1298 | class URLHandle(unittest.TestCase): |
| 1299 | |
| 1300 | datatable = { |
| 1301 | "http://www.google.com/index.html" : ('http', 'www.google.com', '/index.html', '', '', {}), |
| 1302 | "cvs://anoncvs@cvs.handhelds.org/cvs;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', '', {'module': 'familiar/dist/ipkg'}), |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1303 | "cvs://anoncvs:anonymous@cvs.handhelds.org/cvs;tag=V0-99-81;module=familiar/dist/ipkg" : ('cvs', 'cvs.handhelds.org', '/cvs', 'anoncvs', 'anonymous', collections.OrderedDict([('tag', 'V0-99-81'), ('module', 'familiar/dist/ipkg')])), |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1304 | "git://git.openembedded.org/bitbake;branch=@foo" : ('git', 'git.openembedded.org', '/bitbake', '', '', {'branch': '@foo'}), |
| 1305 | "file://somelocation;someparam=1": ('file', '', 'somelocation', '', '', {'someparam': '1'}), |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1306 | } |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1307 | # we require a pathname to encodeurl but users can still pass such urls to |
| 1308 | # decodeurl and we need to handle them |
| 1309 | decodedata = datatable.copy() |
| 1310 | decodedata.update({ |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1311 | "http://somesite.net;someparam=1": ('http', 'somesite.net', '/', '', '', {'someparam': '1'}), |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1312 | }) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1313 | |
| 1314 | def test_decodeurl(self): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1315 | for k, v in self.decodedata.items(): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1316 | result = bb.fetch.decodeurl(k) |
| 1317 | self.assertEqual(result, v) |
| 1318 | |
| 1319 | def test_encodeurl(self): |
| 1320 | for k, v in self.datatable.items(): |
| 1321 | result = bb.fetch.encodeurl(v) |
| 1322 | self.assertEqual(result, k) |
| 1323 | |
| 1324 | class FetchLatestVersionTest(FetcherTest): |
| 1325 | |
| 1326 | test_git_uris = { |
| 1327 | # version pattern "X.Y.Z" |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1328 | ("mx-1.0", "git://github.com/clutter-project/mx.git;branch=mx-1.4;protocol=https", "9b1db6b8060bd00b121a692f942404a24ae2960f", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1329 | : "1.99.4", |
| 1330 | # version pattern "vX.Y" |
Andrew Geissler | d25ed32 | 2020-06-27 00:28:28 -0500 | [diff] [blame] | 1331 | # mirror of git.infradead.org since network issues interfered with testing |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1332 | ("mtd-utils", "git://git.yoctoproject.org/mtd-utils.git;branch=master", "ca39eb1d98e736109c64ff9c1aa2a6ecca222d8f", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1333 | : "1.5.0", |
| 1334 | # version pattern "pkg_name-X.Y" |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1335 | # mirror of git://anongit.freedesktop.org/git/xorg/proto/presentproto since network issues interfered with testing |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1336 | ("presentproto", "git://git.yoctoproject.org/bbfetchtests-presentproto;branch=master", "24f3a56e541b0a9e6c6ee76081f441221a120ef9", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1337 | : "1.0", |
| 1338 | # version pattern "pkg_name-vX.Y.Z" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1339 | ("dtc", "git://git.yoctoproject.org/bbfetchtests-dtc.git;branch=master", "65cc4d2748a2c2e6f27f1cf39e07a5dbabd80ebf", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1340 | : "1.4.0", |
| 1341 | # combination version pattern |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1342 | ("sysprof", "git://gitlab.gnome.org/GNOME/sysprof.git;protocol=https;branch=master", "cd44ee6644c3641507fb53b8a2a69137f2971219", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1343 | : "1.2.0", |
| 1344 | ("u-boot-mkimage", "git://git.denx.de/u-boot.git;branch=master;protocol=git", "62c175fbb8a0f9a926c88294ea9f7e88eb898f6c", "") |
| 1345 | : "2014.01", |
| 1346 | # version pattern "yyyymmdd" |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1347 | ("mobile-broadband-provider-info", "git://gitlab.gnome.org/GNOME/mobile-broadband-provider-info.git;protocol=https;branch=master", "4ed19e11c2975105b71b956440acdb25d46a347d", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1348 | : "20120614", |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1349 | # packages with a valid UPSTREAM_CHECK_GITTAGREGEX |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1350 | # mirror of git://anongit.freedesktop.org/xorg/driver/xf86-video-omap since network issues interfered with testing |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1351 | ("xf86-video-omap", "git://git.yoctoproject.org/bbfetchtests-xf86-video-omap;branch=master", "ae0394e687f1a77e966cf72f895da91840dffb8f", r"(?P<pver>(\d+\.(\d\.?)*))") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1352 | : "0.4.3", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1353 | ("build-appliance-image", "git://git.yoctoproject.org/poky;branch=master", "b37dd451a52622d5b570183a81583cc34c2ff555", r"(?P<pver>(([0-9][\.|_]?)+[0-9]))") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1354 | : "11.0.0", |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1355 | ("chkconfig-alternatives-native", "git://github.com/kergoth/chkconfig;branch=sysroot;protocol=https", "cd437ecbd8986c894442f8fce1e0061e20f04dee", r"chkconfig\-(?P<pver>((\d+[\.\-_]*)+))") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1356 | : "1.3.59", |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1357 | ("remake", "git://github.com/rocky/remake.git;protocol=https;branch=master", "f05508e521987c8494c92d9c2871aec46307d51d", r"(?P<pver>(\d+\.(\d+\.)*\d*(\+dbg\d+(\.\d+)*)*))") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1358 | : "3.82+dbg0.9", |
| 1359 | } |
| 1360 | |
| 1361 | test_wget_uris = { |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1362 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1363 | # packages with versions inside directory name |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1364 | # |
| 1365 | # http://kernel.org/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2 |
| 1366 | ("util-linux", "/pub/linux/utils/util-linux/v2.23/util-linux-2.24.2.tar.bz2", "", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1367 | : "2.24.2", |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1368 | # http://www.abisource.com/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz |
| 1369 | ("enchant", "/downloads/enchant/1.6.0/enchant-1.6.0.tar.gz", "", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1370 | : "1.6.0", |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1371 | # http://www.cmake.org/files/v2.8/cmake-2.8.12.1.tar.gz |
| 1372 | ("cmake", "/files/v2.8/cmake-2.8.12.1.tar.gz", "", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1373 | : "2.8.12.1", |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1374 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1375 | # packages with versions only in current directory |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1376 | # |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 1377 | # https://downloads.yoctoproject.org/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1378 | ("eglic", "/releases/eglibc/eglibc-2.18-svnr23787.tar.bz2", "", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1379 | : "2.19", |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 1380 | # https://downloads.yoctoproject.org/releases/gnu-config/gnu-config-20120814.tar.bz2 |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1381 | ("gnu-config", "/releases/gnu-config/gnu-config-20120814.tar.bz2", "", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1382 | : "20120814", |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1383 | # |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1384 | # packages with "99" in the name of possible version |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1385 | # |
| 1386 | # http://freedesktop.org/software/pulseaudio/releases/pulseaudio-4.0.tar.xz |
| 1387 | ("pulseaudio", "/software/pulseaudio/releases/pulseaudio-4.0.tar.xz", "", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1388 | : "5.0", |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1389 | # http://xorg.freedesktop.org/releases/individual/xserver/xorg-server-1.15.1.tar.bz2 |
| 1390 | ("xserver-xorg", "/releases/individual/xserver/xorg-server-1.15.1.tar.bz2", "", "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1391 | : "1.15.1", |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1392 | # |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1393 | # packages with valid UPSTREAM_CHECK_URI and UPSTREAM_CHECK_REGEX |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1394 | # |
| 1395 | # http://www.cups.org/software/1.7.2/cups-1.7.2-source.tar.bz2 |
| 1396 | # https://github.com/apple/cups/releases |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 1397 | ("cups", "/software/1.7.2/cups-1.7.2-source.tar.bz2", "/apple/cups/releases", r"(?P<name>cups\-)(?P<pver>((\d+[\.\-_]*)+))\-source\.tar\.gz") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1398 | : "2.0.0", |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1399 | # http://download.oracle.com/berkeley-db/db-5.3.21.tar.gz |
| 1400 | # http://ftp.debian.org/debian/pool/main/d/db5.3/ |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 1401 | ("db", "/berkeley-db/db-5.3.21.tar.gz", "/debian/pool/main/d/db5.3/", r"(?P<name>db5\.3_)(?P<pver>\d+(\.\d+)+).+\.orig\.tar\.xz") |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 1402 | : "5.3.10", |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 1403 | # |
| 1404 | # packages where the tarball compression changed in the new version |
| 1405 | # |
| 1406 | # http://ftp.debian.org/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz |
| 1407 | ("minicom", "/debian/pool/main/m/minicom/minicom_2.7.1.orig.tar.gz", "", "") |
| 1408 | : "2.8", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1409 | } |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1410 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1411 | @skipIfNoNetwork() |
| 1412 | def test_git_latest_versionstring(self): |
| 1413 | for k, v in self.test_git_uris.items(): |
| 1414 | self.d.setVar("PN", k[0]) |
| 1415 | self.d.setVar("SRCREV", k[2]) |
| 1416 | self.d.setVar("UPSTREAM_CHECK_GITTAGREGEX", k[3]) |
| 1417 | ud = bb.fetch2.FetchData(k[1], self.d) |
| 1418 | pupver= ud.method.latest_versionstring(ud, self.d) |
| 1419 | verstring = pupver[0] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1420 | self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0]) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1421 | r = bb.utils.vercmp_string(v, verstring) |
| 1422 | self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) |
| 1423 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1424 | def test_wget_latest_versionstring(self): |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1425 | testdata = os.path.dirname(os.path.abspath(__file__)) + "/fetch-testdata" |
| 1426 | server = HTTPService(testdata) |
| 1427 | server.start() |
| 1428 | port = server.port |
| 1429 | try: |
| 1430 | for k, v in self.test_wget_uris.items(): |
| 1431 | self.d.setVar("PN", k[0]) |
| 1432 | checkuri = "" |
| 1433 | if k[2]: |
| 1434 | checkuri = "http://localhost:%s/" % port + k[2] |
| 1435 | self.d.setVar("UPSTREAM_CHECK_URI", checkuri) |
| 1436 | self.d.setVar("UPSTREAM_CHECK_REGEX", k[3]) |
| 1437 | url = "http://localhost:%s/" % port + k[1] |
| 1438 | ud = bb.fetch2.FetchData(url, self.d) |
| 1439 | pupver = ud.method.latest_versionstring(ud, self.d) |
| 1440 | verstring = pupver[0] |
| 1441 | self.assertTrue(verstring, msg="Could not find upstream version for %s" % k[0]) |
| 1442 | r = bb.utils.vercmp_string(v, verstring) |
| 1443 | self.assertTrue(r == -1 or r == 0, msg="Package %s, version: %s <= %s" % (k[0], v, verstring)) |
| 1444 | finally: |
| 1445 | server.stop() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1446 | |
| 1447 | |
| 1448 | class FetchCheckStatusTest(FetcherTest): |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 1449 | test_wget_uris = ["https://downloads.yoctoproject.org/releases/sato/sato-engine-0.1.tar.gz", |
| 1450 | "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.2.tar.gz", |
| 1451 | "https://downloads.yoctoproject.org/releases/sato/sato-engine-0.3.tar.gz", |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1452 | "https://yoctoproject.org/", |
Andrew Geissler | 95ac1b8 | 2021-03-31 14:34:31 -0500 | [diff] [blame] | 1453 | "https://docs.yoctoproject.org", |
Andrew Geissler | eff2747 | 2021-10-29 15:35:00 -0500 | [diff] [blame] | 1454 | "https://downloads.yoctoproject.org/releases/opkg/opkg-0.1.7.tar.gz", |
| 1455 | "https://downloads.yoctoproject.org/releases/opkg/opkg-0.3.0.tar.gz", |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1456 | "ftp://sourceware.org/pub/libffi/libffi-1.20.tar.gz", |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1457 | # GitHub releases are hosted on Amazon S3, which doesn't support HEAD |
| 1458 | "https://github.com/kergoth/tslib/releases/download/1.1/tslib-1.1.tar.xz" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1459 | ] |
| 1460 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1461 | @skipIfNoNetwork() |
| 1462 | def test_wget_checkstatus(self): |
| 1463 | fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d) |
| 1464 | for u in self.test_wget_uris: |
| 1465 | with self.subTest(url=u): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1466 | ud = fetch.ud[u] |
| 1467 | m = ud.method |
| 1468 | ret = m.checkstatus(fetch, ud, self.d) |
| 1469 | self.assertTrue(ret, msg="URI %s, can't check status" % (u)) |
| 1470 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1471 | @skipIfNoNetwork() |
| 1472 | def test_wget_checkstatus_connection_cache(self): |
| 1473 | from bb.fetch2 import FetchConnectionCache |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1474 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1475 | connection_cache = FetchConnectionCache() |
| 1476 | fetch = bb.fetch2.Fetch(self.test_wget_uris, self.d, |
| 1477 | connection_cache = connection_cache) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1478 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1479 | for u in self.test_wget_uris: |
| 1480 | with self.subTest(url=u): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1481 | ud = fetch.ud[u] |
| 1482 | m = ud.method |
| 1483 | ret = m.checkstatus(fetch, ud, self.d) |
| 1484 | self.assertTrue(ret, msg="URI %s, can't check status" % (u)) |
| 1485 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1486 | connection_cache.close_connections() |
| 1487 | |
| 1488 | |
| 1489 | class GitMakeShallowTest(FetcherTest): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1490 | def setUp(self): |
| 1491 | FetcherTest.setUp(self) |
| 1492 | self.gitdir = os.path.join(self.tempdir, 'gitshallow') |
| 1493 | bb.utils.mkdirhier(self.gitdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1494 | self.git_init() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1495 | |
| 1496 | def assertRefs(self, expected_refs): |
| 1497 | actual_refs = self.git(['for-each-ref', '--format=%(refname)']).splitlines() |
| 1498 | full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs).splitlines() |
| 1499 | self.assertEqual(sorted(full_expected), sorted(actual_refs)) |
| 1500 | |
| 1501 | def assertRevCount(self, expected_count, args=None): |
| 1502 | if args is None: |
| 1503 | args = ['HEAD'] |
| 1504 | revs = self.git(['rev-list'] + args) |
| 1505 | actual_count = len(revs.splitlines()) |
| 1506 | self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count)) |
| 1507 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1508 | def make_shallow(self, args=None): |
| 1509 | if args is None: |
| 1510 | args = ['HEAD'] |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 1511 | return bb.process.run([bb.fetch2.git.Git.make_shallow_path] + args, cwd=self.gitdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1512 | |
| 1513 | def add_empty_file(self, path, msg=None): |
| 1514 | if msg is None: |
| 1515 | msg = path |
| 1516 | open(os.path.join(self.gitdir, path), 'w').close() |
| 1517 | self.git(['add', path]) |
| 1518 | self.git(['commit', '-m', msg, path]) |
| 1519 | |
| 1520 | def test_make_shallow_single_branch_no_merge(self): |
| 1521 | self.add_empty_file('a') |
| 1522 | self.add_empty_file('b') |
| 1523 | self.assertRevCount(2) |
| 1524 | self.make_shallow() |
| 1525 | self.assertRevCount(1) |
| 1526 | |
| 1527 | def test_make_shallow_single_branch_one_merge(self): |
| 1528 | self.add_empty_file('a') |
| 1529 | self.add_empty_file('b') |
| 1530 | self.git('checkout -b a_branch') |
| 1531 | self.add_empty_file('c') |
| 1532 | self.git('checkout master') |
| 1533 | self.add_empty_file('d') |
| 1534 | self.git('merge --no-ff --no-edit a_branch') |
| 1535 | self.git('branch -d a_branch') |
| 1536 | self.add_empty_file('e') |
| 1537 | self.assertRevCount(6) |
| 1538 | self.make_shallow(['HEAD~2']) |
| 1539 | self.assertRevCount(5) |
| 1540 | |
| 1541 | def test_make_shallow_at_merge(self): |
| 1542 | self.add_empty_file('a') |
| 1543 | self.git('checkout -b a_branch') |
| 1544 | self.add_empty_file('b') |
| 1545 | self.git('checkout master') |
| 1546 | self.git('merge --no-ff --no-edit a_branch') |
| 1547 | self.git('branch -d a_branch') |
| 1548 | self.assertRevCount(3) |
| 1549 | self.make_shallow() |
| 1550 | self.assertRevCount(1) |
| 1551 | |
| 1552 | def test_make_shallow_annotated_tag(self): |
| 1553 | self.add_empty_file('a') |
| 1554 | self.add_empty_file('b') |
| 1555 | self.git('tag -a -m a_tag a_tag') |
| 1556 | self.assertRevCount(2) |
| 1557 | self.make_shallow(['a_tag']) |
| 1558 | self.assertRevCount(1) |
| 1559 | |
| 1560 | def test_make_shallow_multi_ref(self): |
| 1561 | self.add_empty_file('a') |
| 1562 | self.add_empty_file('b') |
| 1563 | self.git('checkout -b a_branch') |
| 1564 | self.add_empty_file('c') |
| 1565 | self.git('checkout master') |
| 1566 | self.add_empty_file('d') |
| 1567 | self.git('checkout -b a_branch_2') |
| 1568 | self.add_empty_file('a_tag') |
| 1569 | self.git('tag a_tag') |
| 1570 | self.git('checkout master') |
| 1571 | self.git('branch -D a_branch_2') |
| 1572 | self.add_empty_file('e') |
| 1573 | self.assertRevCount(6, ['--all']) |
| 1574 | self.make_shallow() |
| 1575 | self.assertRevCount(5, ['--all']) |
| 1576 | |
| 1577 | def test_make_shallow_multi_ref_trim(self): |
| 1578 | self.add_empty_file('a') |
| 1579 | self.git('checkout -b a_branch') |
| 1580 | self.add_empty_file('c') |
| 1581 | self.git('checkout master') |
| 1582 | self.assertRevCount(1) |
| 1583 | self.assertRevCount(2, ['--all']) |
| 1584 | self.assertRefs(['master', 'a_branch']) |
| 1585 | self.make_shallow(['-r', 'master', 'HEAD']) |
| 1586 | self.assertRevCount(1, ['--all']) |
| 1587 | self.assertRefs(['master']) |
| 1588 | |
| 1589 | def test_make_shallow_noop(self): |
| 1590 | self.add_empty_file('a') |
| 1591 | self.assertRevCount(1) |
| 1592 | self.make_shallow() |
| 1593 | self.assertRevCount(1) |
| 1594 | |
| 1595 | @skipIfNoNetwork() |
| 1596 | def test_make_shallow_bitbake(self): |
| 1597 | self.git('remote add origin https://github.com/openembedded/bitbake') |
| 1598 | self.git('fetch --tags origin') |
| 1599 | orig_revs = len(self.git('rev-list --all').splitlines()) |
| 1600 | self.make_shallow(['refs/tags/1.10.0']) |
| 1601 | self.assertRevCount(orig_revs - 1746, ['--all']) |
| 1602 | |
| 1603 | class GitShallowTest(FetcherTest): |
| 1604 | def setUp(self): |
| 1605 | FetcherTest.setUp(self) |
| 1606 | self.gitdir = os.path.join(self.tempdir, 'git') |
| 1607 | self.srcdir = os.path.join(self.tempdir, 'gitsource') |
| 1608 | |
| 1609 | bb.utils.mkdirhier(self.srcdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1610 | self.git_init(cwd=self.srcdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1611 | self.d.setVar('WORKDIR', self.tempdir) |
| 1612 | self.d.setVar('S', self.gitdir) |
| 1613 | self.d.delVar('PREMIRRORS') |
| 1614 | self.d.delVar('MIRRORS') |
| 1615 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1616 | uri = 'git://%s;protocol=file;subdir=${S};branch=master' % self.srcdir |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1617 | self.d.setVar('SRC_URI', uri) |
| 1618 | self.d.setVar('SRCREV', '${AUTOREV}') |
| 1619 | self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}') |
| 1620 | |
| 1621 | self.d.setVar('BB_GIT_SHALLOW', '1') |
| 1622 | self.d.setVar('BB_GENERATE_MIRROR_TARBALLS', '0') |
| 1623 | self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1624 | self.d.setVar("__BBSEENSRCREV", "1") |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1625 | |
| 1626 | def assertRefs(self, expected_refs, cwd=None): |
| 1627 | if cwd is None: |
| 1628 | cwd = self.gitdir |
| 1629 | actual_refs = self.git(['for-each-ref', '--format=%(refname)'], cwd=cwd).splitlines() |
| 1630 | full_expected = self.git(['rev-parse', '--symbolic-full-name'] + expected_refs, cwd=cwd).splitlines() |
| 1631 | self.assertEqual(sorted(set(full_expected)), sorted(set(actual_refs))) |
| 1632 | |
| 1633 | def assertRevCount(self, expected_count, args=None, cwd=None): |
| 1634 | if args is None: |
| 1635 | args = ['HEAD'] |
| 1636 | if cwd is None: |
| 1637 | cwd = self.gitdir |
| 1638 | revs = self.git(['rev-list'] + args, cwd=cwd) |
| 1639 | actual_count = len(revs.splitlines()) |
| 1640 | self.assertEqual(expected_count, actual_count, msg='Object count `%d` is not the expected `%d`' % (actual_count, expected_count)) |
| 1641 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1642 | def add_empty_file(self, path, cwd=None, msg=None): |
| 1643 | if msg is None: |
| 1644 | msg = path |
| 1645 | if cwd is None: |
| 1646 | cwd = self.srcdir |
| 1647 | open(os.path.join(cwd, path), 'w').close() |
| 1648 | self.git(['add', path], cwd) |
| 1649 | self.git(['commit', '-m', msg, path], cwd) |
| 1650 | |
| 1651 | def fetch(self, uri=None): |
| 1652 | if uri is None: |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1653 | uris = self.d.getVar('SRC_URI').split() |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1654 | uri = uris[0] |
| 1655 | d = self.d |
| 1656 | else: |
| 1657 | d = self.d.createCopy() |
| 1658 | d.setVar('SRC_URI', uri) |
| 1659 | uri = d.expand(uri) |
| 1660 | uris = [uri] |
| 1661 | |
| 1662 | fetcher = bb.fetch2.Fetch(uris, d) |
| 1663 | fetcher.download() |
| 1664 | ud = fetcher.ud[uri] |
| 1665 | return fetcher, ud |
| 1666 | |
| 1667 | def fetch_and_unpack(self, uri=None): |
| 1668 | fetcher, ud = self.fetch(uri) |
| 1669 | fetcher.unpack(self.d.getVar('WORKDIR')) |
| 1670 | assert os.path.exists(self.d.getVar('S')) |
| 1671 | return fetcher, ud |
| 1672 | |
| 1673 | def fetch_shallow(self, uri=None, disabled=False, keepclone=False): |
| 1674 | """Fetch a uri, generating a shallow tarball, then unpack using it""" |
| 1675 | fetcher, ud = self.fetch_and_unpack(uri) |
| 1676 | assert os.path.exists(ud.clonedir), 'Git clone in DLDIR (%s) does not exist for uri %s' % (ud.clonedir, uri) |
| 1677 | |
| 1678 | # Confirm that the unpacked repo is unshallow |
| 1679 | if not disabled: |
| 1680 | assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0])) |
| 1681 | |
| 1682 | # fetch and unpack, from the shallow tarball |
| 1683 | bb.utils.remove(self.gitdir, recurse=True) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1684 | bb.process.run('chmod u+w -R "%s"' % ud.clonedir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1685 | bb.utils.remove(ud.clonedir, recurse=True) |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1686 | bb.utils.remove(ud.clonedir.replace('gitsource', 'gitsubmodule'), recurse=True) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1687 | |
| 1688 | # confirm that the unpacked repo is used when no git clone or git |
| 1689 | # mirror tarball is available |
| 1690 | fetcher, ud = self.fetch_and_unpack(uri) |
| 1691 | if not disabled: |
| 1692 | assert os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is not shallow' % self.gitdir |
| 1693 | else: |
| 1694 | assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')), 'Unpacked git repository at %s is shallow' % self.gitdir |
| 1695 | return fetcher, ud |
| 1696 | |
| 1697 | def test_shallow_disabled(self): |
| 1698 | self.add_empty_file('a') |
| 1699 | self.add_empty_file('b') |
| 1700 | self.assertRevCount(2, cwd=self.srcdir) |
| 1701 | |
| 1702 | self.d.setVar('BB_GIT_SHALLOW', '0') |
| 1703 | self.fetch_shallow(disabled=True) |
| 1704 | self.assertRevCount(2) |
| 1705 | |
| 1706 | def test_shallow_nobranch(self): |
| 1707 | self.add_empty_file('a') |
| 1708 | self.add_empty_file('b') |
| 1709 | self.assertRevCount(2, cwd=self.srcdir) |
| 1710 | |
| 1711 | srcrev = self.git('rev-parse HEAD', cwd=self.srcdir).strip() |
| 1712 | self.d.setVar('SRCREV', srcrev) |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1713 | uri = self.d.getVar('SRC_URI').split()[0] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1714 | uri = '%s;nobranch=1;bare=1' % uri |
| 1715 | |
| 1716 | self.fetch_shallow(uri) |
| 1717 | self.assertRevCount(1) |
| 1718 | |
| 1719 | # shallow refs are used to ensure the srcrev sticks around when we |
| 1720 | # have no other branches referencing it |
| 1721 | self.assertRefs(['refs/shallow/default']) |
| 1722 | |
| 1723 | def test_shallow_default_depth_1(self): |
| 1724 | # Create initial git repo |
| 1725 | self.add_empty_file('a') |
| 1726 | self.add_empty_file('b') |
| 1727 | self.assertRevCount(2, cwd=self.srcdir) |
| 1728 | |
| 1729 | self.fetch_shallow() |
| 1730 | self.assertRevCount(1) |
| 1731 | |
| 1732 | def test_shallow_depth_0_disables(self): |
| 1733 | self.add_empty_file('a') |
| 1734 | self.add_empty_file('b') |
| 1735 | self.assertRevCount(2, cwd=self.srcdir) |
| 1736 | |
| 1737 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 1738 | self.fetch_shallow(disabled=True) |
| 1739 | self.assertRevCount(2) |
| 1740 | |
| 1741 | def test_shallow_depth_default_override(self): |
| 1742 | self.add_empty_file('a') |
| 1743 | self.add_empty_file('b') |
| 1744 | self.assertRevCount(2, cwd=self.srcdir) |
| 1745 | |
| 1746 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '2') |
| 1747 | self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '1') |
| 1748 | self.fetch_shallow() |
| 1749 | self.assertRevCount(1) |
| 1750 | |
| 1751 | def test_shallow_depth_default_override_disable(self): |
| 1752 | self.add_empty_file('a') |
| 1753 | self.add_empty_file('b') |
| 1754 | self.add_empty_file('c') |
| 1755 | self.assertRevCount(3, cwd=self.srcdir) |
| 1756 | |
| 1757 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 1758 | self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '2') |
| 1759 | self.fetch_shallow() |
| 1760 | self.assertRevCount(2) |
| 1761 | |
| 1762 | def test_current_shallow_out_of_date_clone(self): |
| 1763 | # Create initial git repo |
| 1764 | self.add_empty_file('a') |
| 1765 | self.add_empty_file('b') |
| 1766 | self.add_empty_file('c') |
| 1767 | self.assertRevCount(3, cwd=self.srcdir) |
| 1768 | |
| 1769 | # Clone and generate mirror tarball |
| 1770 | fetcher, ud = self.fetch() |
| 1771 | |
| 1772 | # Ensure we have a current mirror tarball, but an out of date clone |
| 1773 | self.git('update-ref refs/heads/master refs/heads/master~1', cwd=ud.clonedir) |
| 1774 | self.assertRevCount(2, cwd=ud.clonedir) |
| 1775 | |
| 1776 | # Fetch and unpack, from the current tarball, not the out of date clone |
| 1777 | bb.utils.remove(self.gitdir, recurse=True) |
| 1778 | fetcher, ud = self.fetch() |
| 1779 | fetcher.unpack(self.d.getVar('WORKDIR')) |
| 1780 | self.assertRevCount(1) |
| 1781 | |
| 1782 | def test_shallow_single_branch_no_merge(self): |
| 1783 | self.add_empty_file('a') |
| 1784 | self.add_empty_file('b') |
| 1785 | self.assertRevCount(2, cwd=self.srcdir) |
| 1786 | |
| 1787 | self.fetch_shallow() |
| 1788 | self.assertRevCount(1) |
| 1789 | assert os.path.exists(os.path.join(self.gitdir, 'a')) |
| 1790 | assert os.path.exists(os.path.join(self.gitdir, 'b')) |
| 1791 | |
| 1792 | def test_shallow_no_dangling(self): |
| 1793 | self.add_empty_file('a') |
| 1794 | self.add_empty_file('b') |
| 1795 | self.assertRevCount(2, cwd=self.srcdir) |
| 1796 | |
| 1797 | self.fetch_shallow() |
| 1798 | self.assertRevCount(1) |
| 1799 | assert not self.git('fsck --dangling') |
| 1800 | |
| 1801 | def test_shallow_srcrev_branch_truncation(self): |
| 1802 | self.add_empty_file('a') |
| 1803 | self.add_empty_file('b') |
| 1804 | b_commit = self.git('rev-parse HEAD', cwd=self.srcdir).rstrip() |
| 1805 | self.add_empty_file('c') |
| 1806 | self.assertRevCount(3, cwd=self.srcdir) |
| 1807 | |
| 1808 | self.d.setVar('SRCREV', b_commit) |
| 1809 | self.fetch_shallow() |
| 1810 | |
| 1811 | # The 'c' commit was removed entirely, and 'a' was removed from history |
| 1812 | self.assertRevCount(1, ['--all']) |
| 1813 | self.assertEqual(self.git('rev-parse HEAD').strip(), b_commit) |
| 1814 | assert os.path.exists(os.path.join(self.gitdir, 'a')) |
| 1815 | assert os.path.exists(os.path.join(self.gitdir, 'b')) |
| 1816 | assert not os.path.exists(os.path.join(self.gitdir, 'c')) |
| 1817 | |
| 1818 | def test_shallow_ref_pruning(self): |
| 1819 | self.add_empty_file('a') |
| 1820 | self.add_empty_file('b') |
| 1821 | self.git('branch a_branch', cwd=self.srcdir) |
| 1822 | self.assertRefs(['master', 'a_branch'], cwd=self.srcdir) |
| 1823 | self.assertRevCount(2, cwd=self.srcdir) |
| 1824 | |
| 1825 | self.fetch_shallow() |
| 1826 | |
| 1827 | self.assertRefs(['master', 'origin/master']) |
| 1828 | self.assertRevCount(1) |
| 1829 | |
| 1830 | def test_shallow_submodules(self): |
| 1831 | self.add_empty_file('a') |
| 1832 | self.add_empty_file('b') |
| 1833 | |
| 1834 | smdir = os.path.join(self.tempdir, 'gitsubmodule') |
| 1835 | bb.utils.mkdirhier(smdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1836 | self.git_init(cwd=smdir) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1837 | # Make this look like it was cloned from a remote... |
| 1838 | self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir) |
| 1839 | self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1840 | self.add_empty_file('asub', cwd=smdir) |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1841 | self.add_empty_file('bsub', cwd=smdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1842 | |
| 1843 | self.git('submodule init', cwd=self.srcdir) |
| 1844 | self.git('submodule add file://%s' % smdir, cwd=self.srcdir) |
| 1845 | self.git('submodule update', cwd=self.srcdir) |
| 1846 | self.git('commit -m submodule -a', cwd=self.srcdir) |
| 1847 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1848 | uri = 'gitsm://%s;protocol=file;subdir=${S};branch=master' % self.srcdir |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1849 | fetcher, ud = self.fetch_shallow(uri) |
| 1850 | |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1851 | # Verify the main repository is shallow |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1852 | self.assertRevCount(1) |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1853 | |
| 1854 | # Verify the gitsubmodule directory is present |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1855 | assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule')) |
| 1856 | |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1857 | # Verify the submodule is also shallow |
| 1858 | self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule')) |
| 1859 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1860 | def test_shallow_submodule_mirrors(self): |
| 1861 | self.add_empty_file('a') |
| 1862 | self.add_empty_file('b') |
| 1863 | |
| 1864 | smdir = os.path.join(self.tempdir, 'gitsubmodule') |
| 1865 | bb.utils.mkdirhier(smdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1866 | self.git_init(cwd=smdir) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1867 | # Make this look like it was cloned from a remote... |
| 1868 | self.git('config --add remote.origin.url "%s"' % smdir, cwd=smdir) |
| 1869 | self.git('config --add remote.origin.fetch "+refs/heads/*:refs/remotes/origin/*"', cwd=smdir) |
| 1870 | self.add_empty_file('asub', cwd=smdir) |
| 1871 | self.add_empty_file('bsub', cwd=smdir) |
| 1872 | |
| 1873 | self.git('submodule init', cwd=self.srcdir) |
| 1874 | self.git('submodule add file://%s' % smdir, cwd=self.srcdir) |
| 1875 | self.git('submodule update', cwd=self.srcdir) |
| 1876 | self.git('commit -m submodule -a', cwd=self.srcdir) |
| 1877 | |
| 1878 | uri = 'gitsm://%s;protocol=file;subdir=${S}' % self.srcdir |
| 1879 | |
| 1880 | # Fetch once to generate the shallow tarball |
| 1881 | fetcher, ud = self.fetch(uri) |
| 1882 | |
| 1883 | # Set up the mirror |
| 1884 | mirrordir = os.path.join(self.tempdir, 'mirror') |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1885 | bb.utils.rename(self.dldir, mirrordir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1886 | self.d.setVar('PREMIRRORS', 'gitsm://.*/.* file://%s/' % mirrordir) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 1887 | |
| 1888 | # Fetch from the mirror |
| 1889 | bb.utils.remove(self.dldir, recurse=True) |
| 1890 | bb.utils.remove(self.gitdir, recurse=True) |
| 1891 | self.fetch_and_unpack(uri) |
| 1892 | |
| 1893 | # Verify the main repository is shallow |
| 1894 | self.assertRevCount(1) |
| 1895 | |
| 1896 | # Verify the gitsubmodule directory is present |
| 1897 | assert os.listdir(os.path.join(self.gitdir, 'gitsubmodule')) |
| 1898 | |
| 1899 | # Verify the submodule is also shallow |
| 1900 | self.assertRevCount(1, cwd=os.path.join(self.gitdir, 'gitsubmodule')) |
Brad Bishop | f8caae3 | 2019-03-25 13:13:56 -0400 | [diff] [blame] | 1901 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1902 | if any(os.path.exists(os.path.join(p, 'git-annex')) for p in os.environ.get('PATH').split(':')): |
| 1903 | def test_shallow_annex(self): |
| 1904 | self.add_empty_file('a') |
| 1905 | self.add_empty_file('b') |
| 1906 | self.git('annex init', cwd=self.srcdir) |
| 1907 | open(os.path.join(self.srcdir, 'c'), 'w').close() |
| 1908 | self.git('annex add c', cwd=self.srcdir) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 1909 | self.git('commit --author "Foo Bar <foo@bar>" -m annex-c -a', cwd=self.srcdir) |
| 1910 | bb.process.run('chmod u+w -R %s' % self.srcdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1911 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 1912 | uri = 'gitannex://%s;protocol=file;subdir=${S};branch=master' % self.srcdir |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1913 | fetcher, ud = self.fetch_shallow(uri) |
| 1914 | |
| 1915 | self.assertRevCount(1) |
| 1916 | assert './.git/annex/' in bb.process.run('tar -tzf %s' % os.path.join(self.dldir, ud.mirrortarballs[0]))[0] |
| 1917 | assert os.path.exists(os.path.join(self.gitdir, 'c')) |
| 1918 | |
| 1919 | def test_shallow_multi_one_uri(self): |
| 1920 | # Create initial git repo |
| 1921 | self.add_empty_file('a') |
| 1922 | self.add_empty_file('b') |
| 1923 | self.git('checkout -b a_branch', cwd=self.srcdir) |
| 1924 | self.add_empty_file('c') |
| 1925 | self.add_empty_file('d') |
| 1926 | self.git('checkout master', cwd=self.srcdir) |
| 1927 | self.git('tag v0.0 a_branch', cwd=self.srcdir) |
| 1928 | self.add_empty_file('e') |
| 1929 | self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir) |
| 1930 | self.add_empty_file('f') |
| 1931 | self.assertRevCount(7, cwd=self.srcdir) |
| 1932 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1933 | uri = self.d.getVar('SRC_URI').split()[0] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1934 | uri = '%s;branch=master,a_branch;name=master,a_branch' % uri |
| 1935 | |
| 1936 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 1937 | self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0') |
| 1938 | self.d.setVar('SRCREV_master', '${AUTOREV}') |
| 1939 | self.d.setVar('SRCREV_a_branch', '${AUTOREV}') |
| 1940 | |
| 1941 | self.fetch_shallow(uri) |
| 1942 | |
| 1943 | self.assertRevCount(5) |
| 1944 | self.assertRefs(['master', 'origin/master', 'origin/a_branch']) |
| 1945 | |
| 1946 | def test_shallow_multi_one_uri_depths(self): |
| 1947 | # Create initial git repo |
| 1948 | self.add_empty_file('a') |
| 1949 | self.add_empty_file('b') |
| 1950 | self.git('checkout -b a_branch', cwd=self.srcdir) |
| 1951 | self.add_empty_file('c') |
| 1952 | self.add_empty_file('d') |
| 1953 | self.git('checkout master', cwd=self.srcdir) |
| 1954 | self.add_empty_file('e') |
| 1955 | self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir) |
| 1956 | self.add_empty_file('f') |
| 1957 | self.assertRevCount(7, cwd=self.srcdir) |
| 1958 | |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 1959 | uri = self.d.getVar('SRC_URI').split()[0] |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 1960 | uri = '%s;branch=master,a_branch;name=master,a_branch' % uri |
| 1961 | |
| 1962 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 1963 | self.d.setVar('BB_GIT_SHALLOW_DEPTH_master', '3') |
| 1964 | self.d.setVar('BB_GIT_SHALLOW_DEPTH_a_branch', '1') |
| 1965 | self.d.setVar('SRCREV_master', '${AUTOREV}') |
| 1966 | self.d.setVar('SRCREV_a_branch', '${AUTOREV}') |
| 1967 | |
| 1968 | self.fetch_shallow(uri) |
| 1969 | |
| 1970 | self.assertRevCount(4, ['--all']) |
| 1971 | self.assertRefs(['master', 'origin/master', 'origin/a_branch']) |
| 1972 | |
| 1973 | def test_shallow_clone_preferred_over_shallow(self): |
| 1974 | self.add_empty_file('a') |
| 1975 | self.add_empty_file('b') |
| 1976 | |
| 1977 | # Fetch once to generate the shallow tarball |
| 1978 | fetcher, ud = self.fetch() |
| 1979 | assert os.path.exists(os.path.join(self.dldir, ud.mirrortarballs[0])) |
| 1980 | |
| 1981 | # Fetch and unpack with both the clonedir and shallow tarball available |
| 1982 | bb.utils.remove(self.gitdir, recurse=True) |
| 1983 | fetcher, ud = self.fetch_and_unpack() |
| 1984 | |
| 1985 | # The unpacked tree should *not* be shallow |
| 1986 | self.assertRevCount(2) |
| 1987 | assert not os.path.exists(os.path.join(self.gitdir, '.git', 'shallow')) |
| 1988 | |
| 1989 | def test_shallow_mirrors(self): |
| 1990 | self.add_empty_file('a') |
| 1991 | self.add_empty_file('b') |
| 1992 | |
| 1993 | # Fetch once to generate the shallow tarball |
| 1994 | fetcher, ud = self.fetch() |
| 1995 | mirrortarball = ud.mirrortarballs[0] |
| 1996 | assert os.path.exists(os.path.join(self.dldir, mirrortarball)) |
| 1997 | |
| 1998 | # Set up the mirror |
| 1999 | mirrordir = os.path.join(self.tempdir, 'mirror') |
| 2000 | bb.utils.mkdirhier(mirrordir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2001 | self.d.setVar('PREMIRRORS', 'git://.*/.* file://%s/' % mirrordir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2002 | |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2003 | bb.utils.rename(os.path.join(self.dldir, mirrortarball), |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2004 | os.path.join(mirrordir, mirrortarball)) |
| 2005 | |
| 2006 | # Fetch from the mirror |
| 2007 | bb.utils.remove(self.dldir, recurse=True) |
| 2008 | bb.utils.remove(self.gitdir, recurse=True) |
| 2009 | self.fetch_and_unpack() |
| 2010 | self.assertRevCount(1) |
| 2011 | |
| 2012 | def test_shallow_invalid_depth(self): |
| 2013 | self.add_empty_file('a') |
| 2014 | self.add_empty_file('b') |
| 2015 | |
| 2016 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '-12') |
| 2017 | with self.assertRaises(bb.fetch2.FetchError): |
| 2018 | self.fetch() |
| 2019 | |
| 2020 | def test_shallow_invalid_depth_default(self): |
| 2021 | self.add_empty_file('a') |
| 2022 | self.add_empty_file('b') |
| 2023 | |
| 2024 | self.d.setVar('BB_GIT_SHALLOW_DEPTH_default', '-12') |
| 2025 | with self.assertRaises(bb.fetch2.FetchError): |
| 2026 | self.fetch() |
| 2027 | |
| 2028 | def test_shallow_extra_refs(self): |
| 2029 | self.add_empty_file('a') |
| 2030 | self.add_empty_file('b') |
| 2031 | self.git('branch a_branch', cwd=self.srcdir) |
| 2032 | self.assertRefs(['master', 'a_branch'], cwd=self.srcdir) |
| 2033 | self.assertRevCount(2, cwd=self.srcdir) |
| 2034 | |
| 2035 | self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/a_branch') |
| 2036 | self.fetch_shallow() |
| 2037 | |
| 2038 | self.assertRefs(['master', 'origin/master', 'origin/a_branch']) |
| 2039 | self.assertRevCount(1) |
| 2040 | |
| 2041 | def test_shallow_extra_refs_wildcard(self): |
| 2042 | self.add_empty_file('a') |
| 2043 | self.add_empty_file('b') |
| 2044 | self.git('branch a_branch', cwd=self.srcdir) |
| 2045 | self.git('tag v1.0', cwd=self.srcdir) |
| 2046 | self.assertRefs(['master', 'a_branch', 'v1.0'], cwd=self.srcdir) |
| 2047 | self.assertRevCount(2, cwd=self.srcdir) |
| 2048 | |
| 2049 | self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*') |
| 2050 | self.fetch_shallow() |
| 2051 | |
| 2052 | self.assertRefs(['master', 'origin/master', 'v1.0']) |
| 2053 | self.assertRevCount(1) |
| 2054 | |
| 2055 | def test_shallow_missing_extra_refs(self): |
| 2056 | self.add_empty_file('a') |
| 2057 | self.add_empty_file('b') |
| 2058 | |
| 2059 | self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/heads/foo') |
| 2060 | with self.assertRaises(bb.fetch2.FetchError): |
| 2061 | self.fetch() |
| 2062 | |
| 2063 | def test_shallow_missing_extra_refs_wildcard(self): |
| 2064 | self.add_empty_file('a') |
| 2065 | self.add_empty_file('b') |
| 2066 | |
| 2067 | self.d.setVar('BB_GIT_SHALLOW_EXTRA_REFS', 'refs/tags/*') |
| 2068 | self.fetch() |
| 2069 | |
| 2070 | def test_shallow_remove_revs(self): |
| 2071 | # Create initial git repo |
| 2072 | self.add_empty_file('a') |
| 2073 | self.add_empty_file('b') |
| 2074 | self.git('checkout -b a_branch', cwd=self.srcdir) |
| 2075 | self.add_empty_file('c') |
| 2076 | self.add_empty_file('d') |
| 2077 | self.git('checkout master', cwd=self.srcdir) |
| 2078 | self.git('tag v0.0 a_branch', cwd=self.srcdir) |
| 2079 | self.add_empty_file('e') |
| 2080 | self.git('merge --no-ff --no-edit a_branch', cwd=self.srcdir) |
| 2081 | self.git('branch -d a_branch', cwd=self.srcdir) |
| 2082 | self.add_empty_file('f') |
| 2083 | self.assertRevCount(7, cwd=self.srcdir) |
| 2084 | |
| 2085 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 2086 | self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0') |
| 2087 | |
| 2088 | self.fetch_shallow() |
| 2089 | |
| 2090 | self.assertRevCount(5) |
| 2091 | |
| 2092 | def test_shallow_invalid_revs(self): |
| 2093 | self.add_empty_file('a') |
| 2094 | self.add_empty_file('b') |
| 2095 | |
| 2096 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 2097 | self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0') |
| 2098 | |
| 2099 | with self.assertRaises(bb.fetch2.FetchError): |
| 2100 | self.fetch() |
| 2101 | |
Brad Bishop | 64c979e | 2019-11-04 13:55:29 -0500 | [diff] [blame] | 2102 | def test_shallow_fetch_missing_revs(self): |
| 2103 | self.add_empty_file('a') |
| 2104 | self.add_empty_file('b') |
| 2105 | fetcher, ud = self.fetch(self.d.getVar('SRC_URI')) |
| 2106 | self.git('tag v0.0 master', cwd=self.srcdir) |
| 2107 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 2108 | self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0') |
| 2109 | self.fetch_shallow() |
| 2110 | |
| 2111 | def test_shallow_fetch_missing_revs_fails(self): |
| 2112 | self.add_empty_file('a') |
| 2113 | self.add_empty_file('b') |
| 2114 | fetcher, ud = self.fetch(self.d.getVar('SRC_URI')) |
| 2115 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 2116 | self.d.setVar('BB_GIT_SHALLOW_REVS', 'v0.0') |
| 2117 | |
| 2118 | with self.assertRaises(bb.fetch2.FetchError), self.assertLogs("BitBake.Fetcher", level="ERROR") as cm: |
| 2119 | self.fetch_shallow() |
| 2120 | self.assertIn("Unable to find revision v0.0 even from upstream", cm.output[0]) |
| 2121 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2122 | @skipIfNoNetwork() |
| 2123 | def test_bitbake(self): |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2124 | self.git('remote add --mirror=fetch origin https://github.com/openembedded/bitbake', cwd=self.srcdir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 2125 | self.git('config core.bare true', cwd=self.srcdir) |
| 2126 | self.git('fetch', cwd=self.srcdir) |
| 2127 | |
| 2128 | self.d.setVar('BB_GIT_SHALLOW_DEPTH', '0') |
| 2129 | # Note that the 1.10.0 tag is annotated, so this also tests |
| 2130 | # reference of an annotated vs unannotated tag |
| 2131 | self.d.setVar('BB_GIT_SHALLOW_REVS', '1.10.0') |
| 2132 | |
| 2133 | self.fetch_shallow() |
| 2134 | |
| 2135 | # Confirm that the history of 1.10.0 was removed |
| 2136 | orig_revs = len(self.git('rev-list master', cwd=self.srcdir).splitlines()) |
| 2137 | revs = len(self.git('rev-list master').splitlines()) |
| 2138 | self.assertNotEqual(orig_revs, revs) |
| 2139 | self.assertRefs(['master', 'origin/master']) |
| 2140 | self.assertRevCount(orig_revs - 1758) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 2141 | |
| 2142 | def test_that_unpack_throws_an_error_when_the_git_clone_nor_shallow_tarball_exist(self): |
| 2143 | self.add_empty_file('a') |
| 2144 | fetcher, ud = self.fetch() |
| 2145 | bb.utils.remove(self.gitdir, recurse=True) |
| 2146 | bb.utils.remove(self.dldir, recurse=True) |
| 2147 | |
| 2148 | with self.assertRaises(bb.fetch2.UnpackError) as context: |
| 2149 | fetcher.unpack(self.d.getVar('WORKDIR')) |
| 2150 | |
| 2151 | self.assertIn("No up to date source found", context.exception.msg) |
| 2152 | self.assertIn("clone directory not available or not up to date", context.exception.msg) |
| 2153 | |
| 2154 | @skipIfNoNetwork() |
| 2155 | def test_that_unpack_does_work_when_using_git_shallow_tarball_but_tarball_is_not_available(self): |
| 2156 | self.d.setVar('SRCREV', 'e5939ff608b95cdd4d0ab0e1935781ab9a276ac0') |
| 2157 | self.d.setVar('BB_GIT_SHALLOW', '1') |
| 2158 | self.d.setVar('BB_GENERATE_SHALLOW_TARBALLS', '1') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2159 | fetcher = bb.fetch.Fetch(["git://git.yoctoproject.org/fstests;branch=master"], self.d) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 2160 | fetcher.download() |
| 2161 | |
| 2162 | bb.utils.remove(self.dldir + "/*.tar.gz") |
| 2163 | fetcher.unpack(self.unpackdir) |
| 2164 | |
| 2165 | dir = os.listdir(self.unpackdir + "/git/") |
| 2166 | self.assertIn("fstests.doap", dir) |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2167 | |
| 2168 | class GitLfsTest(FetcherTest): |
| 2169 | def setUp(self): |
| 2170 | FetcherTest.setUp(self) |
| 2171 | |
| 2172 | self.gitdir = os.path.join(self.tempdir, 'git') |
| 2173 | self.srcdir = os.path.join(self.tempdir, 'gitsource') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2174 | |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2175 | self.d.setVar('WORKDIR', self.tempdir) |
| 2176 | self.d.setVar('S', self.gitdir) |
| 2177 | self.d.delVar('PREMIRRORS') |
| 2178 | self.d.delVar('MIRRORS') |
| 2179 | |
| 2180 | self.d.setVar('SRCREV', '${AUTOREV}') |
| 2181 | self.d.setVar('AUTOREV', '${@bb.fetch2.get_autorev(d)}') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2182 | self.d.setVar("__BBSEENSRCREV", "1") |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2183 | |
| 2184 | bb.utils.mkdirhier(self.srcdir) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2185 | self.git_init(cwd=self.srcdir) |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2186 | with open(os.path.join(self.srcdir, '.gitattributes'), 'wt') as attrs: |
| 2187 | attrs.write('*.mp3 filter=lfs -text') |
| 2188 | self.git(['add', '.gitattributes'], cwd=self.srcdir) |
| 2189 | self.git(['commit', '-m', "attributes", '.gitattributes'], cwd=self.srcdir) |
| 2190 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2191 | def fetch(self, uri=None, download=True): |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2192 | uris = self.d.getVar('SRC_URI').split() |
| 2193 | uri = uris[0] |
| 2194 | d = self.d |
| 2195 | |
| 2196 | fetcher = bb.fetch2.Fetch(uris, d) |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2197 | if download: |
| 2198 | fetcher.download() |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2199 | ud = fetcher.ud[uri] |
| 2200 | return fetcher, ud |
| 2201 | |
| 2202 | def test_lfs_enabled(self): |
| 2203 | import shutil |
| 2204 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2205 | uri = 'git://%s;protocol=file;lfs=1;branch=master' % self.srcdir |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2206 | self.d.setVar('SRC_URI', uri) |
| 2207 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2208 | # Careful: suppress initial attempt at downloading until |
| 2209 | # we know whether git-lfs is installed. |
| 2210 | fetcher, ud = self.fetch(uri=None, download=False) |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2211 | self.assertIsNotNone(ud.method._find_git_lfs) |
| 2212 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2213 | # If git-lfs can be found, the unpack should be successful. Only |
| 2214 | # attempt this with the real live copy of git-lfs installed. |
| 2215 | if ud.method._find_git_lfs(self.d): |
| 2216 | fetcher.download() |
| 2217 | shutil.rmtree(self.gitdir, ignore_errors=True) |
| 2218 | fetcher.unpack(self.d.getVar('WORKDIR')) |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2219 | |
| 2220 | # If git-lfs cannot be found, the unpack should throw an error |
| 2221 | with self.assertRaises(bb.fetch2.FetchError): |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2222 | fetcher.download() |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2223 | ud.method._find_git_lfs = lambda d: False |
| 2224 | shutil.rmtree(self.gitdir, ignore_errors=True) |
| 2225 | fetcher.unpack(self.d.getVar('WORKDIR')) |
| 2226 | |
| 2227 | def test_lfs_disabled(self): |
| 2228 | import shutil |
| 2229 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2230 | uri = 'git://%s;protocol=file;lfs=0;branch=master' % self.srcdir |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2231 | self.d.setVar('SRC_URI', uri) |
| 2232 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2233 | # In contrast to test_lfs_enabled(), allow the implicit download |
| 2234 | # done by self.fetch() to occur here. The point of this test case |
| 2235 | # is to verify that the fetcher can survive even if the source |
| 2236 | # repository has Git LFS usage configured. |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2237 | fetcher, ud = self.fetch() |
| 2238 | self.assertIsNotNone(ud.method._find_git_lfs) |
| 2239 | |
Andrew Geissler | d1e8949 | 2021-02-12 15:35:20 -0600 | [diff] [blame] | 2240 | # If git-lfs can be found, the unpack should be successful. A |
| 2241 | # live copy of git-lfs is not required for this case, so |
| 2242 | # unconditionally forge its presence. |
Brad Bishop | 00e122a | 2019-10-05 11:10:57 -0400 | [diff] [blame] | 2243 | ud.method._find_git_lfs = lambda d: True |
| 2244 | shutil.rmtree(self.gitdir, ignore_errors=True) |
| 2245 | fetcher.unpack(self.d.getVar('WORKDIR')) |
| 2246 | |
| 2247 | # If git-lfs cannot be found, the unpack should be successful |
| 2248 | ud.method._find_git_lfs = lambda d: False |
| 2249 | shutil.rmtree(self.gitdir, ignore_errors=True) |
| 2250 | fetcher.unpack(self.d.getVar('WORKDIR')) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2251 | |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 2252 | class GitURLWithSpacesTest(FetcherTest): |
| 2253 | test_git_urls = { |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2254 | "git://tfs-example.org:22/tfs/example%20path/example.git;branch=master" : { |
| 2255 | 'url': 'git://tfs-example.org:22/tfs/example%20path/example.git;branch=master', |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 2256 | 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example.git', |
| 2257 | 'path': '/tfs/example path/example.git' |
| 2258 | }, |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2259 | "git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master" : { |
| 2260 | 'url': 'git://tfs-example.org:22/tfs/example%20path/example%20repo.git;branch=master', |
Andrew Geissler | c3d88e4 | 2020-10-02 09:45:00 -0500 | [diff] [blame] | 2261 | 'gitsrcname': 'tfs-example.org.22.tfs.example_path.example_repo.git', |
| 2262 | 'path': '/tfs/example path/example repo.git' |
| 2263 | } |
| 2264 | } |
| 2265 | |
| 2266 | def test_urls(self): |
| 2267 | |
| 2268 | # Set fake SRCREV to stop git fetcher from trying to contact non-existent git repo |
| 2269 | self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40') |
| 2270 | |
| 2271 | for test_git_url, ref in self.test_git_urls.items(): |
| 2272 | |
| 2273 | fetcher = bb.fetch.Fetch([test_git_url], self.d) |
| 2274 | ud = fetcher.ud[fetcher.urls[0]] |
| 2275 | |
| 2276 | self.assertEqual(ud.url, ref['url']) |
| 2277 | self.assertEqual(ud.path, ref['path']) |
| 2278 | self.assertEqual(ud.localfile, os.path.join(self.dldir, "git2", ref['gitsrcname'])) |
| 2279 | self.assertEqual(ud.localpath, os.path.join(self.dldir, "git2", ref['gitsrcname'])) |
| 2280 | self.assertEqual(ud.lockfile, os.path.join(self.dldir, "git2", ref['gitsrcname'] + '.lock')) |
| 2281 | self.assertEqual(ud.clonedir, os.path.join(self.dldir, "git2", ref['gitsrcname'])) |
| 2282 | self.assertEqual(ud.fullmirror, os.path.join(self.dldir, "git2_" + ref['gitsrcname'] + '.tar.gz')) |
| 2283 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2284 | class CrateTest(FetcherTest): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2285 | @skipIfNoNetwork() |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2286 | def test_crate_url(self): |
| 2287 | |
| 2288 | uri = "crate://crates.io/glob/0.2.11" |
| 2289 | self.d.setVar('SRC_URI', uri) |
| 2290 | |
| 2291 | uris = self.d.getVar('SRC_URI').split() |
| 2292 | d = self.d |
| 2293 | |
| 2294 | fetcher = bb.fetch2.Fetch(uris, self.d) |
| 2295 | fetcher.download() |
| 2296 | fetcher.unpack(self.tempdir) |
| 2297 | self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked']) |
| 2298 | self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done']) |
| 2299 | self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json")) |
| 2300 | self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs")) |
| 2301 | |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2302 | @skipIfNoNetwork() |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 2303 | def test_crate_url_multi(self): |
| 2304 | |
| 2305 | uri = "crate://crates.io/glob/0.2.11 crate://crates.io/time/0.1.35" |
| 2306 | self.d.setVar('SRC_URI', uri) |
| 2307 | |
| 2308 | uris = self.d.getVar('SRC_URI').split() |
| 2309 | d = self.d |
| 2310 | |
| 2311 | fetcher = bb.fetch2.Fetch(uris, self.d) |
| 2312 | fetcher.download() |
| 2313 | fetcher.unpack(self.tempdir) |
| 2314 | self.assertEqual(sorted(os.listdir(self.tempdir)), ['cargo_home', 'download' , 'unpacked']) |
| 2315 | self.assertEqual(sorted(os.listdir(self.tempdir + "/download")), ['glob-0.2.11.crate', 'glob-0.2.11.crate.done', 'time-0.1.35.crate', 'time-0.1.35.crate.done']) |
| 2316 | self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/.cargo-checksum.json")) |
| 2317 | self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/glob-0.2.11/src/lib.rs")) |
| 2318 | self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/.cargo-checksum.json")) |
| 2319 | self.assertTrue(os.path.exists(self.tempdir + "/cargo_home/bitbake/time-0.1.35/src/lib.rs")) |
| 2320 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2321 | class NPMTest(FetcherTest): |
| 2322 | def skipIfNoNpm(): |
| 2323 | import shutil |
| 2324 | if not shutil.which('npm'): |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2325 | return unittest.skip('npm not installed') |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2326 | return lambda f: f |
| 2327 | |
| 2328 | @skipIfNoNpm() |
| 2329 | @skipIfNoNetwork() |
| 2330 | def test_npm(self): |
| 2331 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2332 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2333 | ud = fetcher.ud[fetcher.urls[0]] |
| 2334 | fetcher.download() |
| 2335 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2336 | self.assertTrue(os.path.exists(ud.localpath + '.done')) |
| 2337 | self.assertTrue(os.path.exists(ud.resolvefile)) |
| 2338 | fetcher.unpack(self.unpackdir) |
| 2339 | unpackdir = os.path.join(self.unpackdir, 'npm') |
| 2340 | self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json'))) |
| 2341 | |
| 2342 | @skipIfNoNpm() |
| 2343 | @skipIfNoNetwork() |
| 2344 | def test_npm_bad_checksum(self): |
| 2345 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2346 | # Fetch once to get a tarball |
| 2347 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2348 | ud = fetcher.ud[fetcher.urls[0]] |
| 2349 | fetcher.download() |
| 2350 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2351 | # Modify the tarball |
| 2352 | bad = b'bad checksum' |
| 2353 | with open(ud.localpath, 'wb') as f: |
| 2354 | f.write(bad) |
| 2355 | # Verify that the tarball is fetched again |
| 2356 | fetcher.download() |
| 2357 | badsum = hashlib.sha512(bad).hexdigest() |
| 2358 | self.assertTrue(os.path.exists(ud.localpath + '_bad-checksum_' + badsum)) |
| 2359 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2360 | |
| 2361 | @skipIfNoNpm() |
| 2362 | @skipIfNoNetwork() |
| 2363 | def test_npm_premirrors(self): |
| 2364 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2365 | # Fetch once to get a tarball |
| 2366 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2367 | ud = fetcher.ud[fetcher.urls[0]] |
| 2368 | fetcher.download() |
| 2369 | self.assertTrue(os.path.exists(ud.localpath)) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2370 | |
| 2371 | # Setup the mirror by renaming the download directory |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2372 | mirrordir = os.path.join(self.tempdir, 'mirror') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2373 | bb.utils.rename(self.dldir, mirrordir) |
| 2374 | os.mkdir(self.dldir) |
| 2375 | |
| 2376 | # Configure the premirror to be used |
| 2377 | self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/npm2' % mirrordir) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2378 | self.d.setVar('BB_FETCH_PREMIRRORONLY', '1') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2379 | |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2380 | # Fetch again |
| 2381 | self.assertFalse(os.path.exists(ud.localpath)) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2382 | # The npm fetcher doesn't handle that the .resolved file disappears |
| 2383 | # while the fetcher object exists, which it does when we rename the |
| 2384 | # download directory to "mirror" above. Thus we need a new fetcher to go |
| 2385 | # with the now empty download directory. |
| 2386 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2387 | ud = fetcher.ud[fetcher.urls[0]] |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2388 | fetcher.download() |
| 2389 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2390 | |
| 2391 | @skipIfNoNpm() |
| 2392 | @skipIfNoNetwork() |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 2393 | def test_npm_premirrors_with_specified_filename(self): |
| 2394 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2395 | # Fetch once to get a tarball |
| 2396 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2397 | ud = fetcher.ud[fetcher.urls[0]] |
| 2398 | fetcher.download() |
| 2399 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2400 | # Setup the mirror |
| 2401 | mirrordir = os.path.join(self.tempdir, 'mirror') |
| 2402 | bb.utils.mkdirhier(mirrordir) |
| 2403 | mirrorfilename = os.path.join(mirrordir, os.path.basename(ud.localpath)) |
| 2404 | os.replace(ud.localpath, mirrorfilename) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2405 | self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s' % mirrorfilename) |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 2406 | self.d.setVar('BB_FETCH_PREMIRRORONLY', '1') |
| 2407 | # Fetch again |
| 2408 | self.assertFalse(os.path.exists(ud.localpath)) |
| 2409 | fetcher.download() |
| 2410 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2411 | |
| 2412 | @skipIfNoNpm() |
| 2413 | @skipIfNoNetwork() |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2414 | def test_npm_mirrors(self): |
| 2415 | # Fetch once to get a tarball |
| 2416 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2417 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2418 | ud = fetcher.ud[fetcher.urls[0]] |
| 2419 | fetcher.download() |
| 2420 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2421 | # Setup the mirror |
| 2422 | mirrordir = os.path.join(self.tempdir, 'mirror') |
| 2423 | bb.utils.mkdirhier(mirrordir) |
| 2424 | os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath))) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2425 | self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2426 | # Update the resolved url to an invalid url |
| 2427 | with open(ud.resolvefile, 'r') as f: |
| 2428 | url = f.read() |
| 2429 | uri = URI(url) |
| 2430 | uri.path = '/invalid' |
| 2431 | with open(ud.resolvefile, 'w') as f: |
| 2432 | f.write(str(uri)) |
| 2433 | # Fetch again |
| 2434 | self.assertFalse(os.path.exists(ud.localpath)) |
| 2435 | fetcher.download() |
| 2436 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2437 | |
| 2438 | @skipIfNoNpm() |
| 2439 | @skipIfNoNetwork() |
| 2440 | def test_npm_destsuffix_downloadfilename(self): |
| 2441 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0;destsuffix=foo/bar;downloadfilename=foo-bar.tgz' |
| 2442 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2443 | fetcher.download() |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2444 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'foo-bar.tgz'))) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2445 | fetcher.unpack(self.unpackdir) |
| 2446 | unpackdir = os.path.join(self.unpackdir, 'foo', 'bar') |
| 2447 | self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json'))) |
| 2448 | |
| 2449 | def test_npm_no_network_no_tarball(self): |
| 2450 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2451 | self.d.setVar('BB_NO_NETWORK', '1') |
| 2452 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2453 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 2454 | fetcher.download() |
| 2455 | |
| 2456 | @skipIfNoNpm() |
| 2457 | @skipIfNoNetwork() |
| 2458 | def test_npm_no_network_with_tarball(self): |
| 2459 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2460 | # Fetch once to get a tarball |
| 2461 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2462 | fetcher.download() |
| 2463 | # Disable network access |
| 2464 | self.d.setVar('BB_NO_NETWORK', '1') |
| 2465 | # Fetch again |
| 2466 | fetcher.download() |
| 2467 | fetcher.unpack(self.unpackdir) |
| 2468 | unpackdir = os.path.join(self.unpackdir, 'npm') |
| 2469 | self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json'))) |
| 2470 | |
| 2471 | @skipIfNoNpm() |
| 2472 | @skipIfNoNetwork() |
| 2473 | def test_npm_registry_alternate(self): |
Andrew Geissler | 5199d83 | 2021-09-24 16:47:35 -0500 | [diff] [blame] | 2474 | url = 'npm://skimdb.npmjs.com;package=@savoirfairelinux/node-server-example;version=1.0.0' |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2475 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2476 | fetcher.download() |
| 2477 | fetcher.unpack(self.unpackdir) |
| 2478 | unpackdir = os.path.join(self.unpackdir, 'npm') |
| 2479 | self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json'))) |
| 2480 | |
| 2481 | @skipIfNoNpm() |
| 2482 | @skipIfNoNetwork() |
| 2483 | def test_npm_version_latest(self): |
| 2484 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=latest' |
| 2485 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2486 | fetcher.download() |
| 2487 | fetcher.unpack(self.unpackdir) |
| 2488 | unpackdir = os.path.join(self.unpackdir, 'npm') |
| 2489 | self.assertTrue(os.path.exists(os.path.join(unpackdir, 'package.json'))) |
| 2490 | |
| 2491 | @skipIfNoNpm() |
| 2492 | @skipIfNoNetwork() |
| 2493 | def test_npm_registry_invalid(self): |
| 2494 | url = 'npm://registry.invalid.org;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2495 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2496 | with self.assertRaises(bb.fetch2.FetchError): |
| 2497 | fetcher.download() |
| 2498 | |
| 2499 | @skipIfNoNpm() |
| 2500 | @skipIfNoNetwork() |
| 2501 | def test_npm_package_invalid(self): |
| 2502 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/invalid;version=1.0.0' |
| 2503 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2504 | with self.assertRaises(bb.fetch2.FetchError): |
| 2505 | fetcher.download() |
| 2506 | |
| 2507 | @skipIfNoNpm() |
| 2508 | @skipIfNoNetwork() |
| 2509 | def test_npm_version_invalid(self): |
| 2510 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example;version=invalid' |
| 2511 | with self.assertRaises(bb.fetch2.ParameterError): |
| 2512 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2513 | |
| 2514 | @skipIfNoNpm() |
| 2515 | @skipIfNoNetwork() |
| 2516 | def test_npm_registry_none(self): |
| 2517 | url = 'npm://;package=@savoirfairelinux/node-server-example;version=1.0.0' |
| 2518 | with self.assertRaises(bb.fetch2.MalformedUrl): |
| 2519 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2520 | |
| 2521 | @skipIfNoNpm() |
| 2522 | @skipIfNoNetwork() |
| 2523 | def test_npm_package_none(self): |
| 2524 | url = 'npm://registry.npmjs.org;version=1.0.0' |
| 2525 | with self.assertRaises(bb.fetch2.MissingParameterError): |
| 2526 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2527 | |
| 2528 | @skipIfNoNpm() |
| 2529 | @skipIfNoNetwork() |
| 2530 | def test_npm_version_none(self): |
| 2531 | url = 'npm://registry.npmjs.org;package=@savoirfairelinux/node-server-example' |
| 2532 | with self.assertRaises(bb.fetch2.MissingParameterError): |
| 2533 | fetcher = bb.fetch.Fetch([url], self.d) |
| 2534 | |
| 2535 | def create_shrinkwrap_file(self, data): |
| 2536 | import json |
| 2537 | datadir = os.path.join(self.tempdir, 'data') |
| 2538 | swfile = os.path.join(datadir, 'npm-shrinkwrap.json') |
| 2539 | bb.utils.mkdirhier(datadir) |
| 2540 | with open(swfile, 'w') as f: |
| 2541 | json.dump(data, f) |
| 2542 | # Also configure the S directory |
| 2543 | self.sdir = os.path.join(self.unpackdir, 'S') |
| 2544 | self.d.setVar('S', self.sdir) |
| 2545 | return swfile |
| 2546 | |
| 2547 | @skipIfNoNpm() |
| 2548 | @skipIfNoNetwork() |
| 2549 | def test_npmsw(self): |
| 2550 | swfile = self.create_shrinkwrap_file({ |
| 2551 | 'dependencies': { |
| 2552 | 'array-flatten': { |
| 2553 | 'version': '1.1.1', |
| 2554 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2555 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=', |
| 2556 | 'dependencies': { |
| 2557 | 'content-type': { |
| 2558 | 'version': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz', |
| 2559 | 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==', |
| 2560 | 'dependencies': { |
| 2561 | 'cookie': { |
| 2562 | 'version': 'git+https://github.com/jshttp/cookie.git#aec1177c7da67e3b3273df96cf476824dbc9ae09', |
| 2563 | 'from': 'git+https://github.com/jshttp/cookie.git' |
| 2564 | } |
| 2565 | } |
| 2566 | } |
| 2567 | } |
| 2568 | } |
| 2569 | } |
| 2570 | }) |
| 2571 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2572 | fetcher.download() |
| 2573 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz'))) |
| 2574 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) |
| 2575 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'git2', 'github.com.jshttp.cookie.git'))) |
| 2576 | fetcher.unpack(self.unpackdir) |
| 2577 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'npm-shrinkwrap.json'))) |
| 2578 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json'))) |
| 2579 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'package.json'))) |
| 2580 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'node_modules', 'content-type', 'node_modules', 'cookie', 'package.json'))) |
| 2581 | |
| 2582 | @skipIfNoNpm() |
| 2583 | @skipIfNoNetwork() |
| 2584 | def test_npmsw_dev(self): |
| 2585 | swfile = self.create_shrinkwrap_file({ |
| 2586 | 'dependencies': { |
| 2587 | 'array-flatten': { |
| 2588 | 'version': '1.1.1', |
| 2589 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2590 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2591 | }, |
| 2592 | 'content-type': { |
| 2593 | 'version': '1.0.4', |
| 2594 | 'resolved': 'https://registry.npmjs.org/content-type/-/content-type-1.0.4.tgz', |
| 2595 | 'integrity': 'sha512-hIP3EEPs8tB9AT1L+NUqtwOAps4mk2Zob89MWXMHjHWg9milF/j4osnnQLXBCBFBk/tvIG/tUc9mOUJiPBhPXA==', |
| 2596 | 'dev': True |
| 2597 | } |
| 2598 | } |
| 2599 | }) |
| 2600 | # Fetch with dev disabled |
| 2601 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2602 | fetcher.download() |
| 2603 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz'))) |
| 2604 | self.assertFalse(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) |
| 2605 | # Fetch with dev enabled |
| 2606 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';dev=1'], self.d) |
| 2607 | fetcher.download() |
| 2608 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz'))) |
| 2609 | self.assertTrue(os.path.exists(os.path.join(self.dldir, 'npm2', 'content-type-1.0.4.tgz'))) |
| 2610 | |
| 2611 | @skipIfNoNpm() |
| 2612 | @skipIfNoNetwork() |
| 2613 | def test_npmsw_destsuffix(self): |
| 2614 | swfile = self.create_shrinkwrap_file({ |
| 2615 | 'dependencies': { |
| 2616 | 'array-flatten': { |
| 2617 | 'version': '1.1.1', |
| 2618 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2619 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2620 | } |
| 2621 | } |
| 2622 | }) |
| 2623 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile + ';destsuffix=foo/bar'], self.d) |
| 2624 | fetcher.download() |
| 2625 | fetcher.unpack(self.unpackdir) |
| 2626 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'foo', 'bar', 'node_modules', 'array-flatten', 'package.json'))) |
| 2627 | |
| 2628 | def test_npmsw_no_network_no_tarball(self): |
| 2629 | swfile = self.create_shrinkwrap_file({ |
| 2630 | 'dependencies': { |
| 2631 | 'array-flatten': { |
| 2632 | 'version': '1.1.1', |
| 2633 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2634 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2635 | } |
| 2636 | } |
| 2637 | }) |
| 2638 | self.d.setVar('BB_NO_NETWORK', '1') |
| 2639 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2640 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 2641 | fetcher.download() |
| 2642 | |
| 2643 | @skipIfNoNpm() |
| 2644 | @skipIfNoNetwork() |
| 2645 | def test_npmsw_no_network_with_tarball(self): |
| 2646 | # Fetch once to get a tarball |
| 2647 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) |
| 2648 | fetcher.download() |
| 2649 | # Disable network access |
| 2650 | self.d.setVar('BB_NO_NETWORK', '1') |
| 2651 | # Fetch again |
| 2652 | swfile = self.create_shrinkwrap_file({ |
| 2653 | 'dependencies': { |
| 2654 | 'array-flatten': { |
| 2655 | 'version': '1.1.1', |
| 2656 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2657 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2658 | } |
| 2659 | } |
| 2660 | }) |
| 2661 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2662 | fetcher.download() |
| 2663 | fetcher.unpack(self.unpackdir) |
| 2664 | self.assertTrue(os.path.exists(os.path.join(self.sdir, 'node_modules', 'array-flatten', 'package.json'))) |
| 2665 | |
| 2666 | @skipIfNoNpm() |
| 2667 | @skipIfNoNetwork() |
| 2668 | def test_npmsw_npm_reusability(self): |
| 2669 | # Fetch once with npmsw |
| 2670 | swfile = self.create_shrinkwrap_file({ |
| 2671 | 'dependencies': { |
| 2672 | 'array-flatten': { |
| 2673 | 'version': '1.1.1', |
| 2674 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2675 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2676 | } |
| 2677 | } |
| 2678 | }) |
| 2679 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2680 | fetcher.download() |
| 2681 | # Disable network access |
| 2682 | self.d.setVar('BB_NO_NETWORK', '1') |
| 2683 | # Fetch again with npm |
| 2684 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) |
| 2685 | fetcher.download() |
| 2686 | fetcher.unpack(self.unpackdir) |
| 2687 | self.assertTrue(os.path.exists(os.path.join(self.unpackdir, 'npm', 'package.json'))) |
| 2688 | |
| 2689 | @skipIfNoNpm() |
| 2690 | @skipIfNoNetwork() |
| 2691 | def test_npmsw_bad_checksum(self): |
| 2692 | # Try to fetch with bad checksum |
| 2693 | swfile = self.create_shrinkwrap_file({ |
| 2694 | 'dependencies': { |
| 2695 | 'array-flatten': { |
| 2696 | 'version': '1.1.1', |
| 2697 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2698 | 'integrity': 'sha1-gfNEp2hqgLTFKT6P3AsBYMgsBqg=' |
| 2699 | } |
| 2700 | } |
| 2701 | }) |
| 2702 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2703 | with self.assertRaises(bb.fetch2.FetchError): |
| 2704 | fetcher.download() |
| 2705 | # Fetch correctly to get a tarball |
| 2706 | swfile = self.create_shrinkwrap_file({ |
| 2707 | 'dependencies': { |
| 2708 | 'array-flatten': { |
| 2709 | 'version': '1.1.1', |
| 2710 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2711 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2712 | } |
| 2713 | } |
| 2714 | }) |
| 2715 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2716 | fetcher.download() |
| 2717 | localpath = os.path.join(self.dldir, 'npm2', 'array-flatten-1.1.1.tgz') |
| 2718 | self.assertTrue(os.path.exists(localpath)) |
| 2719 | # Modify the tarball |
| 2720 | bad = b'bad checksum' |
| 2721 | with open(localpath, 'wb') as f: |
| 2722 | f.write(bad) |
| 2723 | # Verify that the tarball is fetched again |
| 2724 | fetcher.download() |
| 2725 | badsum = hashlib.sha1(bad).hexdigest() |
| 2726 | self.assertTrue(os.path.exists(localpath + '_bad-checksum_' + badsum)) |
| 2727 | self.assertTrue(os.path.exists(localpath)) |
| 2728 | |
| 2729 | @skipIfNoNpm() |
| 2730 | @skipIfNoNetwork() |
| 2731 | def test_npmsw_premirrors(self): |
| 2732 | # Fetch once to get a tarball |
| 2733 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) |
| 2734 | ud = fetcher.ud[fetcher.urls[0]] |
| 2735 | fetcher.download() |
| 2736 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2737 | # Setup the mirror |
| 2738 | mirrordir = os.path.join(self.tempdir, 'mirror') |
| 2739 | bb.utils.mkdirhier(mirrordir) |
| 2740 | os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath))) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2741 | self.d.setVar('PREMIRRORS', 'https?$://.*/.* file://%s/' % mirrordir) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2742 | self.d.setVar('BB_FETCH_PREMIRRORONLY', '1') |
| 2743 | # Fetch again |
| 2744 | self.assertFalse(os.path.exists(ud.localpath)) |
| 2745 | swfile = self.create_shrinkwrap_file({ |
| 2746 | 'dependencies': { |
| 2747 | 'array-flatten': { |
| 2748 | 'version': '1.1.1', |
| 2749 | 'resolved': 'https://registry.npmjs.org/array-flatten/-/array-flatten-1.1.1.tgz', |
| 2750 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2751 | } |
| 2752 | } |
| 2753 | }) |
| 2754 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2755 | fetcher.download() |
| 2756 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2757 | |
| 2758 | @skipIfNoNpm() |
| 2759 | @skipIfNoNetwork() |
| 2760 | def test_npmsw_mirrors(self): |
| 2761 | # Fetch once to get a tarball |
| 2762 | fetcher = bb.fetch.Fetch(['npm://registry.npmjs.org;package=array-flatten;version=1.1.1'], self.d) |
| 2763 | ud = fetcher.ud[fetcher.urls[0]] |
| 2764 | fetcher.download() |
| 2765 | self.assertTrue(os.path.exists(ud.localpath)) |
| 2766 | # Setup the mirror |
| 2767 | mirrordir = os.path.join(self.tempdir, 'mirror') |
| 2768 | bb.utils.mkdirhier(mirrordir) |
| 2769 | os.replace(ud.localpath, os.path.join(mirrordir, os.path.basename(ud.localpath))) |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2770 | self.d.setVar('MIRRORS', 'https?$://.*/.* file://%s/' % mirrordir) |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 2771 | # Fetch again with invalid url |
| 2772 | self.assertFalse(os.path.exists(ud.localpath)) |
| 2773 | swfile = self.create_shrinkwrap_file({ |
| 2774 | 'dependencies': { |
| 2775 | 'array-flatten': { |
| 2776 | 'version': '1.1.1', |
| 2777 | 'resolved': 'https://invalid', |
| 2778 | 'integrity': 'sha1-ml9pkFGx5wczKPKgCJaLZOopVdI=' |
| 2779 | } |
| 2780 | } |
| 2781 | }) |
| 2782 | fetcher = bb.fetch.Fetch(['npmsw://' + swfile], self.d) |
| 2783 | fetcher.download() |
| 2784 | self.assertTrue(os.path.exists(ud.localpath)) |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2785 | |
| 2786 | class GitSharedTest(FetcherTest): |
| 2787 | def setUp(self): |
| 2788 | super(GitSharedTest, self).setUp() |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2789 | self.recipe_url = "git://git.openembedded.org/bitbake;branch=master" |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2790 | self.d.setVar('SRCREV', '82ea737a0b42a8b53e11c9cde141e9e9c0bd8c40') |
Andrew Geissler | 7e0e3c0 | 2022-02-25 20:34:39 +0000 | [diff] [blame] | 2791 | self.d.setVar("__BBSEENSRCREV", "1") |
Andrew Geissler | c926e17 | 2021-05-07 16:11:35 -0500 | [diff] [blame] | 2792 | |
| 2793 | @skipIfNoNetwork() |
| 2794 | def test_shared_unpack(self): |
| 2795 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2796 | |
| 2797 | fetcher.download() |
| 2798 | fetcher.unpack(self.unpackdir) |
| 2799 | alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates') |
| 2800 | self.assertTrue(os.path.exists(alt)) |
| 2801 | |
| 2802 | @skipIfNoNetwork() |
| 2803 | def test_noshared_unpack(self): |
| 2804 | self.d.setVar('BB_GIT_NOSHARED', '1') |
| 2805 | self.unpackdir += '_noshared' |
| 2806 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2807 | |
| 2808 | fetcher.download() |
| 2809 | fetcher.unpack(self.unpackdir) |
| 2810 | alt = os.path.join(self.unpackdir, 'git/.git/objects/info/alternates') |
| 2811 | self.assertFalse(os.path.exists(alt)) |
Andrew Geissler | 78b7279 | 2022-06-14 06:47:25 -0500 | [diff] [blame] | 2812 | |
| 2813 | |
| 2814 | class FetchPremirroronlyLocalTest(FetcherTest): |
| 2815 | |
| 2816 | def setUp(self): |
| 2817 | super(FetchPremirroronlyLocalTest, self).setUp() |
| 2818 | self.mirrordir = os.path.join(self.tempdir, "mirrors") |
| 2819 | os.mkdir(self.mirrordir) |
| 2820 | self.reponame = "bitbake" |
| 2821 | self.gitdir = os.path.join(self.tempdir, "git", self.reponame) |
| 2822 | self.recipe_url = "git://git.fake.repo/bitbake" |
| 2823 | self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") |
| 2824 | self.d.setVar("BB_NO_NETWORK", "1") |
| 2825 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") |
| 2826 | |
| 2827 | def make_git_repo(self): |
| 2828 | self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz" |
| 2829 | recipeurl = "git:/git.fake.repo/bitbake" |
| 2830 | os.makedirs(self.gitdir) |
| 2831 | self.git("init", self.gitdir) |
| 2832 | for i in range(0): |
| 2833 | self.git_new_commit() |
| 2834 | bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir) |
| 2835 | |
| 2836 | def git_new_commit(self): |
| 2837 | import random |
| 2838 | testfilename = "bibake-fetch.test" |
| 2839 | os.unlink(os.path.join(self.mirrordir, self.mirrorname)) |
| 2840 | with open(os.path.join(self.gitdir, testfilename), "w") as testfile: |
| 2841 | testfile.write("Useless random data {}".format(random.random())) |
| 2842 | self.git("add {}".format(testfilename), self.gitdir) |
| 2843 | self.git("commit -a -m \"This random commit {}. I'm useless.\"".format(random.random()), self.gitdir) |
| 2844 | bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir) |
| 2845 | return self.git("rev-parse HEAD", self.gitdir).strip() |
| 2846 | |
| 2847 | def test_mirror_commit_nonexistent(self): |
| 2848 | self.make_git_repo() |
| 2849 | self.d.setVar("SRCREV", "0"*40) |
| 2850 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2851 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 2852 | fetcher.download() |
| 2853 | |
| 2854 | def test_mirror_commit_exists(self): |
| 2855 | self.make_git_repo() |
| 2856 | self.d.setVar("SRCREV", self.git_new_commit()) |
| 2857 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2858 | fetcher.download() |
| 2859 | fetcher.unpack(self.unpackdir) |
| 2860 | |
| 2861 | def test_mirror_tarball_nonexistent(self): |
| 2862 | self.d.setVar("SRCREV", "0"*40) |
| 2863 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2864 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 2865 | fetcher.download() |
| 2866 | |
| 2867 | class FetchPremirroronlyNetworkTest(FetcherTest): |
| 2868 | |
| 2869 | def setUp(self): |
| 2870 | super(FetchPremirroronlyNetworkTest, self).setUp() |
| 2871 | self.mirrordir = os.path.join(self.tempdir, "mirrors") |
| 2872 | os.mkdir(self.mirrordir) |
| 2873 | self.reponame = "fstests" |
| 2874 | self.clonedir = os.path.join(self.tempdir, "git") |
| 2875 | self.gitdir = os.path.join(self.tempdir, "git", "{}.git".format(self.reponame)) |
| 2876 | self.recipe_url = "git://git.yoctoproject.org/fstests" |
| 2877 | self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") |
| 2878 | self.d.setVar("BB_NO_NETWORK", "0") |
| 2879 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") |
| 2880 | |
| 2881 | def make_git_repo(self): |
| 2882 | import shutil |
| 2883 | self.mirrorname = "git2_git.yoctoproject.org.fstests.tar.gz" |
| 2884 | os.makedirs(self.clonedir) |
| 2885 | self.git("clone --bare --shallow-since=\"01.01.2013\" {}".format(self.recipe_url), self.clonedir) |
| 2886 | bb.process.run('tar -czvf {} .'.format(os.path.join(self.mirrordir, self.mirrorname)), cwd = self.gitdir) |
| 2887 | shutil.rmtree(self.clonedir) |
| 2888 | |
| 2889 | @skipIfNoNetwork() |
| 2890 | def test_mirror_tarball_updated(self): |
| 2891 | self.make_git_repo() |
| 2892 | ## Upstream commit is in the mirror |
| 2893 | self.d.setVar("SRCREV", "49d65d53c2bf558ae6e9185af0f3af7b79d255ec") |
| 2894 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2895 | fetcher.download() |
| 2896 | |
| 2897 | @skipIfNoNetwork() |
| 2898 | def test_mirror_tarball_outdated(self): |
| 2899 | self.make_git_repo() |
| 2900 | ## Upstream commit not in the mirror |
| 2901 | self.d.setVar("SRCREV", "15413486df1f5a5b5af699b6f3ba5f0984e52a9f") |
| 2902 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2903 | with self.assertRaises(bb.fetch2.NetworkAccess): |
| 2904 | fetcher.download() |
Andrew Geissler | 615f2f1 | 2022-07-15 14:00:58 -0500 | [diff] [blame] | 2905 | |
| 2906 | class FetchPremirroronlyBrokenTarball(FetcherTest): |
| 2907 | |
| 2908 | def setUp(self): |
| 2909 | super(FetchPremirroronlyBrokenTarball, self).setUp() |
| 2910 | self.mirrordir = os.path.join(self.tempdir, "mirrors") |
| 2911 | os.mkdir(self.mirrordir) |
| 2912 | self.reponame = "bitbake" |
| 2913 | self.gitdir = os.path.join(self.tempdir, "git", self.reponame) |
| 2914 | self.recipe_url = "git://git.fake.repo/bitbake" |
| 2915 | self.d.setVar("BB_FETCH_PREMIRRORONLY", "1") |
| 2916 | self.d.setVar("BB_NO_NETWORK", "1") |
| 2917 | self.d.setVar("PREMIRRORS", self.recipe_url + " " + "file://{}".format(self.mirrordir) + " \n") |
| 2918 | self.mirrorname = "git2_git.fake.repo.bitbake.tar.gz" |
| 2919 | with open(os.path.join(self.mirrordir, self.mirrorname), 'w') as targz: |
| 2920 | targz.write("This is not tar.gz file!") |
| 2921 | |
| 2922 | def test_mirror_broken_download(self): |
| 2923 | import sys |
| 2924 | self.d.setVar("SRCREV", "0"*40) |
| 2925 | fetcher = bb.fetch.Fetch([self.recipe_url], self.d) |
| 2926 | with self.assertRaises(bb.fetch2.FetchError): |
| 2927 | fetcher.download() |
| 2928 | stdout = sys.stdout.getvalue() |
| 2929 | self.assertFalse(" not a git repository (or any parent up to mount point /)" in stdout) |