2 # Copyright (c) 2011 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.
17 def GetVersion(compiler
):
19 # Note that compiler could be something tricky like "distcc g++".
20 compiler
= compiler
+ " -dumpversion"
21 pipe
= subprocess
.Popen(compiler
, stdout
=subprocess
.PIPE
, shell
=True)
22 gcc_output
= pipe
.communicate()[0]
23 result
= re
.match(r
"(\d+)\.(\d+)", gcc_output
)
24 return result
.group(1) + result
.group(2)
26 print >> sys
.stderr
, "compiler_version.py failed to execute:", compiler
27 print >> sys
.stderr
, e
31 # Check if CXX environment variable exists and
32 # if it does use that compiler.
33 cxx
= os
.getenv("CXX", None)
35 cxxversion
= GetVersion(cxx
)
40 # Otherwise we check the g++ version.
41 gccversion
= GetVersion("g++")
48 if __name__
== "__main__":