Bug 1375798 - Add a unit test for library/object prefix/suffixes. r=mshal
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 23 Jun 2017 14:41:45 +0900
changeset 366524 0f78019d37dc9ca9caf778cd7e1a4091e2b5005d
parent 366523 400cc1535cb3923b6a16c4d88470248a2aea62f1
child 366525 9e83254e336b774bf009035178a836bc0500cc9c
push id92008
push usercbook@mozilla.com
push dateThu, 29 Jun 2017 13:50:12 +0000
treeherdermozilla-inbound@6e0dd1705c75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmshal
bugs1375798, 1372987
milestone56.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 1375798 - Add a unit test for library/object prefix/suffixes. r=mshal This happen to uncover the fact that mingw clang was not handled properly after bug 1372987. This will allow us to substantially modify the function that handles them and avoid regressions.
moz.configure
python/mozbuild/mozbuild/test/configure/common.py
python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
--- a/moz.configure
+++ b/moz.configure
@@ -140,37 +140,37 @@ include('build/moz.configure/memory.conf
         when='--enable-compile-environment')
 include('build/moz.configure/headers.configure',
         when='--enable-compile-environment')
 include('build/moz.configure/warnings.configure',
         when='--enable-compile-environment')
 
 option(env='SO_VERSION', nargs=1, help='Shared library version for OpenBSD systems')
 
-@depends(target, target_is_windows, target_is_darwin, building_with_gcc, 'SO_VERSION')
-def library_name_info(target, is_windows, is_darwin, building_with_gcc, so_version):
+@depends(target, target_is_windows, target_is_darwin, c_compiler, 'SO_VERSION')
+def library_name_info(target, is_windows, is_darwin, c_compiler, so_version):
     dll_prefix = 'lib'
     dll_suffix = '.so'
     lib_prefix = 'lib'
     lib_suffix = 'a'
     rust_lib_prefix = 'lib'
     rust_lib_suffix = 'a'
     obj_suffix = 'o'
     import_lib_suffix = ''
 
     if is_windows:
         dll_prefix = ''
         dll_suffix = '.dll'
 
         rust_lib_prefix = ''
         rust_lib_suffix = 'lib'
 
-        # It's OK if we're doing an artifact build and building_with_gcc is
-        # inaccurate.  Artifact builds with mingw ought to be pretty rare anyway.
-        if building_with_gcc:
+        # There aren't artifacts for mingw builds, so it's OK that the results
+        # are inaccurate in that case.
+        if c_compiler and c_compiler.type not in ('msvc', 'clang-cl'):
             import_lib_suffix = 'a'
         else:
             import_lib_suffix = 'lib'
             lib_prefix = ''
             lib_suffix = 'lib'
             obj_suffix = 'obj'
     elif is_darwin:
         dll_suffix = '.dylib'
--- a/python/mozbuild/mozbuild/test/configure/common.py
+++ b/python/mozbuild/mozbuild/test/configure/common.py
@@ -214,16 +214,25 @@ class ConfigureTestSandbox(ConfigureSand
         script = mozpath.abspath(args[0])
         if script in self._subprocess_paths:
             return self._subprocess_paths[script](stdin, args[1:])
         return 127, '', 'File not found'
 
     def vswhere(self, stdin, args):
         return 0, '[]', ''
 
+    def get_config(self, name):
+        # Like the loop in ConfigureSandbox.run, but only execute the code
+        # associated with the given config item.
+        for func, args in self._execution_queue:
+            if (func == self._resolve_and_set and args[0] is self._config
+                    and args[1] == name):
+                func(*args)
+                return self._config.get(name)
+
 
 class BaseConfigureTest(unittest.TestCase):
     HOST = 'x86_64-pc-linux-gnu'
 
     def setUp(self):
         self._cwd = os.getcwd()
         os.chdir(topobjdir)
 
--- a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
+++ b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py
@@ -124,16 +124,20 @@ GCC_PLATFORM_DARWIN = {
     '__APPLE__': 1,
 }
 
 GCC_PLATFORM_WIN = {
     '_WIN32': 1,
     'WINNT': 1,
 }
 
+GCC_PLATFORM_OPENBSD = {
+    '__OpenBSD__': 1,
+}
+
 GCC_PLATFORM_X86_LINUX = FakeCompiler(GCC_PLATFORM_X86, GCC_PLATFORM_LINUX)
 GCC_PLATFORM_X86_64_LINUX = FakeCompiler(GCC_PLATFORM_X86_64,
                                          GCC_PLATFORM_LINUX)
 GCC_PLATFORM_ARM_LINUX = FakeCompiler(GCC_PLATFORM_ARM, GCC_PLATFORM_LINUX)
 GCC_PLATFORM_X86_OSX = FakeCompiler(GCC_PLATFORM_X86, GCC_PLATFORM_DARWIN)
 GCC_PLATFORM_X86_64_OSX = FakeCompiler(GCC_PLATFORM_X86_64,
                                        GCC_PLATFORM_DARWIN)
 GCC_PLATFORM_X86_WIN = FakeCompiler(GCC_PLATFORM_X86, GCC_PLATFORM_WIN)
@@ -235,16 +239,69 @@ CLANG_CL_3_9 = (CLANG_BASE('3.9.0') + VS
         '__cplusplus': '201103L',
     },
     '-fms-compatibility-version=19.00.24213': VS('19.00.24213')[None],
 }
 
 CLANG_CL_PLATFORM_X86 = FakeCompiler(VS_PLATFORM_X86, GCC_PLATFORM_X86[None])
 CLANG_CL_PLATFORM_X86_64 = FakeCompiler(VS_PLATFORM_X86_64, GCC_PLATFORM_X86_64[None])
 
+LIBRARY_NAME_INFOS = {
+    'linux-gnu': {
+        'DLL_PREFIX': 'lib',
+        'DLL_SUFFIX': '.so',
+        'LIB_PREFIX': 'lib',
+        'LIB_SUFFIX': 'a',
+        'IMPORT_LIB_SUFFIX': '',
+        'RUST_LIB_PREFIX': 'lib',
+        'RUST_LIB_SUFFIX': 'a',
+        'OBJ_SUFFIX': 'o',
+    },
+    'darwin11.2.0': {
+        'DLL_PREFIX': 'lib',
+        'DLL_SUFFIX': '.dylib',
+        'LIB_PREFIX': 'lib',
+        'LIB_SUFFIX': 'a',
+        'IMPORT_LIB_SUFFIX': '',
+        'RUST_LIB_PREFIX': 'lib',
+        'RUST_LIB_SUFFIX': 'a',
+        'OBJ_SUFFIX': 'o',
+    },
+    'mingw32': {
+        'DLL_PREFIX': '',
+        'DLL_SUFFIX': '.dll',
+        'LIB_PREFIX': 'lib',
+        'LIB_SUFFIX': 'a',
+        'IMPORT_LIB_SUFFIX': 'a',
+        'RUST_LIB_PREFIX': '',
+        'RUST_LIB_SUFFIX': 'lib',
+        'OBJ_SUFFIX': 'o',
+    },
+    'msvc': {
+        'DLL_PREFIX': '',
+        'DLL_SUFFIX': '.dll',
+        'LIB_PREFIX': '',
+        'LIB_SUFFIX': 'lib',
+        'IMPORT_LIB_SUFFIX': 'lib',
+        'RUST_LIB_PREFIX': '',
+        'RUST_LIB_SUFFIX': 'lib',
+        'OBJ_SUFFIX': 'obj',
+    },
+    'openbsd6.1': {
+        'DLL_PREFIX': 'lib',
+        'DLL_SUFFIX': '.so.1.0',
+        'LIB_PREFIX': 'lib',
+        'LIB_SUFFIX': 'a',
+        'IMPORT_LIB_SUFFIX': '',
+        'RUST_LIB_PREFIX': 'lib',
+        'RUST_LIB_SUFFIX': 'a',
+        'OBJ_SUFFIX': 'o',
+    },
+}
+
 
 class BaseToolchainTest(BaseConfigureTest):
     def setUp(self):
         super(BaseToolchainTest, self).setUp()
         self.out = StringIO()
         self.logger = logging.getLogger('BaseToolchainTest')
         self.logger.setLevel(logging.ERROR)
         self.handler = logging.StreamHandler(self.out)
@@ -292,16 +349,54 @@ class BaseToolchainTest(BaseConfigureTes
                 # Add var on both ends to make it clear which of the
                 # variables is failing the test when that happens.
                 self.assertEquals((var, compiler), (var, result))
             except SystemExit:
                 self.assertEquals((var, result),
                                   (var, self.out.getvalue().strip()))
                 return
 
+        # Normalize the target os to match what we have as keys in
+        # LIBRARY_NAME_INFOS.
+        target_os = getattr(self, 'TARGET', self.HOST).split('-', 2)[2]
+        if target_os == 'mingw32':
+            compiler_type = sandbox._value_for(sandbox['c_compiler']).type
+            if compiler_type in ('msvc', 'clang-cl'):
+                target_os = 'msvc'
+        elif target_os == 'linux-gnuabi64':
+            target_os = 'linux-gnu'
+
+        self.do_library_name_info_test(target_os, sandbox)
+
+        # Try again on artifact builds. In that case, we always get library
+        # name info for msvc on Windows
+        if target_os == 'mingw32':
+            target_os = 'msvc'
+
+        sandbox = self.get_sandbox(
+            paths, {}, args + ['--enable-artifact-builds'], environ,
+            logger=self.logger)
+
+        self.do_library_name_info_test(target_os, sandbox)
+
+    def do_library_name_info_test(self, target_os, sandbox):
+        library_name_info = LIBRARY_NAME_INFOS[target_os]
+        for k in (
+            'DLL_PREFIX',
+            'DLL_SUFFIX',
+            'LIB_PREFIX',
+            'LIB_SUFFIX',
+            'IMPORT_LIB_SUFFIX',
+            'RUST_LIB_PREFIX',
+            'RUST_LIB_SUFFIX',
+            'OBJ_SUFFIX',
+        ):
+            self.assertEquals('%s=%s' % (k, sandbox.get_config(k)),
+                              '%s=%s' % (k, library_name_info[k]))
+
 
 class LinuxToolchainTest(BaseToolchainTest):
     PATHS = {
         '/usr/bin/gcc': GCC_4_9 + GCC_PLATFORM_X86_64_LINUX,
         '/usr/bin/g++': GXX_4_9 + GCC_PLATFORM_X86_64_LINUX,
         '/usr/bin/gcc-4.7': GCC_4_7 + GCC_PLATFORM_X86_64_LINUX,
         '/usr/bin/g++-4.7': GXX_4_7 + GCC_PLATFORM_X86_64_LINUX,
         '/usr/bin/gcc-5': GCC_5 + GCC_PLATFORM_X86_64_LINUX,
@@ -1265,10 +1360,27 @@ class OSXCrossToolchainTest(BaseToolchai
         self.do_toolchain_test(self.PATHS, {
             'c_compiler': 'Target C compiler target kernel (Linux) does not '
                           'match --target kernel (Darwin)',
         }, environ={
             'CC': 'gcc',
         })
 
 
+class OpenBSDToolchainTest(BaseToolchainTest):
+    HOST = 'x86_64-unknown-openbsd6.1'
+    TARGET = 'x86_64-unknown-openbsd6.1'
+    PATHS = {
+        '/usr/bin/gcc': GCC_4_9 + GCC_PLATFORM_X86_64 + GCC_PLATFORM_OPENBSD,
+        '/usr/bin/g++': GXX_4_9 + GCC_PLATFORM_X86_64 + GCC_PLATFORM_OPENBSD,
+    }
+    GCC_4_9_RESULT = LinuxToolchainTest.GCC_4_9_RESULT
+    GXX_4_9_RESULT = LinuxToolchainTest.GXX_4_9_RESULT
+
+    def test_gcc(self):
+        self.do_toolchain_test(self.PATHS, {
+            'c_compiler': self.GCC_4_9_RESULT,
+            'cxx_compiler': self.GXX_4_9_RESULT,
+        })
+
+
 if __name__ == '__main__':
     main()