3 Commits

Author SHA1 Message Date
  Marvin Scholz 2fe75ab31d dependencies/pkgconfig: Log pkg-config exceptions 5 months ago
  Marvin Scholz 273d6e75ea dependencies/pkgconfig: Fix error reporting 5 months ago
  Marvin Scholz fc86339b39 dependencies/pkgconfig: Fix found state ignoring errors 5 months ago
2 changed files with 27 additions and 25 deletions
  1. 23
    21
      mesonbuild/dependencies/base.py
  2. 4
    4
      run_unittests.py

+ 23
- 21
mesonbuild/dependencies/base.py View File

@@ -645,16 +645,19 @@ class PkgConfigDependency(ExternalDependency):
645 645
 
646 646
         mlog.debug('Determining dependency {!r} with pkg-config executable '
647 647
                    '{!r}'.format(name, self.pkgbin.get_path()))
648
-        ret, self.version = self._call_pkgbin(['--modversion', name])
648
+        ret, self.version, _ = self._call_pkgbin(['--modversion', name])
649 649
         if ret != 0:
650 650
             return
651 651
 
652
+        self.is_found = True
653
+
652 654
         try:
653 655
             # Fetch cargs to be used while using this dependency
654 656
             self._set_cargs()
655 657
             # Fetch the libraries and library paths needed for using this
656 658
             self._set_libs()
657 659
         except DependencyException as e:
660
+            mlog.debug("pkg-config error with '%s': %s" % (name, e))
658 661
             if self.required:
659 662
                 raise
660 663
             else:
@@ -663,8 +666,6 @@ class PkgConfigDependency(ExternalDependency):
663 666
                 self.is_found = False
664 667
                 self.reason = e
665 668
 
666
-        self.is_found = True
667
-
668 669
     def __repr__(self):
669 670
         s = '<{0} {1}: {2} {3}>'
670 671
         return s.format(self.__class__.__name__, self.name, self.is_found,
@@ -672,11 +673,11 @@ class PkgConfigDependency(ExternalDependency):
672 673
 
673 674
     def _call_pkgbin_real(self, args, env):
674 675
         cmd = self.pkgbin.get_command() + args
675
-        p, out = Popen_safe(cmd, env=env)[0:2]
676
-        rc, out = p.returncode, out.strip()
676
+        p, out, err = Popen_safe(cmd, env=env)
677
+        rc, out, err = p.returncode, out.strip(), err.strip()
677 678
         call = ' '.join(cmd)
678 679
         mlog.debug("Called `{}` -> {}\n{}".format(call, rc, out))
679
-        return rc, out
680
+        return rc, out, err
680 681
 
681 682
     def _call_pkgbin(self, args, env=None):
682 683
         # Always copy the environment since we're going to modify it
@@ -741,10 +742,10 @@ class PkgConfigDependency(ExternalDependency):
741 742
             # so don't allow pkg-config to suppress -I flags for system paths
742 743
             env = os.environ.copy()
743 744
             env['PKG_CONFIG_ALLOW_SYSTEM_CFLAGS'] = '1'
744
-        ret, out = self._call_pkgbin(['--cflags', self.name], env=env)
745
+        ret, out, err = self._call_pkgbin(['--cflags', self.name], env=env)
745 746
         if ret != 0:
746
-            raise DependencyException('Could not generate cargs for %s:\n\n%s' %
747
-                                      (self.name, out))
747
+            raise DependencyException('Could not generate cargs for %s:\n%s\n' %
748
+                                      (self.name, err))
748 749
         self.compile_args = self._convert_mingw_paths(self._split_args(out))
749 750
 
750 751
     def _search_libs(self, out, out_raw, out_all):
@@ -910,20 +911,21 @@ class PkgConfigDependency(ExternalDependency):
910 911
         # paths so we can do manual searching with cc.find_library() later.
911 912
         env = os.environ.copy()
912 913
         env['PKG_CONFIG_ALLOW_SYSTEM_LIBS'] = '1'
913
-        ret, out = self._call_pkgbin(libcmd, env=env)
914
+        ret, out, err = self._call_pkgbin(libcmd, env=env)
914 915
         if ret != 0:
915
-            raise DependencyException('Could not generate libs for %s:\n\n%s' %
916
-                                      (self.name, out))
916
+            raise DependencyException('Could not generate libs for %s:\n%s\n' %
917
+                                      (self.name, err))
917 918
         # Also get the 'raw' output without -Lfoo system paths for adding -L
918 919
         # args with -lfoo when a library can't be found, and also in
919 920
         # gnome.generate_gir + gnome.gtkdoc which need -L -l arguments.
920
-        ret, out_raw = self._call_pkgbin(libcmd)
921
+        ret, out_raw, err_raw = self._call_pkgbin(libcmd)
921 922
         if ret != 0:
922
-            raise DependencyException('Could not generate libs for %s:\n\n%s' %
923
-                                      (self.name, out_raw))
924
-        ret, out_all = self._call_pkgbin(libcmd_all)
923
+            raise DependencyException('Could not generate libs for %s:\n%s\n' %
924
+                                      (self.name, err_raw))
925
+        ret, out_all, err_all = self._call_pkgbin(libcmd_all)
925 926
         if ret != 0:
926
-            mlog.warning('Could not determine complete list of dependencies for %s' % self.name)
927
+            mlog.warning('Could not determine complete list of dependencies for %s:\n%s\n' %
928
+                         (self.name, err_all))
927 929
         self.link_args, self.raw_link_args = self._search_libs(out, out_raw, out_all)
928 930
 
929 931
     def get_pkgconfig_variable(self, variable_name, kwargs):
@@ -939,19 +941,19 @@ class PkgConfigDependency(ExternalDependency):
939 941
 
940 942
             options = ['--define-variable=' + '='.join(definition)] + options
941 943
 
942
-        ret, out = self._call_pkgbin(options)
944
+        ret, out, err = self._call_pkgbin(options)
943 945
         variable = ''
944 946
         if ret != 0:
945 947
             if self.required:
946
-                raise DependencyException('dependency %s not found.' %
947
-                                          (self.name))
948
+                raise DependencyException('dependency %s not found:\n%s\n' %
949
+                                          (self.name, err))
948 950
         else:
949 951
             variable = out.strip()
950 952
 
951 953
             # pkg-config doesn't distinguish between empty and non-existent variables
952 954
             # use the variable list to check for variable existence
953 955
             if not variable:
954
-                ret, out = self._call_pkgbin(['--print-variables', self.name])
956
+                ret, out, _ = self._call_pkgbin(['--print-variables', self.name])
955 957
                 if not re.search(r'^' + variable_name + r'$', out, re.MULTILINE):
956 958
                     if 'default' in kwargs:
957 959
                         variable = kwargs['default']

+ 4
- 4
run_unittests.py View File

@@ -860,13 +860,13 @@ class InternalTests(unittest.TestCase):
860 860
 
861 861
             def fake_call_pkgbin(self, args, env=None):
862 862
                 if '--libs' not in args:
863
-                    return 0, ''
863
+                    return 0, '', ''
864 864
                 if args[0] == 'foo':
865
-                    return 0, '-L{} -lfoo -L{} -lbar'.format(p2.as_posix(), p1.as_posix())
865
+                    return 0, '-L{} -lfoo -L{} -lbar'.format(p2.as_posix(), p1.as_posix()), ''
866 866
                 if args[0] == 'bar':
867
-                    return 0, '-L{} -lbar'.format(p2.as_posix())
867
+                    return 0, '-L{} -lbar'.format(p2.as_posix()), ''
868 868
                 if args[0] == 'internal':
869
-                    return 0, '-L{} -lpthread -lm -lc -lrt -ldl'.format(p1.as_posix())
869
+                    return 0, '-L{} -lpthread -lm -lc -lrt -ldl'.format(p1.as_posix()), ''
870 870
 
871 871
             old_call = PkgConfigDependency._call_pkgbin
872 872
             old_check = PkgConfigDependency.check_pkgconfig

Loading…
Cancel
Save