]> xenbits.xensource.com Git - seabios.git/commitdiff
build: Be more permissive in buildversion.py tool version scan
authorKevin O'Connor <kevin@koconnor.net>
Thu, 22 Oct 2015 00:35:50 +0000 (20:35 -0400)
committerKevin O'Connor <kevin@koconnor.net>
Thu, 22 Oct 2015 13:43:31 +0000 (09:43 -0400)
There is some variation in version strings between various tool chain
builds.  Make the version tool scan more permissive to attempt to
handle these variations.

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
scripts/buildversion.py

index c3a83b015ed73189d73e731c8e6df5355a82d4e8..bceae63d203ee45c90b74b929208e2185177ef61 100755 (executable)
@@ -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: