diff options
author | Yoann Congal <yoann.congal@smile.fr> | 2025-03-15 00:52:13 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-03-18 11:03:17 +0000 |
commit | e4761312f77e3ea23588a3c211f5e44cbd7cac15 (patch) | |
tree | 158a86a6fcf9173db4991850e4dbc5bab80a984f /bitbake/lib | |
parent | 8180865c22000adc5114a062dbe67f4b02ea06d5 (diff) | |
download | poky-e4761312f77e3ea23588a3c211f5e44cbd7cac15.tar.gz |
bitbake: tinfoil: Refactor temporary data tracking in a context manager
A new context manager Tinfoil._data_tracked_if_enabled() is introduced to
replace the following structure:
if self.tracking:
self.run_command('enableDataTracking')
# Code that need data tracking
if self.tracking:
self.run_command('disableDataTracking')
(Bitbake rev: 0fea4555d2143c6b23a79d3d5cf791103a68141b)
Signed-off-by: Yoann Congal <yoann.congal@smile.fr>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'bitbake/lib')
-rw-r--r-- | bitbake/lib/bb/tinfoil.py | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/bitbake/lib/bb/tinfoil.py b/bitbake/lib/bb/tinfoil.py index 13b05cec2d..60359a1a38 100644 --- a/bitbake/lib/bb/tinfoil.py +++ b/bitbake/lib/bb/tinfoil.py | |||
@@ -15,6 +15,7 @@ import atexit | |||
15 | import re | 15 | import re |
16 | from collections import OrderedDict, defaultdict | 16 | from collections import OrderedDict, defaultdict |
17 | from functools import partial | 17 | from functools import partial |
18 | from contextlib import contextmanager | ||
18 | 19 | ||
19 | import bb.cache | 20 | import bb.cache |
20 | import bb.cooker | 21 | import bb.cooker |
@@ -641,6 +642,22 @@ class Tinfoil: | |||
641 | fn = self.get_recipe_file(pn) | 642 | fn = self.get_recipe_file(pn) |
642 | return self.parse_recipe_file(fn) | 643 | return self.parse_recipe_file(fn) |
643 | 644 | ||
645 | @contextmanager | ||
646 | def _data_tracked_if_enabled(self): | ||
647 | """ | ||
648 | A context manager to enable data tracking for a code segment if data | ||
649 | tracking was enabled for this tinfoil instance. | ||
650 | """ | ||
651 | if self.tracking: | ||
652 | # Enable history tracking just for the operation | ||
653 | self.run_command('enableDataTracking') | ||
654 | |||
655 | # Here goes the operation with the optional data tracking | ||
656 | yield | ||
657 | |||
658 | if self.tracking: | ||
659 | self.run_command('disableDataTracking') | ||
660 | |||
644 | def finalizeData(self): | 661 | def finalizeData(self): |
645 | """ | 662 | """ |
646 | Run anonymous functions and expand keys | 663 | Run anonymous functions and expand keys |
@@ -659,10 +676,7 @@ class Tinfoil: | |||
659 | appendlist: optional list of bbappend files to apply, if you | 676 | appendlist: optional list of bbappend files to apply, if you |
660 | want to filter them | 677 | want to filter them |
661 | """ | 678 | """ |
662 | if self.tracking: | 679 | with self._data_tracked_if_enabled(): |
663 | # Enable history tracking just for the parse operation | ||
664 | self.run_command('enableDataTracking') | ||
665 | try: | ||
666 | if appends and appendlist == []: | 680 | if appends and appendlist == []: |
667 | appends = False | 681 | appends = False |
668 | if config_data: | 682 | if config_data: |
@@ -674,9 +688,6 @@ class Tinfoil: | |||
674 | return self._reconvert_type(dscon, 'DataStoreConnectionHandle') | 688 | return self._reconvert_type(dscon, 'DataStoreConnectionHandle') |
675 | else: | 689 | else: |
676 | return None | 690 | return None |
677 | finally: | ||
678 | if self.tracking: | ||
679 | self.run_command('disableDataTracking') | ||
680 | 691 | ||
681 | def build_file(self, buildfile, task, internal=True): | 692 | def build_file(self, buildfile, task, internal=True): |
682 | """ | 693 | """ |