Bug 1270446 - Simplify the fake compiler definitions. r=chmanchester
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 22 Apr 2016 13:39:06 +0900
changeset 296395 cc14a8472950cbc481c9baefac973865e45391b2
parent 296394 471bf0db284398af3ac4c83615e56ad22a0e2fe8
child 296396 c3573274d787f8477e3e7ee5f6287fb26da9f06a
push id30237
push userkwierso@gmail.com
push dateFri, 06 May 2016 22:41:28 +0000
treeherdermozilla-central@47bc46e92a73 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerschmanchester
bugs1270446
milestone49.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1270446 - Simplify the fake compiler definitions. r=chmanchester Originally, the changes to FakeCompiler allowing overlays was meant to be used for compiler target platform, but it turns out the simplifications this allows on the compiler definitions themselves are nice.
python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
--- a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
@@ -7,221 +7,136 @@ from __future__ import absolute_import, 
 import logging
 import os
 
 from StringIO import StringIO
 
 from mozunit import main
 
 from common import BaseConfigureTest
+from mozbuild.configure.util import Version
+from mozbuild.util import memoize
 from mozpack import path as mozpath
 from test_toolchain_helpers import FakeCompiler
 
 
-GCC_4_7 = FakeCompiler({
-    None: {
-        '__GNUC__': 4,
-        '__GNUC_MINOR__': 7,
-        '__GNUC_PATCHLEVEL__': 3,
-        '__STDC__': 1,
-    },
-    '-std=gnu99': {
-        '__STDC_VERSION__': '199901L',
-    },
-})
+DEFAULT_C99 = {
+    '__STDC_VERSION__': '199901L',
+}
+
+DEFAULT_C11 = {
+    '__STDC_VERSION__': '201112L',
+}
+
+DEFAULT_CXX_97 = {
+    '__cplusplus': '199711L',
+}
+
+DEFAULT_CXX_11 = {
+    '__cplusplus': '201103L',
+}
 
-GXX_4_7 = FakeCompiler({
-    None: {
-        '__GNUC__': 4,
-        '__GNUC_MINOR__': 7,
-        '__GNUC_PATCHLEVEL__': 3,
-        '__STDC__': 1,
-        '__cplusplus': '199711L',
-    },
-    '-std=gnu++11': {
-        '__cplusplus': '201103L',
-    },
-})
+SUPPORTS_GNU99 = {
+    '-std=gnu99': DEFAULT_C99,
+}
+
+SUPPORTS_GNUXX11 = {
+    '-std=gnu++11': DEFAULT_CXX_11,
+}
 
-GCC_4_9 = FakeCompiler({
-    None: {
-        '__GNUC__': 4,
-        '__GNUC_MINOR__': 9,
-        '__GNUC_PATCHLEVEL__': 3,
+
+@memoize
+def GCC_BASE(version):
+    version = Version(version)
+    return FakeCompiler({
+        '__GNUC__': version.major,
+        '__GNUC_MINOR__': version.minor,
+        '__GNUC_PATCHLEVEL__': version.patch,
         '__STDC__': 1,
-    },
-    '-std=gnu99': {
-        '__STDC_VERSION__': '199901L',
-    },
-})
+    })
+
 
-GXX_4_9 = FakeCompiler({
-    None: {
-        '__GNUC__': 4,
-        '__GNUC_MINOR__': 9,
-        '__GNUC_PATCHLEVEL__': 3,
-        '__STDC__': 1,
-        '__cplusplus': '199711L',
-    },
-    '-std=gnu++11': {
-        '__cplusplus': '201103L',
-    },
-})
+@memoize
+def GCC(version):
+    return GCC_BASE(version) + SUPPORTS_GNU99
 
-GCC_5 = FakeCompiler({
-    None: {
-        '__GNUC__': 5,
-        '__GNUC_MINOR__': 2,
-        '__GNUC_PATCHLEVEL__': 1,
-        '__STDC__': 1,
-        '__STDC_VERSION__': '201112L',
-    },
-    '-std=gnu99': {
-        '__STDC_VERSION__': '199901L',
-    },
-})
 
-GXX_5 = FakeCompiler({
-    None: {
-        '__GNUC__': 5,
-        '__GNUC_MINOR__': 2,
-        '__GNUC_PATCHLEVEL__': 1,
-        '__STDC__': 1,
-        '__cplusplus': '199711L',
-    },
-    '-std=gnu++11': {
-        '__cplusplus': '201103L',
-    },
-})
+@memoize
+def GXX(version):
+    return GCC_BASE(version) + DEFAULT_CXX_97 + SUPPORTS_GNUXX11
+
 
-CLANG_3_3 = FakeCompiler({
-    '__GNUC__': 4,
-    '__GNUC_MINOR__': 2,
-    '__GNUC_PATCHLEVEL__': 1,
-    '__clang__': 1,
-    '__clang_major__': 3,
-    '__clang_minor__': 3,
-    '__clang_patchlevel__': 0,
-    '__STDC__': 1,
-    '__STDC_VERSION__': '199901L',
-})
+GCC_4_7 = GCC('4.7.3')
+GXX_4_7 = GXX('4.7.3')
+GCC_4_9 = GCC('4.9.3')
+GXX_4_9 = GXX('4.9.3')
+GCC_5 = GCC('5.2.1') + DEFAULT_C11
+GXX_5 = GXX('5.2.1')
 
-CLANGXX_3_3 = FakeCompiler({
-    None: {
-        '__GNUC__': 4,
-        '__GNUC_MINOR__': 2,
-        '__GNUC_PATCHLEVEL__': 1,
+
+@memoize
+def CLANG_BASE(version):
+    version = Version(version)
+    return FakeCompiler({
         '__clang__': 1,
-        '__clang_major__': 3,
-        '__clang_minor__': 3,
-        '__clang_patchlevel__': 0,
-        '__STDC__': 1,
-        '__cplusplus': '199711L',
-    },
-    '-std=gnu++11': {
-        '__cplusplus': '201103L',
-    },
-})
+        '__clang_major__': version.major,
+        '__clang_minor__': version.minor,
+        '__clang_patchlevel__': version.patch,
+    })
+
+
+@memoize
+def CLANG(version):
+    return GCC_BASE('4.2.1') + CLANG_BASE(version) + SUPPORTS_GNU99
+
 
-CLANG_3_6 = FakeCompiler({
-    None: {
-        '__GNUC__': 4,
-        '__GNUC_MINOR__': 2,
-        '__GNUC_PATCHLEVEL__': 1,
-        '__clang__': 1,
-        '__clang_major__': 3,
-        '__clang_minor__': 6,
-        '__clang_patchlevel__': 2,
-        '__STDC__': 1,
-        '__STDC_VERSION__': '201112L',
-    },
-    '-std=gnu99': {
-        '__STDC_VERSION__': '199901L',
-    },
-})
+@memoize
+def CLANGXX(version):
+    return (GCC_BASE('4.2.1') + CLANG_BASE(version) + DEFAULT_CXX_97 +
+            SUPPORTS_GNUXX11)
+
 
-CLANGXX_3_6 = FakeCompiler({
-    None: {
-        '__GNUC__': 4,
-        '__GNUC_MINOR__': 2,
-        '__GNUC_PATCHLEVEL__': 1,
-        '__clang__': 1,
-        '__clang_major__': 3,
-        '__clang_minor__': 6,
-        '__clang_patchlevel__': 2,
-        '__STDC__': 1,
-        '__cplusplus': '199711L',
-    },
+CLANG_3_3 = CLANG('3.3.0') + DEFAULT_C99
+CLANGXX_3_3 = CLANGXX('3.3.0')
+CLANG_3_6 = CLANG('3.6.2') + DEFAULT_C11
+CLANGXX_3_6 = CLANGXX('3.6.2') + {
     '-std=gnu++11': {
-        '__cplusplus': '201103L',
         '__cpp_static_assert': '200410',
     },
-})
+}
 
-VS_2013u2 = FakeCompiler({
-    None: {
-        '_MSC_VER': '1800',
-        '_MSC_FULL_VER': '180030501',
-    },
-    '*.cpp': {
-        '__cplusplus': '199711L',
-    },
-})
-
-VS_2013u3 = FakeCompiler({
-    None: {
-        '_MSC_VER': '1800',
-        '_MSC_FULL_VER': '180030723',
-    },
-    '*.cpp': {
-        '__cplusplus': '199711L',
-    },
-})
 
-VS_2015 = FakeCompiler({
-    None: {
-        '_MSC_VER': '1900',
-        '_MSC_FULL_VER': '190023026',
-    },
-    '*.cpp': {
-        '__cplusplus': '199711L',
-    },
-})
+@memoize
+def VS(version):
+    version = Version(version)
+    return FakeCompiler({
+        None: {
+            '_MSC_VER': '%02d%02d' % (version.major, version.minor),
+            '_MSC_FULL_VER': '%02d%02d%05d' % (version.major, version.minor,
+                                               version.patch),
+        },
+        '*.cpp': DEFAULT_CXX_97,
+    })
 
-VS_2015u1 = FakeCompiler({
-    None: {
-        '_MSC_VER': '1900',
-        '_MSC_FULL_VER': '190023506',
-    },
-    '*.cpp': {
-        '__cplusplus': '199711L',
-    },
-})
 
-CLANG_CL = FakeCompiler({
-    None: {
-        '__clang__': 1,
-        '__clang_major__': 3,
-        '__clang_minor__': 9,
-        '__clang_patchlevel__': 0,
-        '__STDC_VERSION__': '201112L',
-        '_MSC_VER': '1800',
-        '_MSC_FULL_VER': '180000000',
-    },
-    '-std=gnu99': {  # In reality, the option needs to be preceded by -Xclang.
-        '__STDC_VERSION__': '199901L',
-    },
+VS_2013u2 = VS('18.00.30501')
+VS_2013u3 = VS('18.00.30723')
+VS_2015 = VS('19.00.23026')
+VS_2015u1 = VS('19.00.23506')
+
+# Note: In reality, the -std=gnu* options are only supported when preceded by
+# -Xclang.
+CLANG_CL_3_9 = (CLANG_BASE('3.9.0') + VS('18.00.00000') + DEFAULT_C11 +
+                SUPPORTS_GNU99 + SUPPORTS_GNUXX11) + {
     '*.cpp': {
         '__STDC_VERSION__': False,
         '__cplusplus': '201103L',
     },
-    '-fms-compatibility-version=18.00.30723': {
-        '_MSC_FULL_VER': '180030723',
-    },
-})
+    '-fms-compatibility-version=18.00.30723': VS('18.00.30723')[None],
+}
 
 
 class BaseToolchainTest(BaseConfigureTest):
     def setUp(self):
         super(BaseToolchainTest, self).setUp()
         self.out = StringIO()
         self.logger = logging.getLogger('BaseToolchainTest')
         self.logger.setLevel(logging.ERROR)
@@ -617,17 +532,17 @@ class WindowsToolchainTest(BaseToolchain
 
     # For the purpose of this test, it doesn't matter that the paths are not
     # real Windows paths.
     PATHS = {
         '/opt/VS_2013u2/bin/cl': VS_2013u2,
         '/opt/VS_2013u3/bin/cl': VS_2013u3,
         '/opt/VS_2015/bin/cl': VS_2015,
         '/usr/bin/cl': VS_2015u1,
-        '/usr/bin/clang-cl': CLANG_CL,
+        '/usr/bin/clang-cl': CLANG_CL_3_9,
     }
     PATHS.update(LinuxToolchainTest.PATHS)
 
     VS_2013u2_RESULT = (
         'This version (18.00.30501) of the MSVC compiler is not supported.\n'
         'You must install Visual C++ 2013 Update 3, Visual C++ 2015 Update 1, '
         'or newer in order to build.\n'
         'See https://developer.mozilla.org/en/Windows_Build_Prerequisites')
@@ -643,24 +558,24 @@ class WindowsToolchainTest(BaseToolchain
         'or newer in order to build.\n'
         'See https://developer.mozilla.org/en/Windows_Build_Prerequisites')
     VS_2015u1_RESULT = {
         'flags': [],
         'version': '19.00.23506',
         'type': 'msvc',
         'compiler': '/usr/bin/cl',
     }
-    CLANG_CL_RESULT = {
+    CLANG_CL_3_9_RESULT = {
         'flags': ['-Xclang', '-std=gnu99',
                   '-fms-compatibility-version=18.00.30723', '-fallback'],
         'version': '18.00.30723',
         'type': 'clang-cl',
         'compiler': '/usr/bin/clang-cl',
     }
-    CLANGXX_CL_RESULT = {
+    CLANGXX_CL_3_9_RESULT = {
         'flags': ['-fms-compatibility-version=18.00.30723', '-fallback'],
         'version': '18.00.30723',
         'type': 'clang-cl',
         'compiler': '/usr/bin/clang-cl',
     }
     CLANG_3_3_RESULT = LinuxToolchainTest.CLANG_3_3_RESULT
     CLANGXX_3_3_RESULT = LinuxToolchainTest.CLANGXX_3_3_RESULT
     CLANG_3_6_RESULT = LinuxToolchainTest.CLANG_3_6_RESULT
@@ -702,18 +617,18 @@ class WindowsToolchainTest(BaseToolchain
 
     def test_clang_cl(self):
         # We'll pick clang-cl if msvc can't be found.
         paths = {
             k: v for k, v in self.PATHS.iteritems()
             if os.path.basename(k) != 'cl'
         }
         self.do_toolchain_test(paths, {
-            'c_compiler': self.CLANG_CL_RESULT,
-            'cxx_compiler': self.CLANGXX_CL_RESULT,
+            'c_compiler': self.CLANG_CL_3_9_RESULT,
+            'cxx_compiler': self.CLANGXX_CL_3_9_RESULT,
         })
 
     def test_gcc(self):
         # We'll pick GCC if msvc and clang-cl can't be found.
         paths = {
             k: v for k, v in self.PATHS.iteritems()
             if os.path.basename(k) not in ('cl', 'clang-cl')
         }