[2/2] cooker: Restore sys.path and sys.modules between parses

Message ID 20220331110437.1562951-2-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 951942c3c284ec2c62e730e145688033190af9b2
Headers show
Series [1/2] cooker: Further fixes to inotify to fix memres bitbake issues | expand

Commit Message

Richard Purdie March 31, 2022, 11:04 a.m. UTC
When memory resident bitbake is active and we re-parse, the old module
configuration is present which can lead to strange errors. Reset this
when reparsing so the state is consistent. This fixes memory resident
bitbake errors.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/cooker.py | 6 ++++++
 1 file changed, 6 insertions(+)

Comments

Christopher Larson March 31, 2022, 3:34 p.m. UTC | #1
On Thu, Mar 31, 2022 at 4:04 AM Richard Purdie <
richard.purdie@linuxfoundation.org> wrote:

> When memory resident bitbake is active and we re-parse, the old module
> configuration is present which can lead to strange errors. Reset this
> when reparsing so the state is consistent. This fixes memory resident
> bitbake errors.
>
> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
>

Looks good!

Acked-by: Christopher Larson <chris_larson@mentor.com>

Patch

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 1359d33f77..4753fd16e2 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -159,6 +159,9 @@  class BBCooker:
             for f in featureSet:
                 self.featureset.setFeature(f)
 
+        self.orig_syspath = sys.path.copy()
+        self.orig_sysmodules = sys.modules.copy()
+
         self.configuration = bb.cookerdata.CookerConfiguration()
 
         self.idleCallBackRegister = idleCallBackRegister
@@ -350,6 +353,9 @@  class BBCooker:
         self.state = state.initial
         self.caches_array = []
 
+        sys.path = self.orig_syspath.copy()
+        sys.modules = self.orig_sysmodules.copy()
+
         # Need to preserve BB_CONSOLELOG over resets
         consolelog = None
         if hasattr(self, "data"):