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