Bug 1375798 - Reorganize the library_name_info function. r=mshal
authorMike Hommey <mh+mozilla@glandium.org>
Fri, 23 Jun 2017 15:05:06 +0900
changeset 405574 374900b2142af725d4136758ac00dce2fbb824be
parent 405573 9e83254e336b774bf009035178a836bc0500cc9c
child 405575 8847981eee44dd2790d6628a1e791269696f015a
push id58
push userfmarier@mozilla.com
push dateThu, 06 Jul 2017 00:08:44 +0000
reviewersmshal
bugs1375798
milestone56.0a1
Bug 1375798 - Reorganize the library_name_info function. r=mshal The function as it currently is matches how things were done in old-configure.in. However, that's just confusing and hard to follow. In fact, the unit test failing numerous times while writing this patch pretty much highlights the problem. So instead of a confusing set of overrides to the prefixes and suffixes, spell out the whole set for each set of platforms. This also happens to make the function shorter. Win/win. At the same time, we normalize the function output as a nested namespace, where we get, for each of dll, lib, import_lib, etc. a prefix/suffix pair. Further down the road, we can imagine changing those to class instances with a method allowing to format file names based on those prefix/suffixes.
moz.configure
toolkit/moz.configure
--- a/moz.configure
+++ b/moz.configure
@@ -151,76 +151,68 @@ option(env='SO_VERSION', nargs=1, defaul
        help='Shared library version for OpenBSD systems')
 
 @depends('SO_VERSION', when=is_openbsd)
 def so_version(value):
     return value
 
 @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'
-
         # 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'
+            return namespace(
+                dll=namespace(prefix='', suffix='.dll'),
+                lib=namespace(prefix='lib', suffix='a'),
+                import_lib=namespace(prefix='lib', suffix='a'),
+                rust_lib=namespace(prefix='', suffix='lib'),
+                obj=namespace(prefix='', suffix='o'),
+            )
+
+        return namespace(
+            dll=namespace(prefix='', suffix='.dll'),
+            lib=namespace(prefix='', suffix='lib'),
+            import_lib=namespace(prefix='', suffix='lib'),
+            rust_lib=namespace(prefix='', suffix='lib'),
+            obj=namespace(prefix='', suffix='obj'),
+        )
+
     elif is_darwin:
-        dll_suffix = '.dylib'
+        return namespace(
+            dll=namespace(prefix='lib', suffix='.dylib'),
+            lib=namespace(prefix='lib', suffix='a'),
+            import_lib=namespace(prefix=None, suffix=''),
+            rust_lib=namespace(prefix='lib', suffix='a'),
+            obj=namespace(prefix='', suffix='o'),
+        )
     elif so_version:
-        dll_suffix = '.so.%s' % so_version
-
-    assert dll_suffix[0] == '.'
-    assert obj_suffix[0] != '.'
-    assert lib_suffix[0] != '.'
-    assert rust_lib_suffix[0] != '.'
+        so = '.so.%s' % so_version
+    else:
+        so = '.so'
 
     return namespace(
-        dll_prefix=dll_prefix,
-        dll_suffix=dll_suffix,
-
-        lib_prefix=lib_prefix,
-        lib_suffix=lib_suffix,
-
-        rust_lib_prefix=rust_lib_prefix,
-        rust_lib_suffix=rust_lib_suffix,
-
-        obj_suffix=obj_suffix,
-        import_lib_suffix=import_lib_suffix,
+        dll=namespace(prefix='lib', suffix=so),
+        lib=namespace(prefix='lib', suffix='a'),
+        import_lib=namespace(prefix=None, suffix=''),
+        rust_lib=namespace(prefix='lib', suffix='a'),
+        obj=namespace(prefix='', suffix='o'),
     )
 
-set_config('DLL_PREFIX', library_name_info.dll_prefix)
-set_config('DLL_SUFFIX', library_name_info.dll_suffix)
-set_config('LIB_PREFIX', library_name_info.lib_prefix)
-set_config('LIB_SUFFIX', library_name_info.lib_suffix)
-set_config('RUST_LIB_PREFIX', library_name_info.rust_lib_prefix)
-set_config('RUST_LIB_SUFFIX', library_name_info.rust_lib_suffix)
-set_config('OBJ_SUFFIX', library_name_info.obj_suffix)
+set_config('DLL_PREFIX', library_name_info.dll.prefix)
+set_config('DLL_SUFFIX', library_name_info.dll.suffix)
+set_config('LIB_PREFIX', library_name_info.lib.prefix)
+set_config('LIB_SUFFIX', library_name_info.lib.suffix)
+set_config('RUST_LIB_PREFIX', library_name_info.rust_lib.prefix)
+set_config('RUST_LIB_SUFFIX', library_name_info.rust_lib.suffix)
+set_config('OBJ_SUFFIX', library_name_info.obj.suffix)
 # Lots of compilation tests depend on this variable being present.
-add_old_configure_assignment('OBJ_SUFFIX', library_name_info.obj_suffix)
-set_config('IMPORT_LIB_SUFFIX', library_name_info.import_lib_suffix)
-set_define('MOZ_DLL_SUFFIX', depends(library_name_info)(lambda lni: '"%s"' % lni.dll_suffix))
+add_old_configure_assignment('OBJ_SUFFIX', library_name_info.obj.suffix)
+set_config('IMPORT_LIB_SUFFIX', library_name_info.import_lib.suffix)
+set_define('MOZ_DLL_SUFFIX', depends(library_name_info.dll.suffix)(lambda s: '"%s"' % s))
 
 include(include_project_configure)
 
 @depends('--help')
 @imports(_from='mozbuild.backend', _import='backends')
 def build_backends_choices(_):
     return tuple(backends)
 
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -703,18 +703,18 @@ with only_when(building_stylo_bindgen):
                              library_name_info, host):
         def search_for_libclang(path):
             # Try to ensure that the clang shared library that bindgen is going
             # to look for is actually present.  The files that we search for
             # mirror the logic in clang-sys/build.rs.
             libclang_choices = []
             if host.os == 'WINNT':
                 libclang_choices.append('libclang.dll')
-            libclang_choices.append('%sclang%s' % (library_name_info.dll_prefix,
-                                                   library_name_info.dll_suffix))
+            libclang_choices.append('%sclang%s' % (library_name_info.dll.prefix,
+                                                   library_name_info.dll.suffix))
             if host.kernel == 'Linux':
                 libclang_choices.append('libclang.so.1')
 
             # At least one of the choices must be found.
             for choice in libclang_choices:
                 libclang = os.path.join(path, choice)
                 if os.path.exists(libclang):
                     return (True, None)