Don't require python2.7 in buildversion.py. Also, ignore only those exceptions that are known to be possible.
Signed-off-by: Kevin O'Connor kevin@koconnor.net --- scripts/buildversion.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/scripts/buildversion.py b/scripts/buildversion.py index d61fc9e..5b8807e 100755 --- a/scripts/buildversion.py +++ b/scripts/buildversion.py @@ -4,7 +4,7 @@ # Copyright (C) 2015 Kevin O'Connor kevin@koconnor.net # # This file may be distributed under the terms of the GNU GPLv3 license. -import sys, os, subprocess, time, socket, optparse +import sys, os, subprocess, shlex, time, socket, optparse
VERSION_FORMAT = """ /* DO NOT EDIT! This is an autogenerated file. See scripts/buildversion.py. */ @@ -12,16 +12,24 @@ VERSION_FORMAT = """ #define BUILD_TOOLS "%s" """
+# Run program and return the specified output +def check_output(prog): + try: + process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE) + output = process.communicate()[0] + retcode = process.poll() + except OSError: + return "" + try: + return output.decode() + except UnicodeError: + return "" + # Obtain version info from "git" program def git_version(): if not os.path.exists('.git'): return "" - params = "git describe --tags --long --dirty".split() - try: - ver = subprocess.check_output(params).decode().strip() - except: - return "" - return ver + return check_output("git describe --tags --long --dirty").strip()
# Look for version in a ".version" file. Official release tarballs # have this file (see scripts/tarball.sh). @@ -32,7 +40,7 @@ def file_version(): f = open('.version', 'r') ver = f.readline().strip() f.close() - except: + except OSError: return "" return ver
@@ -50,11 +58,7 @@ def tool_versions(tools): success = 0 for tool in tools: # Extract first line from "tool --version" output - try: - ver = subprocess.check_output([tool, '--version']).decode() - except: - continue - verstr = ver.split('\n')[0] + verstr = check_output("%s --version" % (tool,)).split('\n')[0] # Check if this tool looks like a binutils program isbinutils = 0 if verstr.startswith('GNU '):
On Mon, 2015-11-09 at 09:33 -0500, Kevin O'Connor wrote:
Don't require python2.7 in buildversion.py. Also, ignore only those exceptions that are known to be possible.
Signed-off-by: Kevin O'Connor kevin@koconnor.net
scripts/buildversion.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/scripts/buildversion.py b/scripts/buildversion.py index d61fc9e..5b8807e 100755 --- a/scripts/buildversion.py +++ b/scripts/buildversion.py @@ -4,7 +4,7 @@ # Copyright (C) 2015 Kevin O'Connor kevin@koconnor.net # # This file may be distributed under the terms of the GNU GPLv3 license. -import sys, os, subprocess, time, socket, optparse +import sys, os, subprocess, shlex, time, socket, optparse VERSION_FORMAT = """ /* DO NOT EDIT! This is an autogenerated file. See scripts/buildversion.py. */ @@ -12,16 +12,24 @@ VERSION_FORMAT = """ #define BUILD_TOOLS "%s" """ +# Run program and return the specified output +def check_output(prog): + try: + process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE)
I suppose the old code has the same behaviour, but are you aware of: http:// www.chiark.greenend.org.uk/~cjwatson/blog/python-sigpipe.html ? (tl;dr: One may need to reset SIGPIPE in the child)
On Mon, Nov 09, 2015 at 03:24:13PM +0000, Ian Campbell wrote:
On Mon, 2015-11-09 at 09:33 -0500, Kevin O'Connor wrote:
Don't require python2.7 in buildversion.py. Also, ignore only those exceptions that are known to be possible.
Signed-off-by: Kevin O'Connor kevin@koconnor.net
scripts/buildversion.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-)
diff --git a/scripts/buildversion.py b/scripts/buildversion.py index d61fc9e..5b8807e 100755 --- a/scripts/buildversion.py +++ b/scripts/buildversion.py @@ -4,7 +4,7 @@ # Copyright (C) 2015 Kevin O'Connor kevin@koconnor.net # # This file may be distributed under the terms of the GNU GPLv3 license. -import sys, os, subprocess, time, socket, optparse +import sys, os, subprocess, shlex, time, socket, optparse VERSION_FORMAT = """ /* DO NOT EDIT! This is an autogenerated file. See scripts/buildversion.py. */ @@ -12,16 +12,24 @@ VERSION_FORMAT = """ #define BUILD_TOOLS "%s" """ +# Run program and return the specified output +def check_output(prog): + try: + process = subprocess.Popen(shlex.split(prog), stdout=subprocess.PIPE)
I suppose the old code has the same behaviour, but are you aware of: http:// www.chiark.greenend.org.uk/~cjwatson/blog/python-sigpipe.html ? (tl;dr: One may need to reset SIGPIPE in the child)
Interesting. This script only calls "git describe" and "prog --version" which both have very limited lifetimes, so I don't think it has an impact here.
Thanks, -Kevin
On 2015-11-09 14:33, Kevin O'Connor wrote:
Don't require python2.7 in buildversion.py. Also, ignore only those exceptions that are known to be possible.
I can confirm that works as expected my end, Kevin.
Thank you,
John.
On Tue, Nov 10, 2015 at 01:40:10PM +0000, John Lewis wrote:
On 2015-11-09 14:33, Kevin O'Connor wrote:
Don't require python2.7 in buildversion.py. Also, ignore only those exceptions that are known to be possible.
I can confirm that works as expected my end, Kevin.
Thanks. I pushed a slightly modified version of that patch, plus the debugging patch from yesterday to the master repo.
-Kevin
On 2015-11-11 15:36, Kevin O'Connor wrote:
On Tue, Nov 10, 2015 at 01:40:10PM +0000, John Lewis wrote:
On 2015-11-09 14:33, Kevin O'Connor wrote:
Don't require python2.7 in buildversion.py. Also, ignore only those exceptions that are known to be possible.
I can confirm that works as expected my end, Kevin.
Thanks. I pushed a slightly modified version of that patch, plus the debugging patch from yesterday to the master repo.
Yep, that builds and works as expected too.
John.