1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/webrtc/trunk/build/compiler_version.py Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +#!/usr/bin/env python 1.5 +# Copyright (c) 2012 The Chromium Authors. All rights reserved. 1.6 +# Use of this source code is governed by a BSD-style license that can be 1.7 +# found in the LICENSE file. 1.8 + 1.9 +"""Compiler version checking tool for gcc 1.10 + 1.11 +Print gcc version as XY if you are running gcc X.Y.*. 1.12 +This is used to tweak build flags for gcc 4.4. 1.13 +""" 1.14 + 1.15 +import os 1.16 +import re 1.17 +import subprocess 1.18 +import sys 1.19 + 1.20 +def GetVersion(compiler): 1.21 + try: 1.22 + # Note that compiler could be something tricky like "distcc g++". 1.23 + compiler = compiler + " -dumpversion" 1.24 + pipe = subprocess.Popen(compiler, shell=True, 1.25 + stdout=subprocess.PIPE, stderr=subprocess.PIPE) 1.26 + gcc_output, gcc_error = pipe.communicate() 1.27 + if pipe.returncode: 1.28 + raise subprocess.CalledProcessError(pipe.returncode, compiler) 1.29 + 1.30 + result = re.match(r"(\d+)\.(\d+)", gcc_output) 1.31 + return result.group(1) + result.group(2) 1.32 + except Exception, e: 1.33 + if gcc_error: 1.34 + sys.stderr.write(gcc_error) 1.35 + print >> sys.stderr, "compiler_version.py failed to execute:", compiler 1.36 + print >> sys.stderr, e 1.37 + return "" 1.38 + 1.39 +def GetVersionFromEnvironment(compiler_env): 1.40 + """ Returns the version of compiler 1.41 + 1.42 + If the compiler was set by the given environment variable and exists, 1.43 + return its version, otherwise None is returned. 1.44 + """ 1.45 + cxx = os.getenv(compiler_env, None) 1.46 + if cxx: 1.47 + cxx_version = GetVersion(cxx) 1.48 + if cxx_version != "": 1.49 + return cxx_version 1.50 + return None 1.51 + 1.52 +def main(): 1.53 + # Check if CXX_target or CXX environment variable exists an if it does use 1.54 + # that compiler. 1.55 + # TODO: Fix ninja (see http://crbug.com/140900) instead and remove this code 1.56 + # In ninja's cross compile mode, the CXX_target is target compiler, while 1.57 + # the CXX is host. The CXX_target needs be checked first, though the target 1.58 + # and host compiler have different version, there seems no issue to use the 1.59 + # target compiler's version number as gcc_version in Android. 1.60 + cxx_version = GetVersionFromEnvironment("CXX_target") 1.61 + if cxx_version: 1.62 + print cxx_version 1.63 + return 0 1.64 + 1.65 + cxx_version = GetVersionFromEnvironment("CXX") 1.66 + if cxx_version: 1.67 + print cxx_version 1.68 + return 0 1.69 + 1.70 + # Otherwise we check the g++ version. 1.71 + gccversion = GetVersion("g++") 1.72 + if gccversion != "": 1.73 + print gccversion 1.74 + return 0 1.75 + 1.76 + return 1 1.77 + 1.78 +if __name__ == "__main__": 1.79 + sys.exit(main())