Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(307)

Side by Side Diff: build/compiler_version.py

Issue 1577093002: Remove gcc_version from gyp and gn files. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: moar Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « build/common.gypi ('k') | build/config/compiler/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 14 matching lines...) Expand all
25 return 1 25 return 1
26 26
27 27
28 def ParseArgs(args): 28 def ParseArgs(args):
29 if len(args) != 2: 29 if len(args) != 2:
30 raise Exception('Invalid number of arguments') 30 raise Exception('Invalid number of arguments')
31 mode = args[0] 31 mode = args[0]
32 tool = args[1] 32 tool = args[1]
33 if mode not in ('host', 'target'): 33 if mode not in ('host', 'target'):
34 raise Exception('Invalid mode: %s' % mode) 34 raise Exception('Invalid mode: %s' % mode)
35 if tool not in ('assembler', 'compiler', 'linker'): 35 if tool not in ('assembler',):
Nico 2016/01/11 21:05:53 There's one call to this left in the gyp build to
36 raise Exception('Invalid tool: %s' % tool) 36 raise Exception('Invalid tool: %s' % tool)
37 return mode, tool 37 return mode, tool
38 38
39 39
40 def GetEnvironFallback(var_list, default): 40 def GetEnvironFallback(var_list, default):
41 """Look up an environment variable from a possible list of variable names.""" 41 """Look up an environment variable from a possible list of variable names."""
42 for var in var_list: 42 for var in var_list:
43 if var in os.environ: 43 if var in os.environ:
44 return os.environ[var] 44 return os.environ[var]
45 return default 45 return default
46 46
47 47
48 def GetVersion(compiler, tool): 48 def GetVersion(compiler, tool):
49 tool_output = tool_error = None 49 tool_output = tool_error = None
50 cache_key = (compiler, tool) 50 cache_key = (compiler, tool)
51 cached_version = compiler_version_cache.get(cache_key) 51 cached_version = compiler_version_cache.get(cache_key)
52 if cached_version: 52 if cached_version:
53 return cached_version 53 return cached_version
54 try: 54 try:
55 # Note that compiler could be something tricky like "distcc g++". 55 # Note that compiler could be something tricky like "distcc g++".
56 if tool == "compiler": 56 if tool == "assembler":
57 compiler = compiler + " -dumpversion"
58 # 4.6
59 version_re = re.compile(r"(\d+)\.(\d+)")
60 elif tool == "assembler":
61 compiler = compiler + " -Xassembler --version -x assembler -c /dev/null" 57 compiler = compiler + " -Xassembler --version -x assembler -c /dev/null"
62 # Unmodified: GNU assembler (GNU Binutils) 2.24 58 # Unmodified: GNU assembler (GNU Binutils) 2.24
63 # Ubuntu: GNU assembler (GNU Binutils for Ubuntu) 2.22 59 # Ubuntu: GNU assembler (GNU Binutils for Ubuntu) 2.22
64 # Fedora: GNU assembler version 2.23.2 60 # Fedora: GNU assembler version 2.23.2
65 version_re = re.compile(r"^GNU [^ ]+ .* (\d+).(\d+).*?$", re.M) 61 version_re = re.compile(r"^GNU [^ ]+ .* (\d+).(\d+).*?$", re.M)
66 elif tool == "linker":
67 compiler = compiler + " -Xlinker --version"
68 # Using BFD linker
69 # Unmodified: GNU ld (GNU Binutils) 2.24
70 # Ubuntu: GNU ld (GNU Binutils for Ubuntu) 2.22
71 # Fedora: GNU ld version 2.23.2
72 # Using Gold linker
73 # Unmodified: GNU gold (GNU Binutils 2.24) 1.11
74 # Ubuntu: GNU gold (GNU Binutils for Ubuntu 2.22) 1.11
75 # Fedora: GNU gold (version 2.23.2) 1.11
76 version_re = re.compile(r"^GNU [^ ]+ .* (\d+).(\d+).*?$", re.M)
77 else: 62 else:
78 raise Exception("Unknown tool %s" % tool) 63 raise Exception("Unknown tool %s" % tool)
79 64
80 # Force the locale to C otherwise the version string could be localized 65 # Force the locale to C otherwise the version string could be localized
81 # making regex matching fail. 66 # making regex matching fail.
82 env = os.environ.copy() 67 env = os.environ.copy()
83 env["LC_ALL"] = "C" 68 env["LC_ALL"] = "C"
84 pipe = subprocess.Popen(compiler, shell=True, env=env, 69 pipe = subprocess.Popen(compiler, shell=True, env=env,
85 stdout=subprocess.PIPE, stderr=subprocess.PIPE) 70 stdout=subprocess.PIPE, stderr=subprocess.PIPE)
86 tool_output, tool_error = pipe.communicate() 71 tool_output, tool_error = pipe.communicate()
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 119
135 if compiler: 120 if compiler:
136 compiler_version = GetVersion(compiler, tool) 121 compiler_version = GetVersion(compiler, tool)
137 if compiler_version != "": 122 if compiler_version != "":
138 return (0, compiler_version) 123 return (0, compiler_version)
139 return (1, None) 124 return (1, None)
140 125
141 126
142 if __name__ == "__main__": 127 if __name__ == "__main__":
143 sys.exit(main(sys.argv)) 128 sys.exit(main(sys.argv))
OLDNEW
« no previous file with comments | « build/common.gypi ('k') | build/config/compiler/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698