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. |
Nico
2012/08/06 19:03:03
Please file a bug (on crbug.com) about ninja getti
michaelbai
2012/08/06 20:50:35
Done.
| |
39 cxx = os.getenv("CXX", None) | 52 # In ninja's cross compile mode, the CXX_target is target compiler, while |
40 if cxx: | 53 # the CXX is host. The CXX_target needs be checked first, though the target |
41 cxxversion = GetVersion(cxx) | 54 # and host compiler have different version, there seems no issue to use the |
42 if cxxversion != "": | 55 # target compiler's version number as gcc_version in Android. |
43 print cxxversion | 56 cxx_version = GetVersionFromEnvironment("CXX_target") |
44 return 0 | 57 if cxx_version: |
45 else: | 58 print cxx_version |
46 # Otherwise we check the g++ version. | 59 return 0 |
47 gccversion = GetVersion("g++") | 60 |
48 if gccversion != "": | 61 cxx_version = GetVersionFromEnvironment("CXX") |
49 print gccversion | 62 if cxx_version: |
50 return 0 | 63 print cxx_version |
64 return 0 | |
65 | |
66 # Otherwise we check the g++ version. | |
67 gccversion = GetVersion("g++") | |
68 if gccversion != "": | |
69 print gccversion | |
70 return 0 | |
51 | 71 |
52 return 1 | 72 return 1 |
53 | 73 |
54 if __name__ == "__main__": | 74 if __name__ == "__main__": |
55 sys.exit(main()) | 75 sys.exit(main()) |
OLD | NEW |