mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH] configure_helper.py: check for emptyish ptxdist environment variables
@ 2019-09-11  7:50 Roland Hieber
  2019-09-23  8:46 ` Roland Hieber
                   ` (2 more replies)
  0 siblings, 3 replies; 9+ messages in thread
From: Roland Hieber @ 2019-09-11  7:50 UTC (permalink / raw)
  To: ptxdist; +Cc: Roland Hieber

When the environment variable exists, but is empty, os.environment.get()
will return its value instead of using the supplied default. Check for
cases like that to prevent calling an empty command.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
 scripts/configure_helper.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
index c7b46f3b3846..3261a548ec96 100755
--- a/scripts/configure_helper.py
+++ b/scripts/configure_helper.py
@@ -151,7 +151,12 @@ def abort(message):
 	exit(1)
 
 def ask_ptxdist(pkg):
-	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
+	ptxdist = os.environ.get("PTXDIST")
+	if not ptxdist.strip():
+		ptxdist = os.environ.get("ptxdist")
+	if not ptxdist.strip():
+		ptxdist = "ptxdist"
+	
 	p = subprocess.Popen([ ptxdist, "-k", "make",
 		"/print-%s_DIR" % pkg,
 		"/print-%s_SUBDIR" % pkg,
-- 
2.23.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH] configure_helper.py: check for emptyish ptxdist environment variables
  2019-09-11  7:50 [ptxdist] [PATCH] configure_helper.py: check for emptyish ptxdist environment variables Roland Hieber
@ 2019-09-23  8:46 ` Roland Hieber
  2019-09-25 13:13 ` [ptxdist] [PATCH v2] " Roland Hieber
  2019-10-17  8:41 ` [ptxdist] [PATCH v3] configure_helper.py: be more verbose when calling ptxdist fails Roland Hieber
  2 siblings, 0 replies; 9+ messages in thread
From: Roland Hieber @ 2019-09-23  8:46 UTC (permalink / raw)
  To: ptxdist

mol, any comments to this?

 - Roland

On Wed, Sep 11, 2019 at 09:50:49AM +0200, Roland Hieber wrote:
> When the environment variable exists, but is empty, os.environment.get()
> will return its value instead of using the supplied default. Check for
> cases like that to prevent calling an empty command.
> 
> Signed-off-by: Roland Hieber <rhi@pengutronix.de>
> ---
>  scripts/configure_helper.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
> index c7b46f3b3846..3261a548ec96 100755
> --- a/scripts/configure_helper.py
> +++ b/scripts/configure_helper.py
> @@ -151,7 +151,12 @@ def abort(message):
>  	exit(1)
>  
>  def ask_ptxdist(pkg):
> -	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
> +	ptxdist = os.environ.get("PTXDIST")
> +	if not ptxdist.strip():
> +		ptxdist = os.environ.get("ptxdist")
> +	if not ptxdist.strip():
> +		ptxdist = "ptxdist"
> +	
>  	p = subprocess.Popen([ ptxdist, "-k", "make",
>  		"/print-%s_DIR" % pkg,
>  		"/print-%s_SUBDIR" % pkg,
> -- 
> 2.23.0
> 
> 
> _______________________________________________
> ptxdist mailing list
> ptxdist@pengutronix.de
> 

-- 
Roland Hieber                     | r.hieber@pengutronix.de     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* [ptxdist] [PATCH v2] configure_helper.py: check for emptyish ptxdist environment variables
  2019-09-11  7:50 [ptxdist] [PATCH] configure_helper.py: check for emptyish ptxdist environment variables Roland Hieber
  2019-09-23  8:46 ` Roland Hieber
@ 2019-09-25 13:13 ` Roland Hieber
  2019-10-16 10:53   ` Roland Hieber
  2019-10-17  8:41 ` [ptxdist] [PATCH v3] configure_helper.py: be more verbose when calling ptxdist fails Roland Hieber
  2 siblings, 1 reply; 9+ messages in thread
From: Roland Hieber @ 2019-09-25 13:13 UTC (permalink / raw)
  To: ptxdist; +Cc: Roland Hieber

When the environment variable exists, but is empty, os.environment.get()
will return its value instead of using the supplied default. Check for
cases like that to prevent calling an empty command.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
 v1 -> v2:
  - prevent "AttributeError: 'NoneType' object has no attribute 'strip'"
    if none of the checked environment variables are set

 scripts/configure_helper.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
index c7b46f3b3846..73dd4a2add1c 100755
--- a/scripts/configure_helper.py
+++ b/scripts/configure_helper.py
@@ -151,7 +151,12 @@ def abort(message):
 	exit(1)
 
 def ask_ptxdist(pkg):
-	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
+	ptxdist = os.environ.get("PTXDIST")
+	if not ptxdist or not ptxdist.strip():
+		ptxdist = os.environ.get("ptxdist")
+	if not ptxdist or not ptxdist.strip():
+		ptxdist = "ptxdist"
+	
 	p = subprocess.Popen([ ptxdist, "-k", "make",
 		"/print-%s_DIR" % pkg,
 		"/print-%s_SUBDIR" % pkg,
-- 
2.23.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH v2] configure_helper.py: check for emptyish ptxdist environment variables
  2019-09-25 13:13 ` [ptxdist] [PATCH v2] " Roland Hieber
@ 2019-10-16 10:53   ` Roland Hieber
  2019-10-16 11:38     ` Michael Olbrich
  0 siblings, 1 reply; 9+ messages in thread
From: Roland Hieber @ 2019-10-16 10:53 UTC (permalink / raw)
  To: Michael Olbrich; +Cc: ptxdist

Michael, any comments? It does not seem to be applied yet.

 - Roland

On Wed, Sep 25, 2019 at 03:13:40PM +0200, Roland Hieber wrote:
> When the environment variable exists, but is empty, os.environment.get()
> will return its value instead of using the supplied default. Check for
> cases like that to prevent calling an empty command.
> 
> Signed-off-by: Roland Hieber <rhi@pengutronix.de>
> ---
>  v1 -> v2:
>   - prevent "AttributeError: 'NoneType' object has no attribute 'strip'"
>     if none of the checked environment variables are set
> 
>  scripts/configure_helper.py | 7 ++++++-
>  1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
> index c7b46f3b3846..73dd4a2add1c 100755
> --- a/scripts/configure_helper.py
> +++ b/scripts/configure_helper.py
> @@ -151,7 +151,12 @@ def abort(message):
>  	exit(1)
>  
>  def ask_ptxdist(pkg):
> -	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
> +	ptxdist = os.environ.get("PTXDIST")
> +	if not ptxdist or not ptxdist.strip():
> +		ptxdist = os.environ.get("ptxdist")
> +	if not ptxdist or not ptxdist.strip():
> +		ptxdist = "ptxdist"
> +	
>  	p = subprocess.Popen([ ptxdist, "-k", "make",
>  		"/print-%s_DIR" % pkg,
>  		"/print-%s_SUBDIR" % pkg,
> -- 
> 2.23.0
> 
> 
> _______________________________________________
> ptxdist mailing list
> ptxdist@pengutronix.de
> 

-- 
Roland Hieber                     | r.hieber@pengutronix.de     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH v2] configure_helper.py: check for emptyish ptxdist environment variables
  2019-10-16 10:53   ` Roland Hieber
@ 2019-10-16 11:38     ` Michael Olbrich
  2019-10-16 11:58       ` Roland Hieber
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Olbrich @ 2019-10-16 11:38 UTC (permalink / raw)
  To: ptxdist

On Wed, Oct 16, 2019 at 12:53:10PM +0200, Roland Hieber wrote:
> Michael, any comments? It does not seem to be applied yet.

Right, this got lost. I'm not sure I like this. Why would there be an empty
PTXDIST env variable?

Michael

> On Wed, Sep 25, 2019 at 03:13:40PM +0200, Roland Hieber wrote:
> > When the environment variable exists, but is empty, os.environment.get()
> > will return its value instead of using the supplied default. Check for
> > cases like that to prevent calling an empty command.
> > 
> > Signed-off-by: Roland Hieber <rhi@pengutronix.de>
> > ---
> >  v1 -> v2:
> >   - prevent "AttributeError: 'NoneType' object has no attribute 'strip'"
> >     if none of the checked environment variables are set
> > 
> >  scripts/configure_helper.py | 7 ++++++-
> >  1 file changed, 6 insertions(+), 1 deletion(-)
> > 
> > diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
> > index c7b46f3b3846..73dd4a2add1c 100755
> > --- a/scripts/configure_helper.py
> > +++ b/scripts/configure_helper.py
> > @@ -151,7 +151,12 @@ def abort(message):
> >  	exit(1)
> >  
> >  def ask_ptxdist(pkg):
> > -	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
> > +	ptxdist = os.environ.get("PTXDIST")
> > +	if not ptxdist or not ptxdist.strip():
> > +		ptxdist = os.environ.get("ptxdist")
> > +	if not ptxdist or not ptxdist.strip():
> > +		ptxdist = "ptxdist"
> > +	
> >  	p = subprocess.Popen([ ptxdist, "-k", "make",
> >  		"/print-%s_DIR" % pkg,
> >  		"/print-%s_SUBDIR" % pkg,
> > -- 
> > 2.23.0
> > 
> > 
> > _______________________________________________
> > ptxdist mailing list
> > ptxdist@pengutronix.de
> > 
> 
> -- 
> Roland Hieber                     | r.hieber@pengutronix.de     |
> Pengutronix e.K.                  | https://www.pengutronix.de/ |
> Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
> Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH v2] configure_helper.py: check for emptyish ptxdist environment variables
  2019-10-16 11:38     ` Michael Olbrich
@ 2019-10-16 11:58       ` Roland Hieber
  2019-10-16 13:26         ` Michael Olbrich
  0 siblings, 1 reply; 9+ messages in thread
From: Roland Hieber @ 2019-10-16 11:58 UTC (permalink / raw)
  To: ptxdist

On Wed, Oct 16, 2019 at 01:38:56PM +0200, Michael Olbrich wrote:
> On Wed, Oct 16, 2019 at 12:53:10PM +0200, Roland Hieber wrote:
> > Michael, any comments? It does not seem to be applied yet.
> 
> Right, this got lost. I'm not sure I like this. Why would there be an empty
> PTXDIST env variable?

I don't know, but somehow it happened to me, and the script can be more robust in that case. Also when that happens it is not very
easy to find out what is the fault just from the Python stacktrace: 

  Traceback (most recent call last):
    File "./scripts/configure_helper.py", line 497, in <module>
      (tool, d, pkg_subdir, pkg_conf_opt, sysroot_host) = ask_ptxdist(ptx_PKG)
    File "./scripts/configure_helper.py", line 165, in ask_ptxdist
      universal_newlines=True)
    File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
      restore_signals, start_new_session)
    File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
      raise child_exception_type(errno_num, err_msg, err_filename)
  PermissionError: [Errno 13] Permission denied: ''

 - Roland

> 
> Michael
> 
> > On Wed, Sep 25, 2019 at 03:13:40PM +0200, Roland Hieber wrote:
> > > When the environment variable exists, but is empty, os.environment.get()
> > > will return its value instead of using the supplied default. Check for
> > > cases like that to prevent calling an empty command.
> > > 
> > > Signed-off-by: Roland Hieber <rhi@pengutronix.de>
> > > ---
> > >  v1 -> v2:
> > >   - prevent "AttributeError: 'NoneType' object has no attribute 'strip'"
> > >     if none of the checked environment variables are set
> > > 
> > >  scripts/configure_helper.py | 7 ++++++-
> > >  1 file changed, 6 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
> > > index c7b46f3b3846..73dd4a2add1c 100755
> > > --- a/scripts/configure_helper.py
> > > +++ b/scripts/configure_helper.py
> > > @@ -151,7 +151,12 @@ def abort(message):
> > >  	exit(1)
> > >  
> > >  def ask_ptxdist(pkg):
> > > -	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
> > > +	ptxdist = os.environ.get("PTXDIST")
> > > +	if not ptxdist or not ptxdist.strip():
> > > +		ptxdist = os.environ.get("ptxdist")
> > > +	if not ptxdist or not ptxdist.strip():
> > > +		ptxdist = "ptxdist"
> > > +	
> > >  	p = subprocess.Popen([ ptxdist, "-k", "make",
> > >  		"/print-%s_DIR" % pkg,
> > >  		"/print-%s_SUBDIR" % pkg,
> > > -- 
> > > 2.23.0
> > > 
> > > 
> > > _______________________________________________
> > > ptxdist mailing list
> > > ptxdist@pengutronix.de
> > > 
> > 
> > -- 
> > Roland Hieber                     | r.hieber@pengutronix.de     |
> > Pengutronix e.K.                  | https://www.pengutronix.de/ |
> > Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
> > Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
> > 
> 
> -- 
> Pengutronix e.K.                           |                             |
> Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> 
> _______________________________________________
> ptxdist mailing list
> ptxdist@pengutronix.de
> 

-- 
Roland Hieber                     | r.hieber@pengutronix.de     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH v2] configure_helper.py: check for emptyish ptxdist environment variables
  2019-10-16 11:58       ` Roland Hieber
@ 2019-10-16 13:26         ` Michael Olbrich
  2019-10-17  8:24           ` Roland Hieber
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Olbrich @ 2019-10-16 13:26 UTC (permalink / raw)
  To: ptxdist

On Wed, Oct 16, 2019 at 01:58:07PM +0200, Roland Hieber wrote:
> On Wed, Oct 16, 2019 at 01:38:56PM +0200, Michael Olbrich wrote:
> > On Wed, Oct 16, 2019 at 12:53:10PM +0200, Roland Hieber wrote:
> > > Michael, any comments? It does not seem to be applied yet.
> > 
> > Right, this got lost. I'm not sure I like this. Why would there be an empty
> > PTXDIST env variable?
> 
> I don't know, but somehow it happened to me, and the script can be more robust in that case. Also when that happens it is not very
> easy to find out what is the fault just from the Python stacktrace: 
> 
>   Traceback (most recent call last):
>     File "./scripts/configure_helper.py", line 497, in <module>
>       (tool, d, pkg_subdir, pkg_conf_opt, sysroot_host) = ask_ptxdist(ptx_PKG)
>     File "./scripts/configure_helper.py", line 165, in ask_ptxdist
>       universal_newlines=True)
>     File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
>       restore_signals, start_new_session)
>     File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
>       raise child_exception_type(errno_num, err_msg, err_filename)
>   PermissionError: [Errno 13] Permission denied: ''

I think, catching the exception and printing an error with the failing
commandline would be better. Other bogus, non-empty strings will cause
exceptions as well.

Michael

> > 
> > > On Wed, Sep 25, 2019 at 03:13:40PM +0200, Roland Hieber wrote:
> > > > When the environment variable exists, but is empty, os.environment.get()
> > > > will return its value instead of using the supplied default. Check for
> > > > cases like that to prevent calling an empty command.
> > > > 
> > > > Signed-off-by: Roland Hieber <rhi@pengutronix.de>
> > > > ---
> > > >  v1 -> v2:
> > > >   - prevent "AttributeError: 'NoneType' object has no attribute 'strip'"
> > > >     if none of the checked environment variables are set
> > > > 
> > > >  scripts/configure_helper.py | 7 ++++++-
> > > >  1 file changed, 6 insertions(+), 1 deletion(-)
> > > > 
> > > > diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
> > > > index c7b46f3b3846..73dd4a2add1c 100755
> > > > --- a/scripts/configure_helper.py
> > > > +++ b/scripts/configure_helper.py
> > > > @@ -151,7 +151,12 @@ def abort(message):
> > > >  	exit(1)
> > > >  
> > > >  def ask_ptxdist(pkg):
> > > > -	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
> > > > +	ptxdist = os.environ.get("PTXDIST")
> > > > +	if not ptxdist or not ptxdist.strip():
> > > > +		ptxdist = os.environ.get("ptxdist")
> > > > +	if not ptxdist or not ptxdist.strip():
> > > > +		ptxdist = "ptxdist"
> > > > +	
> > > >  	p = subprocess.Popen([ ptxdist, "-k", "make",
> > > >  		"/print-%s_DIR" % pkg,
> > > >  		"/print-%s_SUBDIR" % pkg,
> > > > -- 
> > > > 2.23.0
> > > > 
> > > > 
> > > > _______________________________________________
> > > > ptxdist mailing list
> > > > ptxdist@pengutronix.de
> > > > 
> > > 
> > > -- 
> > > Roland Hieber                     | r.hieber@pengutronix.de     |
> > > Pengutronix e.K.                  | https://www.pengutronix.de/ |
> > > Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
> > > Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
> > > 
> > 
> > -- 
> > Pengutronix e.K.                           |                             |
> > Industrial Linux Solutions                 | http://www.pengutronix.de/  |
> > Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
> > Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |
> > 
> > _______________________________________________
> > ptxdist mailing list
> > ptxdist@pengutronix.de
> > 
> 
> -- 
> Roland Hieber                     | r.hieber@pengutronix.de     |
> Pengutronix e.K.                  | https://www.pengutronix.de/ |
> Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
> Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |
> 
> _______________________________________________
> ptxdist mailing list
> ptxdist@pengutronix.de
> 

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* Re: [ptxdist] [PATCH v2] configure_helper.py: check for emptyish ptxdist environment variables
  2019-10-16 13:26         ` Michael Olbrich
@ 2019-10-17  8:24           ` Roland Hieber
  0 siblings, 0 replies; 9+ messages in thread
From: Roland Hieber @ 2019-10-17  8:24 UTC (permalink / raw)
  To: ptxdist

On Wed, Oct 16, 2019 at 03:26:15PM +0200, Michael Olbrich wrote:
> On Wed, Oct 16, 2019 at 01:58:07PM +0200, Roland Hieber wrote:
> > On Wed, Oct 16, 2019 at 01:38:56PM +0200, Michael Olbrich wrote:
> > > On Wed, Oct 16, 2019 at 12:53:10PM +0200, Roland Hieber wrote:
> > > > Michael, any comments? It does not seem to be applied yet.
> > > 
> > > Right, this got lost. I'm not sure I like this. Why would there be an empty
> > > PTXDIST env variable?
> > 
> > I don't know, but somehow it happened to me, and the script can be more robust in that case. Also when that happens it is not very
> > easy to find out what is the fault just from the Python stacktrace: 
> > 
> >   Traceback (most recent call last):
> >     File "./scripts/configure_helper.py", line 497, in <module>
> >       (tool, d, pkg_subdir, pkg_conf_opt, sysroot_host) = ask_ptxdist(ptx_PKG)
> >     File "./scripts/configure_helper.py", line 165, in ask_ptxdist
> >       universal_newlines=True)
> >     File "/usr/lib/python3.7/subprocess.py", line 775, in __init__
> >       restore_signals, start_new_session)
> >     File "/usr/lib/python3.7/subprocess.py", line 1522, in _execute_child
> >       raise child_exception_type(errno_num, err_msg, err_filename)
> >   PermissionError: [Errno 13] Permission denied: ''
> 
> I think, catching the exception and printing an error with the failing
> commandline would be better. Other bogus, non-empty strings will cause
> exceptions as well.

Yeah, after having a night of sleep over this, I think this is also the
better approach.

 - Roland


> 
> Michael
> 
> > > 
> > > > On Wed, Sep 25, 2019 at 03:13:40PM +0200, Roland Hieber wrote:
> > > > > When the environment variable exists, but is empty, os.environment.get()
> > > > > will return its value instead of using the supplied default. Check for
> > > > > cases like that to prevent calling an empty command.
> > > > > 
> > > > > Signed-off-by: Roland Hieber <rhi@pengutronix.de>
> > > > > ---
> > > > >  v1 -> v2:
> > > > >   - prevent "AttributeError: 'NoneType' object has no attribute 'strip'"
> > > > >     if none of the checked environment variables are set
> > > > > 
> > > > >  scripts/configure_helper.py | 7 ++++++-
> > > > >  1 file changed, 6 insertions(+), 1 deletion(-)
> > > > > 
> > > > > diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
> > > > > index c7b46f3b3846..73dd4a2add1c 100755
> > > > > --- a/scripts/configure_helper.py
> > > > > +++ b/scripts/configure_helper.py
> > > > > @@ -151,7 +151,12 @@ def abort(message):
> > > > >  	exit(1)
> > > > >  
> > > > >  def ask_ptxdist(pkg):
> > > > > -	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
> > > > > +	ptxdist = os.environ.get("PTXDIST")
> > > > > +	if not ptxdist or not ptxdist.strip():
> > > > > +		ptxdist = os.environ.get("ptxdist")
> > > > > +	if not ptxdist or not ptxdist.strip():
> > > > > +		ptxdist = "ptxdist"
> > > > > +	
> > > > >  	p = subprocess.Popen([ ptxdist, "-k", "make",
> > > > >  		"/print-%s_DIR" % pkg,
> > > > >  		"/print-%s_SUBDIR" % pkg,
> > > > > -- 
> > > > > 2.23.0

-- 
Roland Hieber                     | r.hieber@pengutronix.de     |
Pengutronix e.K.                  | https://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim | Phone: +49-5121-206917-5086 |
Amtsgericht Hildesheim, HRA 2686  | Fax:   +49-5121-206917-5555 |

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

* [ptxdist] [PATCH v3] configure_helper.py: be more verbose when calling ptxdist fails
  2019-09-11  7:50 [ptxdist] [PATCH] configure_helper.py: check for emptyish ptxdist environment variables Roland Hieber
  2019-09-23  8:46 ` Roland Hieber
  2019-09-25 13:13 ` [ptxdist] [PATCH v2] " Roland Hieber
@ 2019-10-17  8:41 ` Roland Hieber
  2 siblings, 0 replies; 9+ messages in thread
From: Roland Hieber @ 2019-10-17  8:41 UTC (permalink / raw)
  To: ptxdist; +Cc: Roland Hieber

For example, when one of the environment variables is empty, the
subprocess call only raises an unhelpful exception:

    PermissionError: [Errno 13] Permission denied: ''

At least print the called command line above the stacktrace to have some
more helpful information where to start looking.

Signed-off-by: Roland Hieber <rhi@pengutronix.de>
---
 scripts/configure_helper.py | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/scripts/configure_helper.py b/scripts/configure_helper.py
index c7b46f3b3846..bf2bf113b1f3 100755
--- a/scripts/configure_helper.py
+++ b/scripts/configure_helper.py
@@ -152,7 +152,7 @@ def abort(message):
 
 def ask_ptxdist(pkg):
 	ptxdist = os.environ.get("PTXDIST", os.environ.get("ptxdist", "ptxdist"))
-	p = subprocess.Popen([ ptxdist, "-k", "make",
+	cmdline = [ ptxdist, "-k", "make",
 		"/print-%s_DIR" % pkg,
 		"/print-%s_SUBDIR" % pkg,
 		"/print-%s_CONF_OPT" % pkg,
@@ -160,9 +160,14 @@ def ask_ptxdist(pkg):
 		"/print-%s_CONF_TOOL" %pkg,
 		"/print-CROSS_MESON_USR",
 		"/print-CROSS_AUTOCONF_USR",
-		"/print-PTXDIST_SYSROOT_HOST"],
-		stdout=subprocess.PIPE,
-		universal_newlines=True)
+		"/print-PTXDIST_SYSROOT_HOST" ]
+	try:
+		p = subprocess.Popen(cmdline,
+			stdout=subprocess.PIPE,
+			universal_newlines=True)
+	except OSError as e:
+		print("Unable to execute ptxdist: ", cmdline)
+		raise
 
 	d = p.stdout.readline().strip()
 	subdir = p.stdout.readline().strip()
-- 
2.20.1


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

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

end of thread, other threads:[~2019-10-17  8:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-09-11  7:50 [ptxdist] [PATCH] configure_helper.py: check for emptyish ptxdist environment variables Roland Hieber
2019-09-23  8:46 ` Roland Hieber
2019-09-25 13:13 ` [ptxdist] [PATCH v2] " Roland Hieber
2019-10-16 10:53   ` Roland Hieber
2019-10-16 11:38     ` Michael Olbrich
2019-10-16 11:58       ` Roland Hieber
2019-10-16 13:26         ` Michael Olbrich
2019-10-17  8:24           ` Roland Hieber
2019-10-17  8:41 ` [ptxdist] [PATCH v3] configure_helper.py: be more verbose when calling ptxdist fails Roland Hieber

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