mirror of
https://github.com/Dasharo/SeaBIOS.git
synced 2026-03-06 14:47:42 -08:00
buildversion: Avoid subprocess.check_output() as that requires python2.7
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>
This commit is contained in:
+19
-13
@@ -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,26 @@ 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 ""
|
||||
if retcode:
|
||||
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 +42,7 @@ def file_version():
|
||||
f = open('.version', 'r')
|
||||
ver = f.readline().strip()
|
||||
f.close()
|
||||
except:
|
||||
except OSError:
|
||||
return ""
|
||||
return ver
|
||||
|
||||
@@ -50,11 +60,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 '):
|
||||
|
||||
Reference in New Issue
Block a user