[bitbake-devel] [PATCH] Fix import spawn error on Python 3.6.5(Default Python version on Ubuntu 18.04 LTS). - Copy the find_executable() function from python3.5/distutils/spawn.py - npm.py do not need to import spawn

Tzu Hsiang Lin t9360341 at ntut.org.tw
Sun May 20 14:51:52 UTC 2018


---
 lib/bb/fetch2/clearcase.py | 28 ++++++++++++++++++++++++++--
 lib/bb/fetch2/npm.py       |  1 -
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/lib/bb/fetch2/clearcase.py b/lib/bb/fetch2/clearcase.py
index 36beab6a..28589dbc 100644
--- a/lib/bb/fetch2/clearcase.py
+++ b/lib/bb/fetch2/clearcase.py
@@ -69,7 +69,6 @@ from   bb.fetch2 import FetchMethod
 from   bb.fetch2 import FetchError
 from   bb.fetch2 import runfetchcmd
 from   bb.fetch2 import logger
-from   distutils import spawn
 
 class ClearCase(FetchMethod):
     """Class to fetch urls via 'clearcase'"""
@@ -107,7 +106,7 @@ class ClearCase(FetchMethod):
         else:
             ud.module = ""
 
-        ud.basecmd = d.getVar("FETCHCMD_ccrc") or spawn.find_executable("cleartool") or spawn.find_executable("rcleartool")
+        ud.basecmd = d.getVar("FETCHCMD_ccrc") or _find_executable("cleartool") or _find_executable("rcleartool")
 
         if d.getVar("SRCREV") == "INVALID":
           raise FetchError("Set a valid SRCREV for the clearcase fetcher in your recipe, e.g. SRCREV = \"/main/LATEST\" or any other label of your choice.")
@@ -207,6 +206,31 @@ class ClearCase(FetchMethod):
             output = runfetchcmd(cmd, d, workdir=ud.ccasedir)
             logger.info("rmview output: %s", output)
 
+    def _find_executable(executable, path=None):
+        """Tries to find 'executable' in the directories listed in 'path'.
+
+        A string listing directories separated by 'os.pathsep'; defaults to
+        os.environ['PATH'].  Returns the complete filename or None if not found.
+        """
+        if path is None:
+            path = os.environ['PATH']
+
+        paths = path.split(os.pathsep)
+        base, ext = os.path.splitext(executable)
+
+        if (sys.platform == 'win32') and (ext != '.exe'):
+            executable = executable + '.exe'
+
+        if not os.path.isfile(executable):
+            for p in paths:
+                f = os.path.join(p, executable)
+                if os.path.isfile(f):
+                    # the file exists, we have a shot at spawn working
+                    return f
+            return None
+        else:
+            return executable
+
     def need_update(self, ud, d):
         if ("LATEST" in ud.label) or (ud.customspec and "LATEST" in ud.customspec):
             ud.identifier += "-%s" % d.getVar("DATETIME",d, True)
diff --git a/lib/bb/fetch2/npm.py b/lib/bb/fetch2/npm.py
index 730c346a..408dfc3d 100644
--- a/lib/bb/fetch2/npm.py
+++ b/lib/bb/fetch2/npm.py
@@ -32,7 +32,6 @@ from   bb.fetch2 import runfetchcmd
 from   bb.fetch2 import logger
 from   bb.fetch2 import UnpackError
 from   bb.fetch2 import ParameterError
-from   distutils import spawn
 
 def subprocess_setup():
     # Python installs a SIGPIPE handler by default. This is usually not what
-- 
2.17.0




More information about the bitbake-devel mailing list