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): |
| 37 """ Returns the version of compiler |
| 38 |
| 39 If the compiler was set by the given environment variable and exists, |
| 40 return its version, otherwise None is returned. |
| 41 """ |
| 42 cxx = os.getenv(compiler_env, None) |
| 43 if cxx: |
| 44 cxx_version = GetVersion(cxx) |
| 45 if cxx_version != "": |
| 46 return cxx_version |
| 47 return None |
| 48 |
36 def main(): | 49 def main(): |
37 # Check if CXX environment variable exists and | 50 # Check if CXX_target or CXX environment variable exists an if it does use |
38 # if it does use that compiler. | 51 # that compiler. |
39 cxx = os.getenv("CXX", None) | 52 # TODO: Fix ninja (see http://crbug.com/140900) instead and remove this code |
40 if cxx: | 53 # In ninja's cross compile mode, the CXX_target is target compiler, while |
41 cxxversion = GetVersion(cxx) | 54 # the CXX is host. The CXX_target needs be checked first, though the target |
42 if cxxversion != "": | 55 # and host compiler have different version, there seems no issue to use the |
43 print cxxversion | 56 # target compiler's version number as gcc_version in Android. |
44 return 0 | 57 cxx_version = GetVersionFromEnvironment("CXX_target") |
45 else: | 58 if cxx_version: |
46 # Otherwise we check the g++ version. | 59 print cxx_version |
47 gccversion = GetVersion("g++") | 60 return 0 |
48 if gccversion != "": | 61 |
49 print gccversion | 62 cxx_version = GetVersionFromEnvironment("CXX") |
50 return 0 | 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 |
51 | 72 |
52 return 1 | 73 return 1 |
53 | 74 |
54 if __name__ == "__main__": | 75 if __name__ == "__main__": |
55 sys.exit(main()) | 76 sys.exit(main()) |
OLD | NEW |