Skip to content
This repository was archived by the owner on Apr 10, 2025. It is now read-only.

Commit e145cf1

Browse files
hillspcrowell
authored andcommitted
Fix compiler_version.py for single-digit compiler versions, including
gcc 5.
1 parent 4df68e2 commit e145cf1

File tree

2 files changed

+56
-18
lines changed

2 files changed

+56
-18
lines changed

build/README.pagespeed

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
The following files in this directory were copied from chromium's repository at
22
revision 256281 (https://src.chromium.org/svn/trunk/src/build/?p=256281).
33

4+
compiler_version.py (with local bugfix decribed at the top)
45
filename_rules.gypi
56
get_landmines.py
67
grit_action.gypi

build/compiler_version.py

Lines changed: 55 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,61 @@
1-
#!/usr/bin/python
2-
3-
# Copyright 2010 Google Inc.
4-
#
5-
# Licensed under the Apache License, Version 2.0 (the "License");
6-
# you may not use this file except in compliance with the License.
7-
# You may obtain a copy of the License at
1+
#!/usr/bin/env python
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
4+
# found in the LICENSE file.
85
#
9-
# http://www.apache.org/licenses/LICENSE-2.0
10-
#
11-
# Unless required by applicable law or agreed to in writing, software
12-
# distributed under the License is distributed on an "AS IS" BASIS,
13-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14-
# See the License for the specific language governing permissions and
15-
# limitations under the License.
6+
# This version contains a bugfix for the compiler returning a single digit
7+
# version number, as is the case for gcc 5.
8+
9+
"""Compiler version checking tool for gcc
1610
17-
# This script is wrapper for the Chromium version of compiler_version.py.
11+
Print gcc version as XY if you are running gcc X.Y.*.
12+
This is used to tweak build flags for gcc 4.4.
13+
"""
1814

1915
import os
16+
import re
17+
import subprocess
18+
import sys
19+
20+
def GetVersion(compiler):
21+
try:
22+
# Note that compiler could be something tricky like "distcc g++".
23+
compiler = compiler + " -dumpversion"
24+
pipe = subprocess.Popen(compiler, shell=True,
25+
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
26+
gcc_output, gcc_error = pipe.communicate()
27+
if pipe.returncode:
28+
raise subprocess.CalledProcessError(pipe.returncode, compiler)
29+
30+
result = re.match(r"(\d+)\.?(\d+)?", gcc_output)
31+
minor_version = result.group(2)
32+
if minor_version is None:
33+
minor_version = "0"
34+
return result.group(1) + minor_version
35+
except Exception, e:
36+
if gcc_error:
37+
sys.stderr.write(gcc_error)
38+
print >> sys.stderr, "compiler_version.py failed to execute:", compiler
39+
print >> sys.stderr, e
40+
return ""
41+
42+
def main():
43+
# Check if CXX environment variable exists and
44+
# if it does use that compiler.
45+
cxx = os.getenv("CXX", None)
46+
if cxx:
47+
cxxversion = GetVersion(cxx)
48+
if cxxversion != "":
49+
print cxxversion
50+
return 0
51+
else:
52+
# Otherwise we check the g++ version.
53+
gccversion = GetVersion("g++")
54+
if gccversion != "":
55+
print gccversion
56+
return 0
2057

21-
script_dir = os.path.dirname(__file__)
22-
chrome_src = os.path.normpath(os.path.join(script_dir, os.pardir, 'third_party', 'chromium', 'src'))
58+
return 1
2359

24-
execfile(os.path.join(chrome_src, 'build', 'compiler_version.py'))
60+
if __name__ == "__main__":
61+
sys.exit(main())

0 commit comments

Comments
 (0)