aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/buildversion.py48
1 files changed, 23 insertions, 25 deletions
diff --git a/scripts/buildversion.py b/scripts/buildversion.py
index c3a83b0..bceae63 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, re
+import sys, os, subprocess, time, socket, optparse
VERSION_FORMAT = """
/* DO NOT EDIT! This is an autogenerated file. See scripts/buildversion.py. */
@@ -42,39 +42,37 @@ def write_version(outfile, version, toolstr):
f.write(VERSION_FORMAT % (version, toolstr))
f.close()
-re_gcc = re.compile(r'^(?P<prog>.*) \(GCC\) (?P<version>.*)$')
-re_binutils = re.compile(r'^GNU (?P<prog>.*) version (?P<version>.*)$')
-
# Run "tool --version" for each specified tool and extract versions
def tool_versions(tools):
tools = [t.strip() for t in tools.split(';')]
- gcc = binutils = ""
+ versions = ['', '']
success = 0
for tool in tools:
+ # Extract first line from "tool --version" output
try:
ver = subprocess.check_output([tool, '--version']).decode()
except:
continue
- ver = ver.split('\n')[0]
- m = re_gcc.match(ver)
- if m:
- ver = m.group('version')
- if gcc and gcc != ver:
- gcc = "mixed"
- continue
- gcc = ver
- success += 1
+ verstr = ver.split('\n')[0]
+ # Check if this tool looks like a binutils program
+ isbinutils = 0
+ if verstr.startswith('GNU '):
+ isbinutils = 1
+ verstr = verstr[4:]
+ # Extract version information and exclude program name
+ if ' ' not in verstr:
+ continue
+ prog, ver = verstr.split(' ', 1)
+ if not prog or not ver:
+ continue
+ # Check for any version conflicts
+ if versions[isbinutils] and versions[isbinutils] != ver:
+ vers[isbinutils] = "mixed"
continue
- m = re_binutils.match(ver)
- if m:
- ver = m.group('version')
- if binutils and binutils != ver:
- binutils = "mixed"
- continue
- binutils = ver
- success += 1
- cleanbuild = binutils and gcc and success == len(tools)
- return cleanbuild, "gcc: %s binutils: %s" % (gcc, binutils)
+ versions[isbinutils] = ver
+ success += 1
+ cleanbuild = versions[0] and versions[1] and success == len(tools)
+ return cleanbuild, "gcc: %s binutils: %s" % (versions[0], versions[1])
def main():
usage = "%prog [options] <outputheader.h>"
@@ -82,7 +80,7 @@ def main():
opts.add_option("-e", "--extra", dest="extra", default="",
help="extra version string to append to version")
opts.add_option("-t", "--tools", dest="tools", default="",
- help="list of build programs to extra version from")
+ help="list of build programs to extract version from")
options, args = opts.parse_args()
if len(args) != 1: