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 """ |
11 | 11 |
12 import os | 12 import os |
13 import re | 13 import re |
14 import subprocess | 14 import subprocess |
15 import sys | 15 import sys |
16 | 16 |
17 | 17 |
18 def GetVersion(compiler, tool): | 18 def GetVersion(compiler, tool): |
19 tool_output = tool_error = None | 19 tool_output = tool_error = None |
20 try: | 20 try: |
21 # Note that compiler could be something tricky like "distcc g++". | 21 # Note that compiler could be something tricky like "distcc g++". |
22 if tool == "compiler": | 22 if tool == "compiler": |
23 compiler = compiler + " -dumpversion" | 23 compiler = compiler + " -dumpversion" |
24 # 4.6 | 24 # 4.6 |
25 version_re = re.compile(r"(\d+)\.(\d+)") | 25 version_re = re.compile(r"(\d+)\.(\d+)") |
26 elif tool == "assembler": | 26 elif tool == "assembler": |
27 compiler = compiler + " -Xassembler --version -x assembler -c /dev/null" | 27 compiler = compiler + " -Xassembler --version -x assembler -c /dev/null" |
28 # GNU assembler (GNU Binutils for Ubuntu) 2.22 | 28 # Unmodified: GNU assembler (GNU Binutils) 2.24 |
29 version_re = re.compile(r"GNU [^ ]+ \(.*\) (\d+).(\d+)") | 29 # Ubuntu: GNU assembler (GNU Binutils for Ubuntu) 2.22 |
| 30 # Fedora: GNU assembler version 2.23.2 |
| 31 version_re = re.compile(r"^GNU [^ ]+ .* (\d+).(\d+).*?$", re.M) |
30 elif tool == "linker": | 32 elif tool == "linker": |
31 compiler = compiler + " -Xlinker --version" | 33 compiler = compiler + " -Xlinker --version" |
32 # GNU gold (GNU Binutils for Ubuntu 2.22) 1.11 | 34 # Using BFD linker |
33 version_re = re.compile(r"GNU [^ ]+ \(.*\) (\d+).(\d+)") | 35 # Unmodified: GNU ld (GNU Binutils) 2.24 |
| 36 # Ubuntu: GNU ld (GNU Binutils for Ubuntu) 2.22 |
| 37 # Fedora: GNU ld version 2.23.2 |
| 38 # Using Gold linker |
| 39 # Unmodified: GNU gold (GNU Binutils 2.24) 1.11 |
| 40 # Ubuntu: GNU gold (GNU Binutils for Ubuntu 2.22) 1.11 |
| 41 # Fedora: GNU gold (version 2.23.2) 1.11 |
| 42 version_re = re.compile(r"^GNU [^ ]+ .* (\d+).(\d+).*?$", re.M) |
34 else: | 43 else: |
35 raise Exception("Unknown tool %s" % tool) | 44 raise Exception("Unknown tool %s" % tool) |
36 | 45 |
37 pipe = subprocess.Popen(compiler, shell=True, | 46 pipe = subprocess.Popen(compiler, shell=True, |
38 stdout=subprocess.PIPE, stderr=subprocess.PIPE) | 47 stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
39 tool_output, tool_error = pipe.communicate() | 48 tool_output, tool_error = pipe.communicate() |
40 if pipe.returncode: | 49 if pipe.returncode: |
41 raise subprocess.CalledProcessError(pipe.returncode, compiler) | 50 raise subprocess.CalledProcessError(pipe.returncode, compiler) |
42 | 51 |
43 result = version_re.match(tool_output) | 52 result = version_re.match(tool_output) |
(...skipping 26 matching lines...) Expand all Loading... |
70 gccversion = GetVersion("g++", tool) | 79 gccversion = GetVersion("g++", tool) |
71 if gccversion != "": | 80 if gccversion != "": |
72 print gccversion | 81 print gccversion |
73 return 0 | 82 return 0 |
74 | 83 |
75 return 1 | 84 return 1 |
76 | 85 |
77 | 86 |
78 if __name__ == "__main__": | 87 if __name__ == "__main__": |
79 sys.exit(main(sys.argv[1:])) | 88 sys.exit(main(sys.argv[1:])) |
OLD | NEW |