From dc8c929ed93eae2ba6a77500a1e6d2f0baa4e9e8 Mon Sep 17 00:00:00 2001 From: Mike Hommey Date: Fri, 23 Jun 2017 14:41:45 +0900 Subject: [PATCH] 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. --HG-- extra : rebase_source : 007257caecf7917480ef6b0a834c304768f77591 --- moz.configure | 10 +- .../mozbuild/test/configure/common.py | 9 ++ .../configure/test_toolchain_configure.py | 112 ++++++++++++++++++ 3 files changed, 126 insertions(+), 5 deletions(-) diff --git a/moz.configure b/moz.configure index 71cf01ec476b..fffba1f66eca 100755 --- a/moz.configure +++ b/moz.configure @@ -145,8 +145,8 @@ include('build/moz.configure/warnings.configure', 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' @@ -163,9 +163,9 @@ def library_name_info(target, is_windows, is_darwin, building_with_gcc, so_versi 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' diff --git a/python/mozbuild/mozbuild/test/configure/common.py b/python/mozbuild/mozbuild/test/configure/common.py index 478623a52f9a..1a3a19a3220e 100644 --- a/python/mozbuild/mozbuild/test/configure/common.py +++ b/python/mozbuild/mozbuild/test/configure/common.py @@ -219,6 +219,15 @@ class ConfigureTestSandbox(ConfigureSandbox): 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' diff --git a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py index 842cb91cf240..21fe0126b8b2 100644 --- a/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py +++ b/python/mozbuild/mozbuild/test/configure/test_toolchain_configure.py @@ -129,6 +129,10 @@ GCC_PLATFORM_WIN = { '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) @@ -240,6 +244,59 @@ CLANG_CL_3_9 = (CLANG_BASE('3.9.0') + VS('18.00.00000') + DEFAULT_C11 + 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): @@ -297,6 +354,44 @@ class BaseToolchainTest(BaseConfigureTest): (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 = { @@ -1270,5 +1365,22 @@ class OSXCrossToolchainTest(BaseToolchainTest): }) +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()