summaryrefslogtreecommitdiffstats
path: root/bitbake/lib/bb/tests
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-12-11 15:32:56 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-14 23:16:17 +0000
commit347347ad78c4c2502e83f2c2adff61f1ba8fed8b (patch)
tree47184afe89bd613d7d8aac86527abb003c3f53dd /bitbake/lib/bb/tests
parent5935783f216cfa20826a7ac64b0d78e9693e0e21 (diff)
downloadpoky-347347ad78c4c2502e83f2c2adff61f1ba8fed8b.tar.gz
bitbake: lib/bb/utils: improve edit_bblayers_conf() handling of bblayers.conf formatting
Make the following improvements to edit_bblayers_conf(): * Support ~ in BBLAYERS entries * Handle where BBLAYERS items are added over multiple lines with += instead of one single long item Also add some comments documenting the function arguments and return values as well as a set of bitbake-selftest tests. (This function is used by the bitbake-layers add, remove and layerindex-fetch subcommands, as well as devtool when adding the workspace layer). (Bitbake master rev: e9a0858023c7671e30cc8ebb08496304b7f26b31) (Bitbake rev: fca41cf073469493e9dada377fc42d4b084c45c9) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib/bb/tests')
-rw-r--r--bitbake/lib/bb/tests/utils.py203
1 files changed, 203 insertions, 0 deletions
diff --git a/bitbake/lib/bb/tests/utils.py b/bitbake/lib/bb/tests/utils.py
index 9171509a62..a035ccf179 100644
--- a/bitbake/lib/bb/tests/utils.py
+++ b/bitbake/lib/bb/tests/utils.py
@@ -376,3 +376,206 @@ do_functionname() {
376 (updated, newlines) = bb.utils.edit_metadata(self._origfile.splitlines(True), varlist, handle_var) 376 (updated, newlines) = bb.utils.edit_metadata(self._origfile.splitlines(True), varlist, handle_var)
377 self.assertTrue(updated, 'List should be updated but isn\'t') 377 self.assertTrue(updated, 'List should be updated but isn\'t')
378 self.assertEqual(newlines, newfile5.splitlines(True)) 378 self.assertEqual(newlines, newfile5.splitlines(True))
379
380
381class EditBbLayersConf(unittest.TestCase):
382
383 def _test_bblayers_edit(self, before, after, add, remove, notadded, notremoved):
384 with tempfile.NamedTemporaryFile('w', delete=False) as tf:
385 tf.write(before)
386 tf.close()
387 try:
388 actual_notadded, actual_notremoved = bb.utils.edit_bblayers_conf(tf.name, add, remove)
389 with open(tf.name) as f:
390 actual_after = f.readlines()
391 self.assertEqual(after.splitlines(True), actual_after)
392 self.assertEqual(notadded, actual_notadded)
393 self.assertEqual(notremoved, actual_notremoved)
394 finally:
395 os.remove(tf.name)
396
397
398 def test_bblayers_remove(self):
399 before = r"""
400# A comment
401
402BBPATH = "${TOPDIR}"
403BBFILES ?= ""
404BBLAYERS = " \
405 /home/user/path/layer1 \
406 /home/user/path/layer2 \
407 /home/user/path/subpath/layer3 \
408 /home/user/path/layer4 \
409 "
410"""
411 after = r"""
412# A comment
413
414BBPATH = "${TOPDIR}"
415BBFILES ?= ""
416BBLAYERS = " \
417 /home/user/path/layer1 \
418 /home/user/path/subpath/layer3 \
419 /home/user/path/layer4 \
420 "
421"""
422 self._test_bblayers_edit(before, after,
423 None,
424 '/home/user/path/layer2',
425 [],
426 [])
427
428
429 def test_bblayers_add(self):
430 before = r"""
431# A comment
432
433BBPATH = "${TOPDIR}"
434BBFILES ?= ""
435BBLAYERS = " \
436 /home/user/path/layer1 \
437 /home/user/path/layer2 \
438 /home/user/path/subpath/layer3 \
439 /home/user/path/layer4 \
440 "
441"""
442 after = r"""
443# A comment
444
445BBPATH = "${TOPDIR}"
446BBFILES ?= ""
447BBLAYERS = " \
448 /home/user/path/layer1 \
449 /home/user/path/layer2 \
450 /home/user/path/subpath/layer3 \
451 /home/user/path/layer4 \
452 /other/path/to/layer5 \
453 "
454"""
455 self._test_bblayers_edit(before, after,
456 '/other/path/to/layer5/',
457 None,
458 [],
459 [])
460
461
462 def test_bblayers_add_remove(self):
463 before = r"""
464# A comment
465
466BBPATH = "${TOPDIR}"
467BBFILES ?= ""
468BBLAYERS = " \
469 /home/user/path/layer1 \
470 /home/user/path/layer2 \
471 /home/user/path/subpath/layer3 \
472 /home/user/path/layer4 \
473 "
474"""
475 after = r"""
476# A comment
477
478BBPATH = "${TOPDIR}"
479BBFILES ?= ""
480BBLAYERS = " \
481 /home/user/path/layer1 \
482 /home/user/path/layer2 \
483 /home/user/path/layer4 \
484 /other/path/to/layer5 \
485 "
486"""
487 self._test_bblayers_edit(before, after,
488 ['/other/path/to/layer5', '/home/user/path/layer2/'], '/home/user/path/subpath/layer3/',
489 ['/home/user/path/layer2'],
490 [])
491
492
493 def test_bblayers_add_remove_home(self):
494 before = r"""
495# A comment
496
497BBPATH = "${TOPDIR}"
498BBFILES ?= ""
499BBLAYERS = " \
500 ~/path/layer1 \
501 ~/path/layer2 \
502 ~/otherpath/layer3 \
503 ~/path/layer4 \
504 "
505"""
506 after = r"""
507# A comment
508
509BBPATH = "${TOPDIR}"
510BBFILES ?= ""
511BBLAYERS = " \
512 ~/path/layer2 \
513 ~/path/layer4 \
514 ~/path2/layer5 \
515 "
516"""
517 self._test_bblayers_edit(before, after,
518 [os.environ['HOME'] + '/path/layer4', '~/path2/layer5'],
519 [os.environ['HOME'] + '/otherpath/layer3', '~/path/layer1', '~/path/notinlist'],
520 [os.environ['HOME'] + '/path/layer4'],
521 ['~/path/notinlist'])
522
523
524 def test_bblayers_add_remove_plusequals(self):
525 before = r"""
526# A comment
527
528BBPATH = "${TOPDIR}"
529BBFILES ?= ""
530BBLAYERS += " \
531 /home/user/path/layer1 \
532 /home/user/path/layer2 \
533 "
534"""
535 after = r"""
536# A comment
537
538BBPATH = "${TOPDIR}"
539BBFILES ?= ""
540BBLAYERS += " \
541 /home/user/path/layer2 \
542 /home/user/path/layer3 \
543 "
544"""
545 self._test_bblayers_edit(before, after,
546 '/home/user/path/layer3',
547 '/home/user/path/layer1',
548 [],
549 [])
550
551
552 def test_bblayers_add_remove_plusequals2(self):
553 before = r"""
554# A comment
555
556BBPATH = "${TOPDIR}"
557BBFILES ?= ""
558BBLAYERS += " \
559 /home/user/path/layer1 \
560 /home/user/path/layer2 \
561 /home/user/path/layer3 \
562 "
563BBLAYERS += "/home/user/path/layer4"
564BBLAYERS += "/home/user/path/layer5"
565"""
566 after = r"""
567# A comment
568
569BBPATH = "${TOPDIR}"
570BBFILES ?= ""
571BBLAYERS += " \
572 /home/user/path/layer2 \
573 /home/user/path/layer3 \
574 "
575BBLAYERS += "/home/user/path/layer5"
576BBLAYERS += "/home/user/otherpath/layer6"
577"""
578 self._test_bblayers_edit(before, after,
579 ['/home/user/otherpath/layer6', '/home/user/path/layer3'], ['/home/user/path/layer1', '/home/user/path/layer4', '/home/user/path/layer7'],
580 ['/home/user/path/layer3'],
581 ['/home/user/path/layer7'])