Openembedded Core Discussions
 help / color / mirror / Atom feed
* [PATCH] icecc.bbclass: replace os.popen with subprocess.check_output
@ 2016-06-14 14:03 Martin Jansa
  2016-06-14 14:59 ` Leonardo Sandoval
  2016-10-05 20:53 ` [PATCHv2] " Martin Jansa
  0 siblings, 2 replies; 4+ messages in thread
From: Martin Jansa @ 2016-06-14 14:03 UTC (permalink / raw)
  To: openembedded-core

* otherwise there is a lot of warnings about missing close on file descriptor

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 meta/classes/icecc.bbclass | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/meta/classes/icecc.bbclass b/meta/classes/icecc.bbclass
index e1c06c4..cb44007 100644
--- a/meta/classes/icecc.bbclass
+++ b/meta/classes/icecc.bbclass
@@ -47,7 +47,8 @@ def get_cross_kernel_cc(bb,d):
 
     # evaluate the expression by the shell if necessary
     if '`' in kernel_cc or '$(' in kernel_cc:
-        kernel_cc = os.popen("echo %s" % kernel_cc).read()[:-1]
+        import subprocess
+        kernel_cc = subprocess.check_output("echo %s" % kernel_cc, shell=True)
 
     kernel_cc = d.expand(kernel_cc)
     kernel_cc = kernel_cc.replace('ccache', '').strip()
@@ -220,9 +221,14 @@ def icecc_get_and_check_tool(bb, d, tool):
     # PATH or icecc-create-env script will silently create an invalid
     # compiler environment package.
     t = icecc_get_tool(bb, d, tool)
-    if t and os.popen("readlink -f %s" % t).read()[:-1] == get_icecc(d):
-        bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d)))
-        return ""
+    if t:
+        import subprocess
+        link_path = subprocess.check_output("readlink -f %s" % t, shell=True)
+        if link_path == get_icecc(d):
+            bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d)))
+            return ""
+        else:
+            return t
     else:
         return t
 
-- 
2.9.0



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] icecc.bbclass: replace os.popen with subprocess.check_output
  2016-06-14 14:03 [PATCH] icecc.bbclass: replace os.popen with subprocess.check_output Martin Jansa
@ 2016-06-14 14:59 ` Leonardo Sandoval
  2016-06-14 15:06   ` Burton, Ross
  2016-10-05 20:53 ` [PATCHv2] " Martin Jansa
  1 sibling, 1 reply; 4+ messages in thread
From: Leonardo Sandoval @ 2016-06-14 14:59 UTC (permalink / raw)
  To: Martin Jansa, openembedded-core



On 06/14/2016 09:03 AM, Martin Jansa wrote:
> * otherwise there is a lot of warnings about missing close on file descriptor
>
> Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
> ---
>   meta/classes/icecc.bbclass | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/meta/classes/icecc.bbclass b/meta/classes/icecc.bbclass
> index e1c06c4..cb44007 100644
> --- a/meta/classes/icecc.bbclass
> +++ b/meta/classes/icecc.bbclass
> @@ -47,7 +47,8 @@ def get_cross_kernel_cc(bb,d):
>   
>       # evaluate the expression by the shell if necessary
>       if '`' in kernel_cc or '$(' in kernel_cc:
> -        kernel_cc = os.popen("echo %s" % kernel_cc).read()[:-1]
> +        import subprocess
There are two imports like this, would it make sense to place just once 
on top?

Also, now that we switch to subprocess.check_output, I wonder if we need 
to convert it to string (the output of this method) before proceeding.
> +        kernel_cc = subprocess.check_output("echo %s" % kernel_cc, shell=True)
>   
>       kernel_cc = d.expand(kernel_cc)
>       kernel_cc = kernel_cc.replace('ccache', '').strip()
> @@ -220,9 +221,14 @@ def icecc_get_and_check_tool(bb, d, tool):
>       # PATH or icecc-create-env script will silently create an invalid
>       # compiler environment package.
>       t = icecc_get_tool(bb, d, tool)
> -    if t and os.popen("readlink -f %s" % t).read()[:-1] == get_icecc(d):
> -        bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d)))
> -        return ""
> +    if t:
> +        import subprocess
> +        link_path = subprocess.check_output("readlink -f %s" % t, shell=True)
> +        if link_path == get_icecc(d):
> +            bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d)))
> +            return ""
> +        else:
> +            return t
>       else:
>           return t
>   



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] icecc.bbclass: replace os.popen with subprocess.check_output
  2016-06-14 14:59 ` Leonardo Sandoval
@ 2016-06-14 15:06   ` Burton, Ross
  0 siblings, 0 replies; 4+ messages in thread
From: Burton, Ross @ 2016-06-14 15:06 UTC (permalink / raw)
  To: Leonardo Sandoval; +Cc: OE-core

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

On 14 June 2016 at 15:59, Leonardo Sandoval <
leonardo.sandoval.gonzalez@linux.intel.com> wrote:

> Also, now that we switch to subprocess.check_output, I wonder if we need
> to convert it to string (the output of this method) before proceeding.
>

Yeah, check_output under py3 returns byte arrays, so you either need to
convert to string or pass universal_newlines=True.

Ross

[-- Attachment #2: Type: text/html, Size: 800 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCHv2] icecc.bbclass: replace os.popen with subprocess.check_output
  2016-06-14 14:03 [PATCH] icecc.bbclass: replace os.popen with subprocess.check_output Martin Jansa
  2016-06-14 14:59 ` Leonardo Sandoval
@ 2016-10-05 20:53 ` Martin Jansa
  1 sibling, 0 replies; 4+ messages in thread
From: Martin Jansa @ 2016-10-05 20:53 UTC (permalink / raw)
  To: openembedded-core

* otherwise there is a lot of warnings about missing close on file descriptor

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 meta/classes/icecc.bbclass | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/meta/classes/icecc.bbclass b/meta/classes/icecc.bbclass
index e1c06c4..a837894 100644
--- a/meta/classes/icecc.bbclass
+++ b/meta/classes/icecc.bbclass
@@ -47,7 +47,8 @@ def get_cross_kernel_cc(bb,d):
 
     # evaluate the expression by the shell if necessary
     if '`' in kernel_cc or '$(' in kernel_cc:
-        kernel_cc = os.popen("echo %s" % kernel_cc).read()[:-1]
+        import subprocess
+        kernel_cc = subprocess.check_output("echo %s" % kernel_cc, shell=True).decode("utf-8")[:-1]
 
     kernel_cc = d.expand(kernel_cc)
     kernel_cc = kernel_cc.replace('ccache', '').strip()
@@ -220,9 +221,14 @@ def icecc_get_and_check_tool(bb, d, tool):
     # PATH or icecc-create-env script will silently create an invalid
     # compiler environment package.
     t = icecc_get_tool(bb, d, tool)
-    if t and os.popen("readlink -f %s" % t).read()[:-1] == get_icecc(d):
-        bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d)))
-        return ""
+    if t:
+        import subprocess
+        link_path = subprocess.check_output("readlink -f %s" % t, shell=True).decode("utf-8")[:-1]
+        if link_path == get_icecc(d):
+            bb.error("%s is a symlink to %s in PATH and this prevents icecc from working" % (t, get_icecc(d)))
+            return ""
+        else:
+            return t
     else:
         return t
 
-- 
2.10.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2016-10-05 20:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-06-14 14:03 [PATCH] icecc.bbclass: replace os.popen with subprocess.check_output Martin Jansa
2016-06-14 14:59 ` Leonardo Sandoval
2016-06-14 15:06   ` Burton, Ross
2016-10-05 20:53 ` [PATCHv2] " Martin Jansa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox