diff options
author | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
---|---|---|
committer | Zeno Albisser <zeno.albisser@digia.com> | 2013-08-15 21:46:11 +0200 |
commit | 679147eead574d186ebf3069647b4c23e8ccace6 (patch) | |
tree | fc247a0ac8ff119f7c8550879ebb6d3dd8d1ff69 /chromium/build/compiler_version.py | |
download | qtwebengine-chromium-679147eead574d186ebf3069647b4c23e8ccace6.tar.gz |
Initial import.
Diffstat (limited to 'chromium/build/compiler_version.py')
-rwxr-xr-x | chromium/build/compiler_version.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/chromium/build/compiler_version.py b/chromium/build/compiler_version.py new file mode 100755 index 00000000000..b349199992c --- /dev/null +++ b/chromium/build/compiler_version.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python +# Copyright (c) 2012 The Chromium Authors. All rights reserved. +# 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" + 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) + + result = re.match(r"(\d+)\.(\d+)", gcc_output) + return result.group(1) + result.group(2) + except Exception, e: + if gcc_error: + sys.stderr.write(gcc_error) + print >> sys.stderr, "compiler_version.py failed to execute:", compiler + print >> sys.stderr, e + return "" + +def main(): + # 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 + + return 1 + +if __name__ == "__main__": + sys.exit(main()) |