summaryrefslogtreecommitdiffstats
path: root/build/compiler_version.py
diff options
context:
space:
mode:
authorcraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 17:32:10 +0000
committercraig.schlenter@chromium.org <craig.schlenter@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-11-03 17:32:10 +0000
commit242a9e626cb6efee738d71849023f804dc6b5bde (patch)
tree475486fd3aec35f33aa1d33d0014f6b309d790c8 /build/compiler_version.py
parentb01a36d473f5b6ba23f4566b3ee4e9144b362de9 (diff)
downloadchromium_src-242a9e626cb6efee738d71849023f804dc6b5bde.zip
chromium_src-242a9e626cb6efee738d71849023f804dc6b5bde.tar.gz
chromium_src-242a9e626cb6efee738d71849023f804dc6b5bde.tar.bz2
Linux: Autodetect and change build flags when using gcc 4.4.
This runs g++ -dumpversion (or $CXX) to establish the compiler version and set the gyp gcc_version variable automatically. BUG=25209 Review URL: http://codereview.chromium.org/339046 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'build/compiler_version.py')
-rwxr-xr-xbuild/compiler_version.py50
1 files changed, 50 insertions, 0 deletions
diff --git a/build/compiler_version.py b/build/compiler_version.py
new file mode 100755
index 0000000..5eb467c
--- /dev/null
+++ b/build/compiler_version.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+
+# Copyright (c) 2009 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Compiler version checking tool for gcc
+
+Print gcc version as XY if you are running gcc X.Y.*.
+This is used to tweak build flags for gcc 4.4.
+"""
+
+import os
+import re
+import subprocess
+import sys
+
+def GetVersion(compiler):
+ try:
+ # Note that compiler could be something tricky like "distcc g++".
+ compiler = compiler + " -dumpversion"
+ pipe = subprocess.Popen(compiler, stdout=subprocess.PIPE, shell=True)
+ gcc_output = pipe.communicate()[0]
+ result = re.match(r"(\d+)\.(\d+)\..*", gcc_output)
+ return result.group(1) + result.group(2)
+ except Exception, e:
+ print >> sys.stderr, "compiler_version.py failed to execute:", compiler
+ print >> sys.stderr, e
+ return ""
+
+def main():
+ # Check if CXX environment variable exists and
+ # if it does use that compiler.
+ cxx = os.getenv("CXX", None)
+ if cxx:
+ cxxversion = GetVersion(cxx)
+ if cxxversion != "":
+ print cxxversion
+ return 0
+ else:
+ # Otherwise we check the g++ version.
+ gccversion = GetVersion("g++")
+ if gccversion != "":
+ print gccversion
+ return 0
+
+ return 1
+
+if __name__ == "__main__":
+ sys.exit(main())