summaryrefslogtreecommitdiffstats
path: root/bitbake/lib
diff options
context:
space:
mode:
Diffstat (limited to 'bitbake/lib')
-rw-r--r--bitbake/lib/bb/fetch2/__init__.py61
-rw-r--r--bitbake/lib/bb/tests/fetch.py12
2 files changed, 28 insertions, 45 deletions
diff --git a/bitbake/lib/bb/fetch2/__init__.py b/bitbake/lib/bb/fetch2/__init__.py
index d36655071b..9ebdcdb91d 100644
--- a/bitbake/lib/bb/fetch2/__init__.py
+++ b/bitbake/lib/bb/fetch2/__init__.py
@@ -1318,6 +1318,11 @@ class FetchMethod(object):
1318 iterate = False 1318 iterate = False
1319 file = urldata.localpath 1319 file = urldata.localpath
1320 1320
1321 # Localpath can't deal with 'dir/*' entries, so it converts them to '.',
1322 # but it must be corrected back for local files copying
1323 if urldata.basename == '*' and file.endswith('/.'):
1324 file = '%s/%s' % (file.rstrip('/.'), urldata.path)
1325
1321 try: 1326 try:
1322 unpack = bb.utils.to_boolean(urldata.parm.get('unpack'), True) 1327 unpack = bb.utils.to_boolean(urldata.parm.get('unpack'), True)
1323 except ValueError as exc: 1328 except ValueError as exc:
@@ -1375,50 +1380,32 @@ class FetchMethod(object):
1375 elif file.endswith('.7z'): 1380 elif file.endswith('.7z'):
1376 cmd = '7za x -y %s 1>/dev/null' % file 1381 cmd = '7za x -y %s 1>/dev/null' % file
1377 1382
1383 # If 'subdir' param exists, create a dir and use it as destination for unpack cmd
1384 if 'subdir' in urldata.parm:
1385 unpackdir = '%s/%s' % (rootdir, urldata.parm.get('subdir'))
1386 bb.utils.mkdirhier(unpackdir)
1387 else:
1388 unpackdir = rootdir
1389
1378 if not unpack or not cmd: 1390 if not unpack or not cmd:
1379 # If file == dest, then avoid any copies, as we already put the file into dest! 1391 # If file == dest, then avoid any copies, as we already put the file into dest!
1380 dest = os.path.join(rootdir, os.path.basename(file)) 1392 dest = os.path.join(unpackdir, os.path.basename(file))
1381 if (file != dest) and not (os.path.exists(dest) and os.path.samefile(file, dest)): 1393 if file != dest and not (os.path.exists(dest) and os.path.samefile(file, dest)):
1382 if os.path.isdir(file): 1394 destdir = '.'
1383 # If for example we're asked to copy file://foo/bar, we need to unpack the result into foo/bar 1395 # For file:// entries all intermediate dirs in path must be created at destination
1384 basepath = getattr(urldata, "basepath", None) 1396 if urldata.type == "file":
1385 destdir = "." 1397 urlpath = urldata.path.rstrip('/') # Trailing '/' does a copying to wrong place
1386 if basepath and basepath.endswith("/"): 1398 if urlpath.find("/") != -1:
1387 basepath = basepath.rstrip("/") 1399 destdir = urlpath.rsplit("/", 1)[0] + '/'
1388 elif basepath: 1400 bb.utils.mkdirhier("%s/%s" % (unpackdir, destdir))
1389 basepath = os.path.dirname(basepath) 1401 cmd = 'cp -fpPR %s %s' % (file, destdir)
1390 if basepath and basepath.find("/") != -1:
1391 destdir = basepath[:basepath.rfind('/')]
1392 destdir = destdir.strip('/')
1393 if destdir != "." and not os.access("%s/%s" % (rootdir, destdir), os.F_OK):
1394 os.makedirs("%s/%s" % (rootdir, destdir))
1395 cmd = 'cp -fpPR %s %s/%s/' % (file, rootdir, destdir)
1396 #cmd = 'tar -cf - -C "%d" -ps . | tar -xf - -C "%s/%s/"' % (file, rootdir, destdir)
1397 else:
1398 # The "destdir" handling was specifically done for FILESPATH
1399 # items. So, only do so for file:// entries.
1400 if urldata.type == "file" and urldata.path.find("/") != -1:
1401 destdir = urldata.path.rsplit("/", 1)[0]
1402 if urldata.parm.get('subdir') != None:
1403 destdir = urldata.parm.get('subdir') + "/" + destdir
1404 else:
1405 if urldata.parm.get('subdir') != None:
1406 destdir = urldata.parm.get('subdir')
1407 else:
1408 destdir = "."
1409 bb.utils.mkdirhier("%s/%s" % (rootdir, destdir))
1410 cmd = 'cp -f %s %s/%s/' % (file, rootdir, destdir)
1411 1402
1412 if not cmd: 1403 if not cmd:
1413 return 1404 return
1414 1405
1415 # Change to subdir before executing command 1406 # Change to unpackdir before executing command
1416 save_cwd = os.getcwd(); 1407 save_cwd = os.getcwd();
1417 os.chdir(rootdir) 1408 os.chdir(unpackdir)
1418 if 'subdir' in urldata.parm:
1419 newdir = ("%s/%s" % (rootdir, urldata.parm.get('subdir')))
1420 bb.utils.mkdirhier(newdir)
1421 os.chdir(newdir)
1422 1409
1423 path = data.getVar('PATH', True) 1410 path = data.getVar('PATH', True)
1424 if path: 1411 if path:
diff --git a/bitbake/lib/bb/tests/fetch.py b/bitbake/lib/bb/tests/fetch.py
index d8a36836d6..f6b11d51ea 100644
--- a/bitbake/lib/bb/tests/fetch.py
+++ b/bitbake/lib/bb/tests/fetch.py
@@ -482,9 +482,7 @@ class FetcherLocalTest(FetcherTest):
482 482
483 def test_local_wildcard(self): 483 def test_local_wildcard(self):
484 tree = self.fetchUnpack(['file://a', 'file://dir/*']) 484 tree = self.fetchUnpack(['file://a', 'file://dir/*'])
485 # FIXME: this is broken - it should return ['a', 'dir/c', 'dir/d', 'dir/subdir/e'] 485 self.assertEqual(tree, ['a', 'dir/c', 'dir/d', 'dir/subdir/e'])
486 # see https://bugzilla.yoctoproject.org/show_bug.cgi?id=6128
487 self.assertEqual(tree, ['a', 'b', 'dir/c', 'dir/d', 'dir/subdir/e'])
488 486
489 def test_local_dir(self): 487 def test_local_dir(self):
490 tree = self.fetchUnpack(['file://a', 'file://dir']) 488 tree = self.fetchUnpack(['file://a', 'file://dir'])
@@ -492,17 +490,15 @@ class FetcherLocalTest(FetcherTest):
492 490
493 def test_local_subdir(self): 491 def test_local_subdir(self):
494 tree = self.fetchUnpack(['file://dir/subdir']) 492 tree = self.fetchUnpack(['file://dir/subdir'])
495 # FIXME: this is broken - it should return ['dir/subdir/e'] 493 self.assertEqual(tree, ['dir/subdir/e'])
496 # see https://bugzilla.yoctoproject.org/show_bug.cgi?id=6129
497 self.assertEqual(tree, ['subdir/e'])
498 494
499 def test_local_subdir_file(self): 495 def test_local_subdir_file(self):
500 tree = self.fetchUnpack(['file://dir/subdir/e']) 496 tree = self.fetchUnpack(['file://dir/subdir/e'])
501 self.assertEqual(tree, ['dir/subdir/e']) 497 self.assertEqual(tree, ['dir/subdir/e'])
502 498
503 def test_local_subdirparam(self): 499 def test_local_subdirparam(self):
504 tree = self.fetchUnpack(['file://a;subdir=bar']) 500 tree = self.fetchUnpack(['file://a;subdir=bar', 'file://dir;subdir=foo/moo'])
505 self.assertEqual(tree, ['bar/a']) 501 self.assertEqual(tree, ['bar/a', 'foo/moo/dir/c', 'foo/moo/dir/d', 'foo/moo/dir/subdir/e'])
506 502
507 def test_local_deepsubdirparam(self): 503 def test_local_deepsubdirparam(self):
508 tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar']) 504 tree = self.fetchUnpack(['file://dir/subdir/e;subdir=bar'])