[jhbuild/sysinstall-fix-pc-lookup: 10/10] sysinstall/apt: Limit .pc search to the pkg-config search paths



commit 189967548c57e70299e8abb403d4b80c756205f0
Author: Christoph Reiter <reiter christoph gmail com>
Date:   Tue Sep 10 19:27:05 2019 +0200

    sysinstall/apt: Limit .pc search to the pkg-config search paths
    
    In case of zlib various packages like emscripten and mingw include
    a zlib.pc file and we currently install a random one of them and hope it
    works out.
    
    Instead only look for .pc files in the default pkg-config search paths
    to avoid false positives.

 .gitlab-ci.yml                 |  2 +-
 jhbuild/utils/systeminstall.py | 24 ++++++++++++++++--------
 2 files changed, 17 insertions(+), 9 deletions(-)
---
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index 31a34886..91477773 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -30,7 +30,7 @@ ubuntu-19.04-glib:
     - echo "use_local_modulesets = True" >> $HOME/.config/jhbuildrc
     - sudo apt-file update
     - jhbuild --no-interact --exit-on-error sysdeps --install --assume-yes glib
-    - sudo apt install -y zlib1g-dev docbook-xml docbook-xsl
+    - sudo apt install -y docbook-xml docbook-xsl
     - jhbuild --no-interact --exit-on-error build glib
 
 pages:
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index a3cf0988..969a3337 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -452,13 +452,6 @@ class AptSystemInstall(SystemInstall):
             ret_value += "|.*/" + re.escape(path)
         return ret_value
 
-    def _name_match_pkg(self, pkg, apt_file_result, native_packages):
-        for name, path in apt_file_result:
-            if path.endswith("/" + pkg):
-                native_packages.append(name)
-                return True
-        return False
-
     def _name_match_exact(self, exact_path_to_match, apt_file_result, native_packages):
         for name, path in apt_file_result:
             if path == exact_path_to_match:
@@ -469,9 +462,24 @@ class AptSystemInstall(SystemInstall):
     def _append_native_packages_or_warn_pkgconfig(self, pkgconfigs, native_packages):
         if len(pkgconfigs) == 0:
             return
+
+        def get_pkg_config_search_paths():
+            output = subprocess.check_output(
+                ["pkg-config", "--variable", "pc_path", "pkg-config"])
+            return output.strip().split(os.pathsep)
+
+        # Various packages include zlib.pc (emscripten, mingw) so look only in
+        # the default pkg-config search paths
+        search_paths = get_pkg_config_search_paths()
+        search_paths = tuple(os.path.join(p, "") for p in search_paths)
+
         apt_file_result = self._apt_file_result(regexp="\\.pc$")
         for modname, pkg in pkgconfigs:
-            if not self._name_match_pkg(pkg, apt_file_result, native_packages):
+            for name, path in apt_file_result:
+                if path.endswith("/" + pkg) and path.startswith(search_paths):
+                    native_packages.append(name)
+                    break
+            else:
                 logging.info(_('No native package found for %(id)s '
                                '(%(filename)s)') % {'id'       : modname,
                                                     'filename' : pkg})


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]