This regular expression should be much more strict. This patch should
fix it. The 'inttostr' module seems like the best way to show this:

diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index fac29883f9..1724b250da 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -1039,6 +1039,8 @@ class GLModuleTable(object):
                     pattern = re.compile(r'^lib_SOURCES[\t ]*\+=([^#]*).*$', 
re.M)
                     for matching_rhs in pattern.findall(snippet):
                         files = matching_rhs.split(' ')
+                        if module.name == 'inttostr':
+                            print(files)
                         for file in files:
                             # Ignore .h files since they are not compiled.
                             if not file.endswith('.h'):

['', '', '', '', 'imaxtostr.c', '', '', '', 'inttostr.c', '', '', '', 
'offtostr.c', '', '', '', 'uinttostr.c', '', '', '', 
'umaxtostr.c\n\nEXTRA_DIST', '+=', 'anytostr.c', 
'inttostr.h\n\nEXTRA_lib_SOURCES', '+=', 'anytostr.c\n\n']

After this patch:

['imaxtostr.c', 'inttostr.c', 'offtostr.c', 'uinttostr.c', 'umaxtostr.c']

Since we just called combine_lines, we should only have to match until
the end of the line starting with 'lib_SOURCES'. Assuming I am
interpreting this comment correctly:

    # Extract the value of unconditional "lib_SOURCES += ..." augmentations.

and the sed invocation in gnulib-tool.sh line 3447:

   sed -n -e 's,^lib_SOURCES[    ]*+=\([^#]*\).*$,\1,p'

Collin
From 1e2b8041b028a7e8b36a217799d08324d6b0fd40 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 2 Apr 2024 04:41:22 -0700
Subject: [PATCH] gnulib-tool.py: Make regular expression more strict.

* pygnulib/GLModuleSystem.py (GLModuleSystem.add_dummy): Only match the
'lib_SOURCES' variable.
---
 ChangeLog                  | 6 ++++++
 pygnulib/GLModuleSystem.py | 6 +++---
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4159305009..8817e8cdcb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2024-04-02  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Make regular expression more strict.
+	* pygnulib/GLModuleSystem.py (GLModuleSystem.add_dummy): Only match the
+	'lib_SOURCES' variable.
+
 2024-04-02  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Accept valid make syntax for escaped newlines.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index fac29883f9..14192754e5 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -1036,9 +1036,9 @@ class GLModuleTable(object):
                     # Extract the value of unconditional "lib_SOURCES += ..." augmentations.
                     snippet = combine_lines(snippet)
                     snippet = self.remove_if_blocks(snippet)
-                    pattern = re.compile(r'^lib_SOURCES[\t ]*\+=([^#]*).*$', re.M)
-                    for matching_rhs in pattern.findall(snippet):
-                        files = matching_rhs.split(' ')
+                    pattern = re.compile(r'^lib_SOURCES[\t ]*\+=[\t ]*([^#]+?)$', re.MULTILINE)
+                    for matching_rhs in re.finditer(pattern, snippet):
+                        files = matching_rhs.group(1).split()
                         for file in files:
                             # Ignore .h files since they are not compiled.
                             if not file.endswith('.h'):
-- 
2.44.0

Reply via email to