At the end of imports gnulib-tool searches for AC_PROG_CC_STDC and
AC_PROG_CC_C99 in configure.ac. If one is found it recommends replacing
them with AC_PROG_CC which is the modern way of doing things.

We only care about the macro occuring in the file so re.search() makes
more sense then re.findall(). If it is found at the start of the file
the rest of the search is just wasted time. Probably noticeable unless
one has a very long configure.ac though.

Collin

>From 80949983d7ebf1f26c9ac96badddb9db276847bb Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Wed, 5 Jun 2024 20:21:51 -0700
Subject: [PATCH] gnulib-tool.py: Don't perform unnecessary configure.ac
 scanning.

* pygnulib/GLImport.py (GLImport.execute): Use re.search() instead of
re.findall() since we only care about finding one match. Remove
unnecessary bool() calls.
---
 ChangeLog            | 7 +++++++
 pygnulib/GLImport.py | 6 ++----
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index eec970671b..3c932f4f73 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-06-05  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Don't perform unnecessary configure.ac scanning.
+	* pygnulib/GLImport.py (GLImport.execute): Use re.search() instead of
+	re.findall() since we only care about finding one match. Remove
+	unnecessary bool() calls.
+
 2024-06-05  Bruno Haible  <br...@clisp.org>
 
 	setenv: On native Windows, don't modify _environ directly.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index e67cbbe5a2..df541a8b77 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -1392,10 +1392,8 @@ def execute(self, filetable: GLFileTable, transformers: dict[str, tuple[re.Patte
         # Detect position_early_after.
         with open(configure_ac, mode='r', newline='\n', encoding='utf-8') as file:
             data = file.read()
-        match_result1 = \
-            bool(re.compile(r'^ *AC_PROG_CC_STDC', re.M).findall(data))
-        match_result2 = \
-            bool(re.compile(r'^ *AC_PROG_CC_C99', re.M).findall(data))
+        match_result1 = re.compile(r'^ *AC_PROG_CC_STDC', re.MULTILINE).search(data)
+        match_result2 = re.compile(r'^ *AC_PROG_CC_C99', re.MULTILINE).search(data)
         if match_result1:
             print('  - replace AC_PROG_CC_STDC with AC_PROG_CC in %s,' % (configure_ac))
             position_early_after = 'AC_PROG_CC_STDC'
-- 
2.45.2

Reply via email to