Skip to contentSkip to conversation

fetch2: Abstract fetcher environment to a function

PATCH New Richard Purdie 1 participant 1 message Feb 19, 2022

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 fetch2: Abstract fetcher environment to a function

The changing of the environment inside the wget fetcher can race if threading is used, such as with sstate in OE-Core. Abstract the function so the environment can be correct before the function is called, removing the race since the enviroment is then no longer changed.

---
 lib/bb/fetch2/__init__.py | 11 +++++++++++
 lib/bb/fetch2/wget.py     |  9 +--------
 2 files changed, 12 insertions(+), 8 deletions(-)
lib/bb/fetch2/__init__.py +11 -0
index 14d3557f98..5dfe5ff360 100644
@@ -851,6 +851,17 @@ FETCH_EXPORT_VARS = ['HOME', 'PATH',
                      'AWS_SECRET_ACCESS_KEY',
                      'AWS_DEFAULT_REGION']
 
+def get_fetcher_environment(d):
+    newenv = {}
+    origenv = d.getVar("BB_ORIGENV")
+    for name in bb.fetch2.FETCH_EXPORT_VARS:
+        value = d.getVar(name)
+        if not value and origenv:
+            value = origenv.getVar(name)
+        if value:
+            newenv[name] = value
+    return newenv
+
 def runfetchcmd(cmd, d, quiet=False, cleanup=None, log=None, workdir=None):
     """
     Run cmd returning the command output
lib/bb/fetch2/wget.py +1 -8
index 92cc10785c..b3a3de571a 100644
@@ -315,14 +315,7 @@ class Wget(FetchMethod):
         # Avoid tramping the environment too much by using bb.utils.environment
         # to scope the changes to the build_opener request, which is when the
         # environment lookups happen.
-        newenv = {}
-        origenv = d.getVar("BB_ORIGENV")
-        for name in bb.fetch2.FETCH_EXPORT_VARS:
-            value = d.getVar(name)
-            if not value and origenv:
-                value = origenv.getVar(name)
-            if value:
-                newenv[name] = value
+        newenv = bb.fetch2.get_fetcher_environment(d)
 
         with bb.utils.environment(**newenv):
             import ssl
Signature · 1 line
2.32.0