|
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. |
8 | 5 | # |
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 |
16 | 10 |
|
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 | +""" |
18 | 14 |
|
19 | 15 | 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 |
20 | 57 |
|
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 |
23 | 59 |
|
24 | | -execfile(os.path.join(chrome_src, 'build', 'compiler_version.py')) |
| 60 | +if __name__ == "__main__": |
| 61 | + sys.exit(main()) |
0 commit comments