Bruno Haible <[email protected]> writes:
>> > Thanks for this recipe. I think this is worth a unit test, since it
>> > is a special case that is otherwise not tested.
>>
>> Agreed. I can add one later today.
>
> I added it already.
Thanks, I've applied the attached patch fixing that regular expression.
Also, Paul while investigating this I noticed some strange behavior. The
Autoconf documentation mentions the limit to a single line for
ACLOCAL_AMFLAGS. Perhaps it is worth changing this regexp [1] or
mentioning this in the documentation [2].
Here is a test case:
$ gnulib-tool --create-testdir --dir testdir1 README-release
$ cd testdir1
$ sed -i -e 's/ACLOCAL_AMFLAGS = -I glm4/ACLOCAL_AMFLAGS = -I glm4 #
--help/g' Makefile.am
$ cat Makefile.am
[...]
ACLOCAL_AMFLAGS = -I glm4 # --help
$ autoreconf
Usage: aclocal [OPTION]...
Generate 'aclocal.m4' by scanning 'configure.ac' or 'configure.in'
[...]
If you remove aclocal.m4 and try to autoreconf the build will fail
because m4 macros cannot be found of course.
I don't know enough about Autotools to tell if anything silly can be
done using this trick. Not that you would run auto* in a project that
you don't trust anyways...
Collin
[1]
https://www.gnu.org/savannah-checkouts/gnu/autoconf/manual/autoconf-2.72/autoconf.html#index-AC_005fCONFIG_005fMACRO_005fDIR-1
[2] https://git.savannah.gnu.org/cgit/autoconf.git/tree/bin/autoreconf.in#n532
>From 1372dc1631053fa72bbf5755cbc89f63cbffec33 Mon Sep 17 00:00:00 2001
From: Collin Funk <[email protected]>
Date: Sun, 2 Jun 2024 05:29:33 -0700
Subject: [PATCH] gnulib-tool.py: Fix regular expression (regr. today).
* pygnulib/main.py (main) [import]: Match all characters until '#' or
end of line, whichever comes first.
---
ChangeLog | 4 ++++
pygnulib/main.py | 2 +-
2 files changed, 5 insertions(+), 1 deletion(-)
diff --git a/ChangeLog b/ChangeLog
index 3a982c4988..f076c168b0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2024-06-02 Collin Funk <[email protected]>
+ gnulib-tool.py: Fix regular expression (regr. today).
+ * pygnulib/main.py (main) [import]: Match all characters until '#' or
+ end of line, whichever comes first.
+
gnulib-tool.py: Fix crash when no ACLOCAL_AMFLAGS is found.
* pygnulib/main.py (main) [import]: Use a regular expression to match
the ACLOCAL_AMFLAGS Makefile.am variable. Properly handle the case where
diff --git a/pygnulib/main.py b/pygnulib/main.py
index 6167135858..c1c2cd2c1e 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -987,7 +987,7 @@ def main(temp_directory: str) -> None:
if os.path.isfile(filepath):
with open(filepath, mode='r', newline='\n', encoding='utf-8') as file:
data = file.read()
- pattern = re.compile(r'^ACLOCAL_AMFLAGS[\t ]*=[\t ]*([^#]+?)$', re.MULTILINE)
+ pattern = re.compile(r'^ACLOCAL_AMFLAGS[\t ]*=[\t ]*(.+?)[\t ]*(?:#|$)', re.MULTILINE)
match = re.search(pattern, data)
if match:
aclocal_amflags = match.group(1).split()
--
2.45.1