[jhbuild/feature/regex-based-include-searching: 1/2] sysdeps: c_include_glob in altdeps




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

    sysdeps: c_include_glob in altdeps
    
    This adds support for a new `c_include_glob` type in the
    `deps` and `altdeps` elements that can be used to search
    for C include files using shell glob expressions
    (i.e, `*` and `?`).
    
    The path specified in the name field can be relative
    or absolute. If the path is absolute it will be evaluated
    directly using pythons `glob.glob` function. If the path
    is relative, it will be evaluated relative to all the
    configured include paths using pythons `fnmatch.fnmatch`
    function.
    
    This change is needed because clang installs its headers
    into non-standard locations. For example on Debian into
    `/usr/lib/llvm-*/include/clang-c` rather than putting them
    into `/usr/include/llvm-*/clang-c`.

 jhbuild/utils/systeminstall.py          | 21 +++++++++++++++++++++
 modulesets/gnome-sysdeps-latest.modules | 32 +++-----------------------------
 2 files changed, 24 insertions(+), 29 deletions(-)
---
diff --git a/jhbuild/utils/systeminstall.py b/jhbuild/utils/systeminstall.py
index 610be80d..19075661 100644
--- a/jhbuild/utils/systeminstall.py
+++ b/jhbuild/utils/systeminstall.py
@@ -19,6 +19,7 @@
 
 from __future__ import print_function
 
+import glob
 import os
 import sys 
 import logging
@@ -27,6 +28,7 @@ import subprocess
 import textwrap
 import time
 import re
+import fnmatch
 
 from .compat import TextIO
 from . import cmds
@@ -180,6 +182,25 @@ def systemdependencies_met(module_name, sysdeps, config):
                     break
             if not found:
                 dep_met = False
+        elif dep_type.lower() == 'c_include_glob':
+            if c_include_search_paths is None:
+                c_include_search_paths = get_c_include_search_paths(config)
+
+            if os.path.isabs(value):
+                matches = glob.glob(value)
+                if matches:
+                    return True
+
+            for path in c_include_search_paths:
+                filename_glob = os.path.normpath(os.path.join(path, value))
+
+                for root, dirs, files in os.walk(path):
+                    for file in files:
+                        candidate_filepath = os.path.join(root, file)
+                        if fnmatch.fnmatch(candidate_filepath, filename_glob):
+                            return True
+
+            dep_met = False
 
         elif dep_type in ('python2', 'python3'):
             command = dep_type
diff --git a/modulesets/gnome-sysdeps-latest.modules b/modulesets/gnome-sysdeps-latest.modules
index 9d0af442..9f925b82 100644
--- a/modulesets/gnome-sysdeps-latest.modules
+++ b/modulesets/gnome-sysdeps-latest.modules
@@ -531,22 +531,8 @@
     <branch repo="system"/>
     <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"/>
+        <!-- Debian -->
+        <altdep type="c_include_glob" name="/usr/lib/llvm-*/include/clang-c/Index.h"/>
         <!-- FreeBSD -->
         <altdep type="c_include" name="../llvm90/include/clang-c/Index.h"/>
         <altdep type="c_include" name="../llvm80/include/clang-c/Index.h"/>
@@ -948,19 +934,7 @@
     <systemdependencies>
       <dep type="c_include" name="llvm-c/Core.h">
         <!-- Debian -->
-        <altdep type="c_include" name="llvm-c-10/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-9/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-8/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-7/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-6.0/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-5.0/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-4.0/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-3.9/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-3.8/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-3.7/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-3.6/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-3.5/llvm-c/Core.h"/>
-        <altdep type="c_include" name="llvm-c-3.4/llvm-c/Core.h"/>
+        <altdep type="c_include_glob" name="llvm-c-*/llvm-c/Core.h"/>
         <!-- FreeBSD -->
         <altdep type="c_include" name="../llvm90/include/llvm-c/Core.h"/>
         <altdep type="c_include" name="../llvm80/include/llvm-c/Core.h"/>


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