chromeos: bluetooth: add BluetoothInputClient
[chromium-blink-merge.git] / build / compiler_version.py
blob9132261faea1bee8db7c5f5ac6b2af3d22bec029
1 #!/usr/bin/env python
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.
10 """
12 import os
13 import re
14 import subprocess
15 import sys
17 def GetVersion(compiler):
18 try:
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)
25 except Exception, e:
26 print >> sys.stderr, "compiler_version.py failed to execute:", compiler
27 print >> sys.stderr, e
28 return ""
30 def main():
31 # Check if CXX environment variable exists and
32 # if it does use that compiler.
33 cxx = os.getenv("CXX", None)
34 if cxx:
35 cxxversion = GetVersion(cxx)
36 if cxxversion != "":
37 print cxxversion
38 return 0
39 else:
40 # Otherwise we check the g++ version.
41 gccversion = GetVersion("g++")
42 if gccversion != "":
43 print gccversion
44 return 0
46 return 1
48 if __name__ == "__main__":
49 sys.exit(main())