Hey Bruno,

I *think* I did this patch correctly, but there are some code ordering
differences which are slightly confusing. I'm not sure if they can
cause issues or not.

Most of the changes in 'GLImport.py' are just translations of the
shell version. I've made one style change:

-        current_edit = int()
+        current_edit = 0

I've just changed it now since it was confusing to me and there are no
other occurrences of this convention.

In gnulib-tool.sh AC_CONFIG_AUX_DIR, A[CM]_PROG_LIBTOOL,
AC_CONFIG_MACRO_DIR, and AC_CONFIG_MACRO_DIRS are checked under:

import | add-import | remove-import | update ) ;;

In the Python version currently we check for AC_CONFIG_AUX_DIR and
A[CM]_PROG_LIBTOOL in GLImport.__init__(). This patch adds the checks
for AC_CONFIG_MACRO_DIR and AC_CONFIG_MACRO_DIRS in main() under:

elif mode in ['import', 'add-import', 'remove-import', 'update']:

Can the AC_CONFIG_AUX_DIR and A[CM]_PROG_LIBTOOL being checked in
every new GLImport cause any issues?

Also, I think my progress learning 'sed' is going well. :)
I am fairly confident I translated the backslashes correctly:

pattern = re.compile(r'^.*AC_CONFIG_MACRO_DIRS?\([\[ ]*([^\]"\$`\\\)]*).*$', 
re.MULTILINE)
print(pattern.findall('''AC_CONFIG_MACRO_DIR([dir1])dnl
AC_CONFIG_MACRO_DIRS(    [dir2]  )
AC_CONFIG_MACRO_DIR(    [dir3]   )'''))
['dir1', 'dir2', 'dir3']

Collin
From 52fcfd3a29f35cec9e458a96dd31118bc4ecf598 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Mon, 18 Mar 2024 12:23:46 -0700
Subject: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 65.

Follow gnulib-tool change
2021-12-19  Bruno Haible  <br...@clisp.org>
gnulib-tool: Don't insist on ACLOCAL_AMFLAGS.

* pygnulib/GLImport.py (GLImport.execute): Don't add extra '-I' before
m4 directory in ACLOCAL_AMFLAGS. Prefer '0' instead of 'int()'. Mention
the use of AC_CONFIG_MACRO_DIRS in configure.ac as an alternative to
augmenting ACLOCAL_AMFLAGS.
* pygnulib/main.py (main): To find the m4 directories, look also for
AC_CONFIG_MACRO_DIR and AC_CONFIG_MACRO_DIRS invocations in
configure.ac. Remove unnecessary call to 'joinpath' since it accepts a
variable length of arguments.
---
 ChangeLog            | 15 +++++++++++++++
 gnulib-tool.py.TODO  | 17 -----------------
 pygnulib/GLImport.py | 14 ++++++++++----
 pygnulib/main.py     | 18 +++++++++++++++++-
 4 files changed, 42 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 075a52f6b3..d24810a93c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2024-03-18  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Follow gnulib-tool changes, part 65.
+	Follow gnulib-tool change
+	2021-12-19  Bruno Haible  <br...@clisp.org>
+	gnulib-tool: Don't insist on ACLOCAL_AMFLAGS.
+	* pygnulib/GLImport.py (GLImport.execute): Don't add extra '-I' before
+	m4 directory in ACLOCAL_AMFLAGS. Prefer '0' instead of 'int()'. Mention
+	the use of AC_CONFIG_MACRO_DIRS in configure.ac as an alternative to
+	augmenting ACLOCAL_AMFLAGS.
+	* pygnulib/main.py (main): To find the m4 directories, look also for
+	AC_CONFIG_MACRO_DIR and AC_CONFIG_MACRO_DIRS invocations in
+	configure.ac. Remove unnecessary call to 'joinpath' since it accepts a
+	variable length of arguments.
+
 2024-03-18  Bruno Haible  <br...@clisp.org>
 
 	gnulib-tool.py: Tweak last change.
diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO
index 976439e2be..ada248c59f 100644
--- a/gnulib-tool.py.TODO
+++ b/gnulib-tool.py.TODO
@@ -88,23 +88,6 @@ Date:   Sat Dec 25 14:30:57 2021 +0100
 
 --------------------------------------------------------------------------------
 
-commit 4bdc327dbda59dcdbfa0f983a4f35c4a4ec3578c
-Author: Bruno Haible <br...@clisp.org>
-Date:   Sun Dec 19 12:49:16 2021 +0100
-
-    gnulib-tool: Don't insist on ACLOCAL_AMFLAGS.
-
-    Reported by Bjarni Ingi Gislason <bjarn...@rhi.hi.is> in
-    <https://lists.gnu.org/archive/html/bug-gnulib/2021-12/msg00112.html>.
-
-    * gnulib-tool (func_import): Mention an AC_CONFIG_MACRO_DIRS invocation
-    as an alternative to augmenting ACLOCAL_AMFLAGS.
-    (--import, --add-import, --remove-import, --update): To find the m4
-    directories, look also for AC_CONFIG_MACRO_DIR and AC_CONFIG_MACRO_DIRS
-    invocations in configure.ac.
-
---------------------------------------------------------------------------------
-
 commit 30459fe101541698ec704acb224946d73676750e
 Author: Bruno Haible <br...@clisp.org>
 Date:   Thu Jun 8 15:09:31 2017 +0200
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 5ab314af36..937c8d42e2 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -1181,7 +1181,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
                 testsbase_dir = os.path.dirname(testsbase)
                 testsbase_base = os.path.basename(testsbase)
                 self.makefiletable.editor(testsbase_dir, 'SUBDIRS', testsbase_base, True)
-        self.makefiletable.editor('', 'ACLOCAL_AMFLAGS', '-I %s' % m4base)
+        self.makefiletable.editor('', 'ACLOCAL_AMFLAGS', m4base)
         self.makefiletable.parent(gentests, source_makefile_am, tests_makefile_am)
 
         # Create library makefile.
@@ -1481,13 +1481,19 @@ in <library>_a_LDFLAGS or <library>_la_LDFLAGS when linking a library.''')
             else:  # if makefile_am != 'Makefile.am'
                 print('  - "include %s" from within "%s/Makefile.am",' % (tests_makefile_am, testsbase))
         # Print makefile edits.
-        current_edit = int()
+        current_edit = 0
         makefile_am_edits = self.makefiletable.count()
         while current_edit != makefile_am_edits:
             dictionary = self.makefiletable[current_edit]
             if dictionary['var']:
-                print('  - mention "%s" in %s in %s,'
-                      % (dictionary['val'], dictionary['var'], joinpath(dictionary['dir'], 'Makefile.am')))
+                if dictionary['var'] == 'ACLOCAL_AMFLAGS':
+                    print('  - mention "-I %s" in %s in %s'
+                          % (dictionary['val'], dictionary['var'], joinpath(dictionary['dir'], 'Makefile.am')))
+                    print('    or add an AC_CONFIG_MACRO_DIRS([%s]) invocation in %s,'
+                          % (dictionary['val'], configure_ac))
+                else:
+                    print('  - mention "%s" in %s in %s,'
+                          % (dictionary['val'], dictionary['var'], joinpath(dictionary['dir'], 'Makefile.am')))
             current_edit += 1
 
         # Detect position_early_after.
diff --git a/pygnulib/main.py b/pygnulib/main.py
index e4499400c6..5042cd3c82 100644
--- a/pygnulib/main.py
+++ b/pygnulib/main.py
@@ -872,6 +872,17 @@ def main():
             destdir = '.'
         config.setDestDir(destdir)
 
+        # Analyze configure.ac.
+        with open(joinpath(destdir, 'configure.ac'), 'r', encoding='utf-8') as file:
+            configure_ac_data = file.read()
+
+        guessed_m4dirs = []
+        pattern = re.compile(r'^.*AC_CONFIG_MACRO_DIRS?\([\[ ]*([^\]"\$`\\\)]*).*$', re.MULTILINE)
+        match = pattern.findall(configure_ac_data)
+        # Append the match to guessed_m4dirs.
+        if match:
+            guessed_m4dirs += match
+
         if mode == MODES['import']:
             # Set variables to default values.
             if not sourcebase:
@@ -937,7 +948,7 @@ def main():
                         if dirisnext:
                             # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
                             if not isabs(aclocal_amflag):
-                                if isfile(joinpath(destdir, joinpath(aclocal_amflag, 'gnulib-cache.m4'))):
+                                if isfile(joinpath(destdir, aclocal_amflag, 'gnulib-cache.m4')):
                                     m4dirs += [aclocal_amflag]
                             dirisnext = False
                         else:  # if not dirisnext
@@ -945,6 +956,11 @@ def main():
                                 dirisnext = True
                             else:  # if aclocal_amflag != '-I'
                                 dirisnext = False
+                    for arg in guessed_m4dirs:
+                        # Ignore absolute directory pathnames, like /usr/local/share/aclocal.
+                        if not isabs(arg):
+                            if isfile(joinpath(destdir, arg, 'gnulib-cache.m4')):
+                                m4dirs += [arg]
                 else:  # if not isfile(filepath)
                     # No Makefile.am! Oh well. Look at the last generated aclocal.m4.
                     filepath = joinpath(destdir, 'aclocal.m4')
-- 
2.44.0

Reply via email to