Skip to contentSkip to conversation

meta/classes: correct subprocess.Popen.communicate() return values

PATCH New Vladimir Zapolskiy 1 participant 3 messages Aug 6, 2016

lore
Share & tools
lore
#0 lore raw

cover meta/classes: correct subprocess.Popen.communicate() return values

This is a non-functional change, which intends to correct element names of a tuple returned by Popen.communicate() in oe-core classes chrpath and package.

Both in python2 and python3 subprocess.Popen.communicate() method returns a tuple (stdoutdata, stderrdata), thus some old assignments and collateral comments are incorrect from human's point of view, however formally there is no error in the code.

The issue was occasionally found by code inspection while investigating early build errors due to not installed chrpath utility on a host.

The change is desired to have to avoid excessive astonishment while reading code and of course copy-paste errors in future.

Vladimir Zapolskiy (2):
chrpath: correct subprocess.Popen.communicate() return values
package: correct subprocess.Popen.communicate() return values

 meta/classes/chrpath.bbclass | 18 +++++++++---------
 meta/classes/package.bbclass | 12 ++++++------
 2 files changed, 15 insertions(+), 15 deletions(-)
Signature · 1 line
2.8.1
#1 lore raw

PATCH 1/2 chrpath: correct subprocess.Popen.communicate() return values

This is a non-functional change, which intends to correct element names of a tuple returned by Popen.communicate().

Both in python2 and python3 subprocess.Popen.communicate() method returns a tuple (stdoutdata, stderrdata), thus old assignments and collateral comments are incorrect from human's point of view, however formally there is no error in the code.

The change is desired to have to avoid copy-paste errors in future.

---
 meta/classes/chrpath.bbclass | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
meta/classes/chrpath.bbclass +9 -9
index cdd7f27..72e8a12 100644
@@ -5,17 +5,17 @@ def process_file_linux(cmd, fpath, rootdir, baseprefix, tmpdir, d):
     import subprocess as sub
 
     p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
-    err, out = p.communicate()
-    # If returned successfully, process stderr for results
+    out, err = p.communicate()
+    # If returned successfully, process stdout for results
     if p.returncode != 0:
         return
 
-    err = err.decode('utf-8')
+    out = out.decode('utf-8')
 
     # Handle RUNPATH as well as RPATH
-    err = err.replace("RUNPATH=","RPATH=")
+    out = out.replace("RUNPATH=","RPATH=")
     # Throw away everything other than the rpath list
-    curr_rpath = err.partition("RPATH=")[2]
+    curr_rpath = out.partition("RPATH=")[2]
     #bb.note("Current rpath for %s is %s" % (fpath, curr_rpath.strip()))
     rpaths = curr_rpath.split(":")
     new_rpaths = []
@@ -46,11 +46,11 @@ def process_file_darwin(cmd, fpath, rootdir, baseprefix, tmpdir, d):
     import subprocess as sub
 
     p = sub.Popen([d.expand("${HOST_PREFIX}otool"), '-L', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
-    err, out = p.communicate()
-    # If returned successfully, process stderr for results
+    out, err = p.communicate()
+    # If returned successfully, process stdout for results
     if p.returncode != 0:
         return
-    for l in err.split("\n"):
+    for l in out.split("\n"):
         if "(compatibility" not in l:
             continue
         rpath = l.partition("(compatibility")[0].strip()
@@ -59,7 +59,7 @@ def process_file_darwin(cmd, fpath, rootdir, baseprefix, tmpdir, d):
 
         newpath = "@loader_path/" + os.path.relpath(rpath, os.path.dirname(fpath.replace(rootdir, "/")))
         p = sub.Popen([d.expand("${HOST_PREFIX}install_name_tool"), '-change', rpath, newpath, fpath],stdout=sub.PIPE,stderr=sub.PIPE)
-        err, out = p.communicate()
+        out, err = p.communicate()
 
 def process_dir (rootdir, directory, d):
     import stat
Signature · 1 line
2.8.1
#2 lore raw

PATCH 2/2 package: correct subprocess.Popen.communicate() return values

In reply to Vladimir Zapolskiy

This is a non-functional change, which intends to correct element names of a tuple returned by Popen.communicate().

Both in python2 and python3 subprocess.Popen.communicate() method returns a tuple (stdoutdata, stderrdata), thus old assignments and collateral comments are incorrect from human's point of view, however formally there is no error in the code.

The change is desired to have to avoid copy-paste errors in future.

---
 meta/classes/package.bbclass | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
meta/classes/package.bbclass +6 -6
index d6204cf..c592ce1 100644
@@ -1557,19 +1557,19 @@ python package_do_shlibs() {
         if file.endswith('.dylib') or file.endswith('.so'):
             rpath = []
             p = sub.Popen([d.expand("${HOST_PREFIX}otool"), '-l', file],stdout=sub.PIPE,stderr=sub.PIPE)
-            err, out = p.communicate()
-            # If returned successfully, process stderr for results
+            out, err = p.communicate()
+            # If returned successfully, process stdout for results
             if p.returncode == 0:
-                for l in err.split("\n"):
+                for l in out.split("\n"):
                     l = l.strip()
                     if l.startswith('path '):
                         rpath.append(l.split()[1])
 
         p = sub.Popen([d.expand("${HOST_PREFIX}otool"), '-L', file],stdout=sub.PIPE,stderr=sub.PIPE)
-        err, out = p.communicate()
-        # If returned successfully, process stderr for results
+        out, err = p.communicate()
+        # If returned successfully, process stdout for results
         if p.returncode == 0:
-            for l in err.split("\n"):
+            for l in out.split("\n"):
                 l = l.strip()
                 if not l or l.endswith(":"):
                     continue
Signature · 1 line
2.8.1