media/webrtc/trunk/build/compiler_version.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 3 # Use of this source code is governed by a BSD-style license that can be
michael@0 4 # found in the LICENSE file.
michael@0 5
michael@0 6 """Compiler version checking tool for gcc
michael@0 7
michael@0 8 Print gcc version as XY if you are running gcc X.Y.*.
michael@0 9 This is used to tweak build flags for gcc 4.4.
michael@0 10 """
michael@0 11
michael@0 12 import os
michael@0 13 import re
michael@0 14 import subprocess
michael@0 15 import sys
michael@0 16
michael@0 17 def GetVersion(compiler):
michael@0 18 try:
michael@0 19 # Note that compiler could be something tricky like "distcc g++".
michael@0 20 compiler = compiler + " -dumpversion"
michael@0 21 pipe = subprocess.Popen(compiler, shell=True,
michael@0 22 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
michael@0 23 gcc_output, gcc_error = pipe.communicate()
michael@0 24 if pipe.returncode:
michael@0 25 raise subprocess.CalledProcessError(pipe.returncode, compiler)
michael@0 26
michael@0 27 result = re.match(r"(\d+)\.(\d+)", gcc_output)
michael@0 28 return result.group(1) + result.group(2)
michael@0 29 except Exception, e:
michael@0 30 if gcc_error:
michael@0 31 sys.stderr.write(gcc_error)
michael@0 32 print >> sys.stderr, "compiler_version.py failed to execute:", compiler
michael@0 33 print >> sys.stderr, e
michael@0 34 return ""
michael@0 35
michael@0 36 def GetVersionFromEnvironment(compiler_env):
michael@0 37 """ Returns the version of compiler
michael@0 38
michael@0 39 If the compiler was set by the given environment variable and exists,
michael@0 40 return its version, otherwise None is returned.
michael@0 41 """
michael@0 42 cxx = os.getenv(compiler_env, None)
michael@0 43 if cxx:
michael@0 44 cxx_version = GetVersion(cxx)
michael@0 45 if cxx_version != "":
michael@0 46 return cxx_version
michael@0 47 return None
michael@0 48
michael@0 49 def main():
michael@0 50 # Check if CXX_target or CXX environment variable exists an if it does use
michael@0 51 # that compiler.
michael@0 52 # TODO: Fix ninja (see http://crbug.com/140900) instead and remove this code
michael@0 53 # In ninja's cross compile mode, the CXX_target is target compiler, while
michael@0 54 # the CXX is host. The CXX_target needs be checked first, though the target
michael@0 55 # and host compiler have different version, there seems no issue to use the
michael@0 56 # target compiler's version number as gcc_version in Android.
michael@0 57 cxx_version = GetVersionFromEnvironment("CXX_target")
michael@0 58 if cxx_version:
michael@0 59 print cxx_version
michael@0 60 return 0
michael@0 61
michael@0 62 cxx_version = GetVersionFromEnvironment("CXX")
michael@0 63 if cxx_version:
michael@0 64 print cxx_version
michael@0 65 return 0
michael@0 66
michael@0 67 # Otherwise we check the g++ version.
michael@0 68 gccversion = GetVersion("g++")
michael@0 69 if gccversion != "":
michael@0 70 print gccversion
michael@0 71 return 0
michael@0 72
michael@0 73 return 1
michael@0 74
michael@0 75 if __name__ == "__main__":
michael@0 76 sys.exit(main())

mercurial