Bug 1363655 - part 8 - check for the existence of a libclang bindgen will use; r=rillian
authorNathan Froyd <froydnj@mozilla.com>
Wed, 21 Jun 2017 13:28:37 -0400
changeset 414070 cc58f2b74c4f3c95d9dfed26b6b69f540052ca27
parent 414069 247d01ab53c74c3e4ea7b36964cef31b87380b9a
child 414071 5424426a71897398c11894f0c43c3e6d485f4604
push id7566
push usermtabara@mozilla.com
push dateWed, 02 Aug 2017 08:25:16 +0000
treeherdermozilla-beta@86913f512c3c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrillian
bugs1363655
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 1363655 - part 8 - check for the existence of a libclang bindgen will use; r=rillian Ideally this check will alert people that something is wrong with their configuration. This check shouldn't normally be firing with our `mach boostrap` setup, but if somebody chooses to install distribution packages for some reason, this will at least prevent some problems.
toolkit/moz.configure
--- a/toolkit/moz.configure
+++ b/toolkit/moz.configure
@@ -689,21 +689,41 @@ with only_when(building_stylo_bindgen):
             To compile Stylo, please install version {} or greater of
             Clang + LLVM and ensure that the 'llvm-config' from that
             installation is first on your path.
 
             You can verify this by typing 'llvm-config --version'.
             '''.format(version, min_version)))
 
     @depends(llvm_config, '--with-libclang-path', '--with-clang-path',
-             host)
+             library_name_info, host)
     @imports('os.path')
     @imports(_from='textwrap', _import='dedent')
     def bindgen_config_paths(llvm_config, libclang_path, clang_path,
-                             host):
+                             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))
+            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)
+            else:
+                return (False, list(set(libclang_choices)))
+
         if not libclang_path and not clang_path:
             # We must have LLVM_CONFIG in this case.
             if not llvm_config:
                 die(dedent('''\
                 Could not find LLVM/Clang installation for compiling stylo build-time
                 bindgen.  Please specify the 'LLVM_CONFIG' environment variable
                 (recommended), pass the '--with-libclang-path' and '--with-clang-path'
                 options to configure, or put 'llvm-config' in your PATH.  Altering your
@@ -723,16 +743,24 @@ with only_when(building_stylo_bindgen):
             # to use their system packages, we can't be more specific about what
             # they need.
             if not os.path.exists(libclang_path):
                 die(dedent('''\
                 The directory {} returned by `llvm-config {}` does not exist.
                 Please check your system configuration.
                 '''.format(libclang_path, libclang_arg)))
 
+            (found, searched) = search_for_libclang(libclang_path)
+            if not found:
+                die(dedent('''\
+                Could not find the clang shared library in the path {}
+                returned by `llvm-config {}` (searched for files {}).
+                Please check your system configuration.
+                '''.format(libclang_path, libclang_arg, searched)))
+
             if not os.path.exists(clang_path):
                 die(dedent('''\
                 The file {} returned by `llvm-config {}` does not exist.
                 Please check your system configuration.
                 '''.format(clang_path, '--bindir')))
 
             return namespace(
                 libclang_path=libclang_path,
@@ -746,16 +774,23 @@ with only_when(building_stylo_bindgen):
             or neither of them.'''))
 
         if not os.path.exists(libclang_path) or \
            not os.path.isdir(libclang_path):
             die(dedent('''\
             The argument to --with-libclang-path is not a directory: {}
             '''.format(libclang_path)))
 
+        (found, searched) = search_for_libclang(libclang_path)
+        if not found:
+            die(dedent('''\
+            Could not find the clang shared library in the path {}
+            specified by --with-libclang-path (searched for files {}).
+            '''.format(libclang_path, searched)))
+
         if not os.path.exists(clang_path) or \
            not os.path.isfile(clang_path):
             die(dedent('''\
             The argument to --with-clang-path is not a file: {}
             '''.format(clang_path)))
 
         return namespace(
             libclang_path=libclang_path[0],