[jhbuild/feature/regex-based-include-searching] sysdeps: support regex in altdeps




commit f376befdfe33753e28bba743893c423835675e0d
Author: Sebastian Geiger <sbastig gmx net>
Date:   Fri May 14 16:09:50 2021 +0200

    sysdeps: support regex in altdeps
    
    This adds support for using regex in altdeps by adding a new attribute 'regex'
    to the deps and altdeps entries.
    
    We also add /usr/lib to the searched directories. This change is
    needed because clang installs its headers into /usr/lib/llvm-*/include/clang
    rather than putting them into /usr/include/llvm-*.
    
    When resolving altdeps we now check if an altdep is specified
    via a regex and then try find a matching header in
    the list of search include directories.

 jhbuild/commands/sysdeps.py             | 10 +++++-----
 jhbuild/modtypes/__init__.py            |  3 ++-
 jhbuild/modtypes/systemmodule.py        |  6 +++---
 jhbuild/moduleset.py                    |  2 +-
 jhbuild/utils/systeminstall.py          | 20 ++++++++++++++++----
 modulesets/gnome-sysdeps-latest.modules | 16 +---------------
 modulesets/moduleset.dtd                |  6 ++++--
 modulesets/moduleset.rnc                |  2 +-
 8 files changed, 33 insertions(+), 32 deletions(-)
---
diff --git a/jhbuild/commands/sysdeps.py b/jhbuild/commands/sysdeps.py
index 5e46cb33..e9ed5524 100644
--- a/jhbuild/commands/sysdeps.py
+++ b/jhbuild/commands/sysdeps.py
@@ -87,9 +87,9 @@ class cmd_sysdeps(cmd_build):
                         print('pkgconfig:{0}'.format(module.pkg_config[:-3])) # remove .pc
 
                     if module.systemdependencies is not None:
-                        for dep_type, value, altdeps in module.systemdependencies:
+                        for dep_type, value, regex, altdeps in module.systemdependencies:
                             sys.stdout.write('{0}:{1}'.format(dep_type, value))
-                            for dep_type, value, empty in altdeps:
+                            for dep_type, value, regex, empty in altdeps:
                                 sys.stdout.write(',{0}:{1}'.format(dep_type, value))
                             sys.stdout.write('\n')
 
@@ -123,9 +123,9 @@ class cmd_sysdeps(cmd_build):
                         print('pkgconfig:{0}'.format(module.pkg_config[:-3])) # remove .pc
 
                     if module.systemdependencies is not None:
-                        for dep_type, value, altdeps in module.systemdependencies:
+                        for dep_type, value, regex, altdeps in module.systemdependencies:
                             sys.stdout.write('{0}:{1}'.format(dep_type, value))
-                            for dep_type, value, empty in altdeps:
+                            for dep_type, value, regex, empty in altdeps:
                                 sys.stdout.write(',{0}:{1}'.format(dep_type, value))
                             sys.stdout.write('\n')
 
@@ -168,7 +168,7 @@ class cmd_sysdeps(cmd_build):
                 if module.pkg_config is not None:
                     uninstalled.append((module.name, 'pkgconfig', module.pkg_config[:-3])) # remove .pc
                 elif module.systemdependencies is not None:
-                    for dep_type, value, altdeps in module.systemdependencies:
+                    for dep_type, value, regex, altdeps in module.systemdependencies:
                         uninstalled.append((module.name, dep_type, value))
         if len(uninstalled) == 0:
             print(_('    (none)'))
diff --git a/jhbuild/modtypes/__init__.py b/jhbuild/modtypes/__init__.py
index 2919a9f9..bb842fe7 100644
--- a/jhbuild/modtypes/__init__.py
+++ b/jhbuild/modtypes/__init__.py
@@ -95,10 +95,11 @@ def get_dependencies(node):
                                      {'node_name'   : 'dep',
                                       'module_name' : node.getAttribute('id'),
                                       'attribute'   : 'name'})
+                regex = dep.getAttribute('regex')
                 altdeps = []
                 if dep.childNodes:
                     add_to_system_dependencies(altdeps, dep, 'altdep')
-                lst.append((typ, name, altdeps))
+                lst.append((typ, name, regex, altdeps))
 
     for childnode in node.childNodes:
         if childnode.nodeType != childnode.ELEMENT_NODE:
diff --git a/jhbuild/modtypes/systemmodule.py b/jhbuild/modtypes/systemmodule.py
index 92b64838..6c08134d 100644
--- a/jhbuild/modtypes/systemmodule.py
+++ b/jhbuild/modtypes/systemmodule.py
@@ -26,14 +26,14 @@ __all__ = [ 'SystemModule' ]
 
 class SystemModule(Package):
     @classmethod
-    def create_virtual(cls, name, branch, deptype, value):
-        return cls(name, branch=branch, systemdependencies=[(deptype, value, [])])
+    def create_virtual(cls, name, branch, deptype, value, regex):
+        return cls(name, branch=branch, systemdependencies=[(deptype, value, regex, [])])
 
 def parse_systemmodule(node, config, uri, repositories, default_repo):
     instance = SystemModule.parse_from_xml(node, config, uri, repositories,
                                            default_repo)
 
-    if any(deptype == 'xml' for deptype, value, altdeps in instance.systemdependencies):
+    if any(deptype == 'xml' for deptype, value, regex, altdeps in instance.systemdependencies):
         instance.dependencies += ['xmlcatalog']
 
     return instance
diff --git a/jhbuild/moduleset.py b/jhbuild/moduleset.py
index 12208992..a0a4bc2a 100644
--- a/jhbuild/moduleset.py
+++ b/jhbuild/moduleset.py
@@ -378,7 +378,7 @@ def load(config, uri=None):
         if name in ms.modules:
             continue
 
-        virtual = SystemModule.create_virtual(name, virtual_branch, 'path', name)
+        virtual = SystemModule.create_virtual(name, virtual_branch, 'path', name, '')
         ms.add(virtual)
 
     return ms
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index 610be80d..52fb3fdb 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -135,7 +135,7 @@ def systemdependencies_met(module_name, sysdeps, config):
         except (EnvironmentError, subprocess.CalledProcessError):
             multiarch = None
         # search /usr/include and its multiarch subdir (if any) by default
-        paths = [ os.path.join(os.sep, 'usr', 'include')]
+        paths = [ os.path.join(os.sep, 'usr', 'include'), os.path.join(os.sep, 'usr', 'lib')]
         if multiarch:
             paths += [ os.path.join(paths[0], multiarch) ]
         paths += extract_path_from_cflags(os.environ.get('CPPFLAGS', ''))
@@ -154,7 +154,7 @@ def systemdependencies_met(module_name, sysdeps, config):
         return paths
 
     c_include_search_paths = None
-    for dep_type, value, altdeps in sysdeps:
+    for dep_type, value, is_regex, altdeps in sysdeps:
         dep_met = True
         if dep_type.lower() == 'path':
             if os.path.split(value)[0]:
@@ -174,8 +174,20 @@ def systemdependencies_met(module_name, sysdeps, config):
                 c_include_search_paths = get_c_include_search_paths(config)
             found = False
             for path in c_include_search_paths:
-                filename = os.path.join(path, value)
-                if os.path.isfile(filename):
+                filename = os.path.normpath(os.path.join(path, value))
+
+                # check if the value is a regex
+                if is_regex:
+                    matches = []
+                    regex = re.compile(filename)
+                    # value is a regex, do a tree walk and see if we can find a matching include
+                    for root, dirs, files in os.walk(path):
+                        for file in files:
+                            if regex.match(os.path.join(root, file)):
+                                matches.append(file)
+                    if matches:
+                        found = True
+                elif os.path.isfile(filename):
                     found = True
                     break
             if not found:
diff --git a/modulesets/gnome-sysdeps-latest.modules b/modulesets/gnome-sysdeps-latest.modules
index 9d0af442..b06d7fd7 100644
--- a/modulesets/gnome-sysdeps-latest.modules
+++ b/modulesets/gnome-sysdeps-latest.modules
@@ -532,21 +532,7 @@
     <systemdependencies>
       <dep type="c_include" name="clang-c/Index.h">
         <!-- Debian. FIXME: This is definitely broken. https://bugzilla.gnome.org/show_bug.cgi?id=781872 -->
-        <altdep type="c_include" name="../lib/llvm-12/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-11/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-10/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-9/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-8/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-7/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-6.0/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-5.0/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-4.0/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-3.9/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-3.8/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-3.7/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-3.6/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-3.5/include/clang-c/Index.h"/>
-        <altdep type="c_include" name="../lib/llvm-3.4/include/clang-c/Index.h"/>
+        <altdep type="c_include" name="../lib/llvm-.*/include/clang-c/Index.h" regex="true" />
         <!-- FreeBSD -->
         <altdep type="c_include" name="../llvm90/include/clang-c/Index.h"/>
         <altdep type="c_include" name="../llvm80/include/clang-c/Index.h"/>
diff --git a/modulesets/moduleset.dtd b/modulesets/moduleset.dtd
index b8cd30d5..b8e4fb8a 100644
--- a/modulesets/moduleset.dtd
+++ b/modulesets/moduleset.dtd
@@ -206,12 +206,14 @@
 <!ATTLIST dep
        package CDATA   #IMPLIED
        type    CDATA   #IMPLIED
-       name    CDATA   #IMPLIED>
+       name    CDATA   #IMPLIED
+       regex   CDATA   #IMPLIED>
 <!-- <altdep> is only used in <systemdependencies> to specify alternative dependencies. -->
 <!ELEMENT altdep EMPTY>
 <!ATTLIST altdep
        type    CDATA   #IMPLIED
-       name    CDATA   #IMPLIED>
+       name    CDATA   #IMPLIED
+       regex   CDATA   #IMPLIED>
 
 <!ELEMENT branch (patch*,quilt*)>
 <!ATTLIST branch
diff --git a/modulesets/moduleset.rnc b/modulesets/moduleset.rnc
index 4522d558..567017af 100644
--- a/modulesets/moduleset.rnc
+++ b/modulesets/moduleset.rnc
@@ -247,7 +247,7 @@ attlist.systemdependencies &= empty
 dep = element dep { attlist.dep, empty }
 attlist.dep &= attribute package { text }
 sysdep = element dep { attlist.sysdep, altdep* }
-attlist.sysdep &= attribute type { text }, attribute name { text }
+attlist.sysdep &= attribute type { text }, attribute name { text }, attribute regex { text }
 altdep = element altdep { attlist.sysdep }
 branch = element branch { attlist.branch, patch*, quilt* }
 attlist.branch &=


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