diff options
| author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-11-20 17:11:16 +1300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-12-07 17:01:21 +0000 |
| commit | 4de214f7529c1d9600dd2c0723d33d7241b3e0c8 (patch) | |
| tree | cd16b5c216760c7992e11b60aee88665017a0096 /bitbake/lib/bb/tests/utils.py | |
| parent | 0debb11883379c746f91eb8a5262f22a669fd16b (diff) | |
| download | poky-4de214f7529c1d9600dd2c0723d33d7241b3e0c8.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 rev: e9a0858023c7671e30cc8ebb08496304b7f26b31)
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/utils.py')
| -rw-r--r-- | bitbake/lib/bb/tests/utils.py | 203 |
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 | |||
| 381 | class 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 | |||
| 402 | BBPATH = "${TOPDIR}" | ||
| 403 | BBFILES ?= "" | ||
| 404 | BBLAYERS = " \ | ||
| 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 | |||
| 414 | BBPATH = "${TOPDIR}" | ||
| 415 | BBFILES ?= "" | ||
| 416 | BBLAYERS = " \ | ||
| 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 | |||
| 433 | BBPATH = "${TOPDIR}" | ||
| 434 | BBFILES ?= "" | ||
| 435 | BBLAYERS = " \ | ||
| 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 | |||
| 445 | BBPATH = "${TOPDIR}" | ||
| 446 | BBFILES ?= "" | ||
| 447 | BBLAYERS = " \ | ||
| 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 | |||
| 466 | BBPATH = "${TOPDIR}" | ||
| 467 | BBFILES ?= "" | ||
| 468 | BBLAYERS = " \ | ||
| 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 | |||
| 478 | BBPATH = "${TOPDIR}" | ||
| 479 | BBFILES ?= "" | ||
| 480 | BBLAYERS = " \ | ||
| 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 | |||
| 497 | BBPATH = "${TOPDIR}" | ||
| 498 | BBFILES ?= "" | ||
| 499 | BBLAYERS = " \ | ||
| 500 | ~/path/layer1 \ | ||
| 501 | ~/path/layer2 \ | ||
| 502 | ~/otherpath/layer3 \ | ||
| 503 | ~/path/layer4 \ | ||
| 504 | " | ||
| 505 | """ | ||
| 506 | after = r""" | ||
| 507 | # A comment | ||
| 508 | |||
| 509 | BBPATH = "${TOPDIR}" | ||
| 510 | BBFILES ?= "" | ||
| 511 | BBLAYERS = " \ | ||
| 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 | |||
| 528 | BBPATH = "${TOPDIR}" | ||
| 529 | BBFILES ?= "" | ||
| 530 | BBLAYERS += " \ | ||
| 531 | /home/user/path/layer1 \ | ||
| 532 | /home/user/path/layer2 \ | ||
| 533 | " | ||
| 534 | """ | ||
| 535 | after = r""" | ||
| 536 | # A comment | ||
| 537 | |||
| 538 | BBPATH = "${TOPDIR}" | ||
| 539 | BBFILES ?= "" | ||
| 540 | BBLAYERS += " \ | ||
| 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 | |||
| 556 | BBPATH = "${TOPDIR}" | ||
| 557 | BBFILES ?= "" | ||
| 558 | BBLAYERS += " \ | ||
| 559 | /home/user/path/layer1 \ | ||
| 560 | /home/user/path/layer2 \ | ||
| 561 | /home/user/path/layer3 \ | ||
| 562 | " | ||
| 563 | BBLAYERS += "/home/user/path/layer4" | ||
| 564 | BBLAYERS += "/home/user/path/layer5" | ||
| 565 | """ | ||
| 566 | after = r""" | ||
| 567 | # A comment | ||
| 568 | |||
| 569 | BBPATH = "${TOPDIR}" | ||
| 570 | BBFILES ?= "" | ||
| 571 | BBLAYERS += " \ | ||
| 572 | /home/user/path/layer2 \ | ||
| 573 | /home/user/path/layer3 \ | ||
| 574 | " | ||
| 575 | BBLAYERS += "/home/user/path/layer5" | ||
| 576 | BBLAYERS += "/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']) | ||
