2011-11-23 23:13:44 +04:00
|
|
|
#!/usr/bin/env python
|
2012-05-07 21:24:49 +04:00
|
|
|
# Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
2009-11-03 20:32:10 +03:00
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
|
|
|
|
"""Compiler version checking tool for gcc
|
|
|
|
|
|
|
|
Print gcc version as XY if you are running gcc X.Y.*.
|
|
|
|
This is used to tweak build flags for gcc 4.4.
|
|
|
|
"""
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
|
|
|
|
def GetVersion(compiler):
|
|
|
|
try:
|
|
|
|
# Note that compiler could be something tricky like "distcc g++".
|
|
|
|
compiler = compiler + " -dumpversion"
|
2012-05-07 21:24:49 +04:00
|
|
|
pipe = subprocess.Popen(compiler, shell=True,
|
|
|
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
gcc_output, gcc_error = pipe.communicate()
|
|
|
|
if pipe.returncode:
|
|
|
|
raise subprocess.CalledProcessError(pipe.returncode, compiler)
|
|
|
|
|
2009-11-03 22:27:51 +03:00
|
|
|
result = re.match(r"(\d+)\.(\d+)", gcc_output)
|
2009-11-03 20:32:10 +03:00
|
|
|
return result.group(1) + result.group(2)
|
|
|
|
except Exception, e:
|
2012-05-07 21:24:49 +04:00
|
|
|
if gcc_error:
|
|
|
|
sys.stderr.write(gcc_error)
|
2009-11-03 20:32:10 +03:00
|
|
|
print >> sys.stderr, "compiler_version.py failed to execute:", compiler
|
|
|
|
print >> sys.stderr, e
|
|
|
|
return ""
|
|
|
|
|
2012-08-07 11:46:52 +04:00
|
|
|
def main():
|
2012-10-19 02:08:06 +04:00
|
|
|
# Check if CXX environment variable exists and
|
|
|
|
# if it does use that compiler.
|
|
|
|
cxx = os.getenv("CXX", None)
|
|
|
|
if cxx:
|
|
|
|
cxxversion = GetVersion(cxx)
|
|
|
|
if cxxversion != "":
|
|
|
|
print cxxversion
|
|
|
|
return 0
|
|
|
|
else:
|
|
|
|
# Otherwise we check the g++ version.
|
|
|
|
gccversion = GetVersion("g++")
|
|
|
|
if gccversion != "":
|
|
|
|
print gccversion
|
|
|
|
return 0
|
2009-11-03 20:32:10 +03:00
|
|
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
sys.exit(main())
|