summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/lib/oe/utils.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/meta/lib/oe/utils.py b/meta/lib/oe/utils.py
index 14a7d07ef01..f6980449c4b 100644
--- a/meta/lib/oe/utils.py
+++ b/meta/lib/oe/utils.py
@@ -4,8 +4,10 @@
# SPDX-License-Identifier: GPL-2.0-only
#
+import contextlib
import subprocess
import multiprocessing
+import os
import traceback
import errno
@@ -540,3 +542,18 @@ def touch(filename):
# Handle read-only file systems gracefully
if e.errno != errno.EROFS:
raise e
+
+# This is taken from contextlib in Python 3.11, and can be removed when we can assume 3.11 onwards.
+class chdir(contextlib.AbstractContextManager):
+ """Non thread-safe context manager to change the current working directory."""
+
+ def __init__(self, path):
+ self.path = path
+ self._old_cwd = []
+
+ def __enter__(self):
+ self._old_cwd.append(os.getcwd())
+ os.chdir(self.path)
+
+ def __exit__(self, *excinfo):
+ os.chdir(self._old_cwd.pop())