From 80ed61e8cd8a447dbe1f16e63ac94e6762a795bf Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Sun, 2 Jun 2024 01:06:32 -0700 Subject: [PATCH] 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 none is found. --- ChangeLog | 7 +++++++ pygnulib/main.py | 9 ++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 67b0ea66ef..3a982c4988 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-06-02 Collin Funk + + 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 + none is found. + 2024-05-31 Bruno Haible windows-once: Improve comments. diff --git a/pygnulib/main.py b/pygnulib/main.py index 68be0ba28f..6167135858 100644 --- a/pygnulib/main.py +++ b/pygnulib/main.py @@ -987,9 +987,12 @@ 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() - data = data.split('ACLOCAL_AMFLAGS')[1] - data = data[data.find('=') + 1 : data.find('\n')] - aclocal_amflags = data.split() + pattern = re.compile(r'^ACLOCAL_AMFLAGS[\t ]*=[\t ]*([^#]+?)$', re.MULTILINE) + match = re.search(pattern, data) + if match: + aclocal_amflags = match.group(1).split() + else: + aclocal_amflags = [] for aclocal_amflag in aclocal_amflags: if dirisnext: # Ignore absolute directory pathnames, like /usr/local/share/aclocal. -- 2.39.5