Skip to contentSkip to conversation

cooker: Restore sys.path and sys.modules between parses

PATCH New Richard Purdie 1 participant 2 messages Mar 31, 2022

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 cooker: Restore sys.path and sys.modules between parses

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.

---
 lib/bb/cooker.py | 8 ++++++++
 1 file changed, 8 insertions(+)
lib/bb/cooker.py +8 -0
index 1359d33f77..0d29aa03a0 100644
@@ -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]
+
         self.configuration = bb.cookerdata.CookerConfiguration()
 
         self.idleCallBackRegister = idleCallBackRegister
@@ -350,6 +353,11 @@ class BBCooker:
         self.state = state.initial
         self.caches_array = []
 
+        sys.path = self.orig_syspath.copy()
+        for mod in [*sys.modules]:
+            if mod not in self.orig_sysmodules:
+                del sys.modules[mod]
+
         # Need to preserve BB_CONSOLELOG over resets
         consolelog = None
         if hasattr(self, "data"):
Signature · 1 line
2.32.0
#1 lore raw

PATCH 2/2 cooker: Ensure any existing hashserv connection is closed

Ensure any exiting hash server connection is terminated before we start a new bitbake session. This avoids errors seen with memory resident bitbake when the asyncio event loop isn't closed correctly.

---
 lib/bb/cooker.py | 2 ++
 1 file changed, 2 insertions(+)
lib/bb/cooker.py +2 -0
index 0d29aa03a0..d100b96f53 100644
@@ -1766,6 +1766,8 @@ class BBCooker:
         self.state = state.initial
 
     def reset(self):
+        if hasattr(bb.parse, "siggen"):
+            bb.parse.siggen.exit()
         self.initConfigurationData()
         self.handlePRServ()
 
Signature · 1 line
2.32.0