Disable tests broken on WinXP Tests(1) only.
[chromium-blink-merge.git] / build / compiler_version.py
blobb06712d25b2d3c25990a97f99a630a66c703ce0b
1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
6 """Compiler version checking tool for gcc
8 Print gcc version as XY if you are running gcc X.Y.*.
9 This is used to tweak build flags for gcc 4.4.
10 """
12 import os
13 import re
14 import subprocess
15 import sys
18 def GetVersion(compiler, tool):
19 tool_output = tool_error = None
20 try:
21 # Note that compiler could be something tricky like "distcc g++".
22 if tool == "compiler":
23 compiler = compiler + " -dumpversion"
24 # 4.6
25 version_re = re.compile(r"(\d+)\.(\d+)")
26 elif tool == "assembler":
27 compiler = compiler + " -Xassembler --version -x assembler -c /dev/null"
28 # Unmodified: GNU assembler (GNU Binutils) 2.24
29 # Ubuntu: GNU assembler (GNU Binutils for Ubuntu) 2.22
30 # Fedora: GNU assembler version 2.23.2
31 version_re = re.compile(r"^GNU [^ ]+ .* (\d+).(\d+).*?$", re.M)
32 elif tool == "linker":
33 compiler = compiler + " -Xlinker --version"
34 # Using BFD linker
35 # Unmodified: GNU ld (GNU Binutils) 2.24
36 # Ubuntu: GNU ld (GNU Binutils for Ubuntu) 2.22
37 # Fedora: GNU ld version 2.23.2
38 # Using Gold linker
39 # Unmodified: GNU gold (GNU Binutils 2.24) 1.11
40 # Ubuntu: GNU gold (GNU Binutils for Ubuntu 2.22) 1.11
41 # Fedora: GNU gold (version 2.23.2) 1.11
42 version_re = re.compile(r"^GNU [^ ]+ .* (\d+).(\d+).*?$", re.M)
43 else:
44 raise Exception("Unknown tool %s" % tool)
46 pipe = subprocess.Popen(compiler, shell=True,
47 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
48 tool_output, tool_error = pipe.communicate()
49 if pipe.returncode:
50 raise subprocess.CalledProcessError(pipe.returncode, compiler)
52 result = version_re.match(tool_output)
53 return result.group(1) + result.group(2)
54 except Exception, e:
55 if tool_error:
56 sys.stderr.write(tool_error)
57 print >> sys.stderr, "compiler_version.py failed to execute:", compiler
58 print >> sys.stderr, e
59 return ""
62 def main(args):
63 tool = "compiler"
64 if len(args) == 1:
65 tool = args[0]
66 elif len(args) > 1:
67 print "Unknown arguments!"
69 # Check if CXX environment variable exists and
70 # if it does use that compiler.
71 cxx = os.getenv("CXX", None)
72 if cxx:
73 cxxversion = GetVersion(cxx, tool)
74 if cxxversion != "":
75 print cxxversion
76 return 0
77 else:
78 # Otherwise we check the g++ version.
79 gccversion = GetVersion("g++", tool)
80 if gccversion != "":
81 print gccversion
82 return 0
84 return 1
87 if __name__ == "__main__":
88 sys.exit(main(sys.argv[1:]))