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