Hi Simon,

This patch should fix gnulib-tool.py when running
'gnulib-tool.py --add-import' in OATH Toolkit.

It appears that gnulib-tool.py was not picking up the m4 directories
correctly. This means that when the GLImport object was created it
could not find the gnulib-cache.m4 file containing the sourcebase.

This appeared as a failure to write since gnulib-tool.py was trying to
write to '$sourcebase/dummy.c' where $sourcebase was an empty string.

The other change prevents calling 'obj.split()' where obj is not a
string:

         sequence = [ True if value == 'true' else value
                      for value in sequence ]
         sequence = [ value.strip()
+                     if type(value) is str else value
                      for value in sequence ]

As a result of the first assignment, sequence can have bools.
Therefore before calling strip() we have to make sure the object is
actually a string. If it isn't we just leave the value alone.

I've attached a patch that fixes this along with a diff between OATH
Toolkit after running 'gnulib-tool --add-import' and
'gnulib-tool.py --add-import'.

There is a few whitespace differences, and then a few lines that still
need to be fixed. Not looking too bad though.

Collin
From c756cb0e6fbb73a6d9cd19339fbd846cd05d3d40 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Wed, 13 Mar 2024 19:21:44 -0700
Subject: [PATCH] gnulib-tool.py: Fix write failure due to bad sourcebase.

* pygnulib/constants.py (cleaner): Only call strip() on string objects.
* pygnulib/main.py (main): Fix parsing of AMLOCAL_AMFLAGS from
Makefile.am. Add some comments from gnulib-tool.
---
 ChangeLog             |  7 +++++++
 pygnulib/constants.py |  1 +
 pygnulib/main.py      | 21 ++++++++++++++++++---
 3 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index ff9cca6439..e169d5697d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-03-13  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Fix write failure due to bad sourcebase.
+	* pygnulib/constants.py (cleaner): Only call strip() on string objects.
+	* pygnulib/main.py (main): Fix parsing of AMLOCAL_AMFLAGS from
+	Makefile.am. Add some comments from gnulib-tool.
+
 2024-03-12  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Follow gnulib-tool changes, part 56.
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index 918faa8cc0..a3bf8cd1d4 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -249,6 +249,7 @@ def cleaner(sequence):
         sequence = [ True if value == 'true' else value
                      for value in sequence ]
         sequence = [ value.strip()
+                     if type(value) is str else value
                      for value in sequence ]
     return sequence
 
diff --git a/pygnulib/main.py b/pygnulib/main.py
index 7f710a2079..b145675f78 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -858,7 +858,10 @@ def main():
 
         else:  # if mode != MODE['--import']
             if m4base:
+                # Apply func_import to a particular gnulib directory.
+                # Any number of additional modules can be given.
                 if not isfile(joinpath(destdir, m4base, 'gnulib-cache.m4')):
+                    # First use of gnulib in the given m4base.
                     if not sourcebase:
                         sourcebase = 'lib'
                     if not docbase:
@@ -877,8 +880,13 @@ def main():
                 filetable, transformers = importer.prepare()
                 importer.execute(filetable, transformers)
             else:  # if not m4base
-                m4dirs = list()
-                dirisnext = bool()
+                # Apply func_import to all gnulib directories.
+                # To get this list of directories, look at Makefile.am. (Not at
+                # configure, because it may be omitted from version control. Also,
+                # don't run "find $destdir -name gnulib-cache.m4", as it might be
+                # too expensive.)
+                m4dirs = []
+                dirisnext = False
                 filepath = joinpath(destdir, 'Makefile.am')
                 if isfile(filepath):
                     with codecs.open(filepath, 'rb', 'UTF-8') as file:
@@ -888,14 +896,18 @@ def main():
                     aclocal_amflags = data.split()
                     for aclocal_amflag in aclocal_amflags:
                         if dirisnext:
+                            # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
                             if not isabs(aclocal_amflag):
-                                m4dirs += [aclocal_amflag]
+                                if isfile(joinpath(destdir, joinpath(aclocal_amflag, 'gnulib-cache.m4'))):
+                                    m4dirs += [aclocal_amflag]
+                            dirisnext = False
                         else:  # if not dirisnext
                             if aclocal_amflag == '-I':
                                 dirisnext = True
                             else:  # if aclocal_amflag != '-I'
                                 dirisnext = False
                 else:  # if not isfile(filepath)
+                    # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
                     filepath = joinpath(destdir, 'aclocal.m4')
                     if isfile(filepath):
                         pattern = re.compile(r'm4_include\(\[(.*?)\]\)')
@@ -929,6 +941,8 @@ def main():
                     filetable, transformers = importer.prepare()
                     importer.execute(filetable, transformers)
                 elif len(m4dirs) == 1:
+                    # There's only one use of gnulib here. Assume the user means it.
+                    # Any number of additional modules can be given.
                     m4base = m4dirs[-1]
                     config.setM4Base(m4base)
                     # Perform GLImport actions.
@@ -936,6 +950,7 @@ def main():
                     filetable, transformers = importer.prepare()
                     importer.execute(filetable, transformers)
                 else:  # if len(m4dirs) > 1
+                    # No further arguments. Guess the user wants to update all of them.
                     for m4base in m4dirs:
                         config.setM4Base(m4base)
                         # Perform GLImport actions.
-- 
2.44.0

diff --git a/gl/Makefile.am b/gl/Makefile.am
index 88a7f50..2b2de9c 100644
--- a/gl/Makefile.am
+++ b/gl/Makefile.am
@@ -53,7 +53,6 @@ CLEANFILES =
 DISTCLEANFILES =
 MAINTAINERCLEANFILES =
 # No GNU Make output.
-EXTRA_DIST += m4/gnulib-cache.m4
 
 AM_CPPFLAGS =
 AM_CFLAGS =
@@ -116,12 +115,6 @@ EXTRA_DIST += $(top_srcdir)/build-aux/vc-list-files
 
 ## end   gnulib module vc-list-files
 
-## begin gnulib module dummy
-
-libgnu_a_SOURCES += dummy.c
-
-## end   gnulib module dummy
-
 
 mostlyclean-local: mostlyclean-generic
 	@for dir in '' $(MOSTLYCLEANDIRS); do \
diff --git a/gl/m4/gnulib-comp.m4 b/gl/m4/gnulib-comp.m4
index 31d21aa..790a72f 100644
--- a/gl/m4/gnulib-comp.m4
+++ b/gl/m4/gnulib-comp.m4
@@ -28,7 +28,7 @@
 # other built files.
 
 
-# This macro should be invoked from ./configure.ac, in the section
+# This macro should be invoked from configure.ac, in the section
 # "Checks for programs", right after AC_PROG_CC, and certainly before
 # any checks for libraries, header files, types and library functions.
 AC_DEFUN([gl_EARLY],
@@ -52,7 +52,7 @@ AC_DEFUN([gl_EARLY],
   # Code from module vc-list-files:
 ])
 
-# This macro should be invoked from ./configure.ac, in the section
+# This macro should be invoked from configure.ac, in the section
 # "Check for header files, types and library functions".
 AC_DEFUN([gl_INIT],
 [
@@ -86,6 +86,7 @@ AC_DEFUN([gl_INIT],
   AC_REQUIRE([AC_PROG_SED])
   AC_REQUIRE([AC_PROG_GREP])
   # End of code from modules
+
   m4_ifval(gl_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([gl_LIBSOURCES_DIR])[ ||
       for gl_file in ]gl_LIBSOURCES_LIST[ ; do
@@ -148,7 +149,9 @@ changequote([, ])dnl
   AC_SUBST([gltests_WITNESS])
   gl_module_indicator_condition=$gltests_WITNESS
   m4_pushdef([gl_MODULE_INDICATOR_CONDITION], [$gl_module_indicator_condition])
+
   m4_popdef([gl_MODULE_INDICATOR_CONDITION])
+
   m4_ifval(gltests_LIBSOURCES_LIST, [
     m4_syscmd([test ! -d ]m4_defn([gltests_LIBSOURCES_DIR])[ ||
       for gl_file in ]gltests_LIBSOURCES_LIST[ ; do

Reply via email to