[gtk-doc/ignored-headers] mkdb: Simplify the ignored files handling



commit ead4596cc3b13c0acbf3169ccc4656498adf8b3b
Author: Emmanuele Bassi <ebassi gnome org>
Date:   Wed Mar 4 18:36:55 2020 +0000

    mkdb: Simplify the ignored files handling
    
    Use the same mechanism as gtkdoc-scan, and store the ignored files in a
    list instead of a string; then construct a list of absolute paths from
    each source directory, and match each file against that list.

 gtkdoc/mkdb.py | 47 +++++++++++++++++------------------------------
 1 file changed, 17 insertions(+), 30 deletions(-)
---
diff --git a/gtkdoc/mkdb.py b/gtkdoc/mkdb.py
index 87fdf24..5ece7e6 100644
--- a/gtkdoc/mkdb.py
+++ b/gtkdoc/mkdb.py
@@ -308,10 +308,12 @@ def Run(options):
         suffix_list = ['.c', '.h']
 
     source_dirs = options.source_dir
-    ignore_files = options.ignore_files
-    logging.info(" ignore files: " + ignore_files)
+    ignore_files = options.ignore_files and options.ignore_files.split(' ') or []
+    logging.info("Ignored files: " + options.ignore_files)
+
     for sdir in source_dirs:
-        ReadSourceDocumentation(sdir, suffix_list, source_dirs, ignore_files)
+        abs_ignored_files = [os.path.join(sdir, x) for x in ignore_files]
+        ReadSourceDocumentation(sdir, suffix_list, abs_ignored_files)
 
     logging.info("Sources scanned")
 
@@ -3601,24 +3603,7 @@ def GetArgs(gobject):
     return (synop, child_synop, style_synop, desc, child_desc, style_desc)
 
 
-def IgnorePath(path, source_dirs, ignore_files):
-    for sdir in source_dirs:
-        # Cut off base directory
-        m1 = re.search(r'^%s/(.*)$' % re.escape(sdir), path)
-        if m1:
-            # Check if the filename is in the ignore list.
-            m2 = re.search(r'(\s|^)%s(\s|$)' % re.escape(m1.group(1)), ignore_files)
-            if m2:
-                logging.info("Skipping path: %s", path)
-                return True
-            else:
-                logging.info("No match for: %s", m1.group(1))
-        else:
-            logging.info("No match for: %s", path)
-    return False
-
-
-def ReadSourceDocumentation(source_dir, suffix_list, source_dirs, ignore_files):
+def ReadSourceDocumentation(source_dir, suffix_list, ignore_files):
     """Read the documentation embedded in comment blocks in the source code.
 
     It recursively descends the source directory looking for source files and
@@ -3627,10 +3612,8 @@ def ReadSourceDocumentation(source_dir, suffix_list, source_dirs, ignore_files):
     Args:
         source_dir (str): the directory to scan.
         suffix_list (list): extensions to check
+        ignore_files (list): a list of ignored paths under source_dir
     """
-    if IgnorePath(source_dir, source_dirs, ignore_files):
-        return
-
     logging.info("Scanning source directory: %s", source_dir)
 
     # This array holds any subdirectories found.
@@ -3643,16 +3626,20 @@ def ReadSourceDocumentation(source_dir, suffix_list, source_dirs, ignore_files):
         fname = os.path.join(source_dir, ifile)
         if os.path.isdir(fname):
             subdirs.append(fname)
+        elif fname in ignore_files:
+            logging.info(f"File {fname} matches ignored files")
         else:
             for suffix in suffix_list:
                 if ifile.endswith(suffix):
-                    if not IgnorePath(fname, source_dirs, ignore_files):
-                        ScanSourceFile(fname, ignore_files)
-                        break
+                    ScanSourceFile(fname, ignore_files)
+                    break
 
     # Now recursively scan the subdirectories.
     for sdir in subdirs:
-        ReadSourceDocumentation(sdir, suffix_list, source_dirs, ignore_files)
+        if sdir in ignore_files:
+            logging.info(f"Directory {sdir} matches ignored files")
+            continue
+        ReadSourceDocumentation(sdir, suffix_list, ignore_files)
 
 
 def ScanSourceFile(ifile, ignore_files):
@@ -3671,8 +3658,8 @@ def ScanSourceFile(ifile, ignore_files):
         common.LogWarning(ifile, 1, "Can't find basename for this filename.")
         basename = ifile
 
-    # Check if the basename is in the list of files to ignore.
-    if re.search(r'(\s|^)%s(\s|$)' % re.escape(basename), ignore_files):
+    # Check if the filename is in the list of files to ignore.
+    if ifile in ignore_files:
         logging.info("Skipping source file: %s", ifile)
         return
 


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