This is a gnulib-tool.py bug fix.

While fighting with the non-standard 'bootstrap' script in GNU m4's repository,
I came into a situation where that script printed a Python exception. I could
reproduce it with this command line:

$ /GNULIB/gnulib/gnulib-tool --no-changelog --no-libtool --update

Traceback (most recent call last):
  File "/GNULIB/gnulib/.gnulib-tool.py", line 30, in <module>
    main.main_with_exception_handling()
  File "/GNULIB/gnulib/pygnulib/main.py", line 1469, in 
main_with_exception_handling
    main(temporary_directory)
  File "/GNULIB/gnulib/pygnulib/main.py", line 1095, in main
    importer = GLImport(config, mode, guessed_m4dirs)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/GNULIB/gnulib/pygnulib/GLImport.py", line 234, in __init__
    self.cache.setFiles(pattern.findall(data)[-1].strip().split())
                        ~~~~~~~~~~~~~~~~~~~~~^^^^
IndexError: list index out of range

It occurs because the m4/gnulib-cache.m4 file specifies

  gl_MACRO_PREFIX([M4])

but the m4/gnulib-comp.m4 file has a definition of gl_FILE_LIST but no
definition of M4_FILE_LIST. (Input files are attached.)

gnulib-tool.sh is tolerant in this situation. This patch makes gnulib-tool.py
tolerant as well.


2025-04-15  Bruno Haible  <br...@clisp.org>

        gnulib-tool.py: Fix exception during --update with changed macro-prefix.
        * pygnulib/GLImport.py (GLImport.__init__): Support the case that the
        expected ${macro_prefix}_FILE_LIST definition was not found.

diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 27d8b749ed..9344c8fa9d 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -231,7 +231,12 @@ def __init__(self, config: GLConfig, mode: int, m4dirs: 
list[str]) -> None:
                     data = file.read()
                 regex = r'AC_DEFUN\(\[%s_FILE_LIST\], \[(.*?)\]\)' % 
self.cache['macro_prefix']
                 pattern = re.compile(regex, re.S | re.M)
-                self.cache.setFiles(pattern.findall(data)[-1].strip().split())
+                matches = pattern.findall(data)
+                if matches:
+                    files = matches[-1].strip().split()
+                else:
+                    files = []
+                self.cache.setFiles(files)
 
         # The self.config['localpath'] defaults to the cached one. Recall that
         # the cached one is relative to self.config['destdir'], whereas the one

Attachment: inputs.tar.gz
Description: application/compressed-tar

Reply via email to