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