On 3/4/24 9:44 PM, Collin Funk wrote:
> I think the two lines I've linked are referring to the same thing. The
> 'inctest' was changed to 'gentests' in commit
> dc135c4fd14cdc219d316c61f344e64090cb33fd which is what I was working
> on. Shouldn't the Python one be using 'self.emitter.tests_Makefile_am'
> instead of 'self.emitter.lib_Makefile_am'?

I've figured this out while testing another patch. The first one fixes
the $testbase in $sourcebase issue. I've used the testcase from here,
with some version number changes for AC_PREREQ and such to avoid
warnings:

https://lists.gnu.org/archive/html/bug-gnulib/2018-09/msg00010.html

With the fix for this commit implemented we get the following diff:

diff --git a/subdir-test-python/libmissing/tests/Makefile.am 
b/subdir-test-shell/libmissing/tests/Makefile.am
index 316c91bdce..02cc8018a9 100644
--- a/subdir-test-python/libmissing/tests/Makefile.am
+++ b/subdir-test-shell/libmissing/tests/Makefile.am
@@ -21,26 +21,18 @@
 # the same distribution terms as the rest of that program.
 #
 # Generated by gnulib-tool.
-# Reproduce by:
-# gnulib-tool --import \
-#  --lib=libmissing \
-#  --source-base=libmissing \
-#  --m4-base=libmissing/m4 \
-#  --doc-base=doc \
-#  --tests-base=libmissing/tests \
-#  --aux-dir=build-aux \
-#  --with-tests \
-#  --no-conditional-dependencies \
-#  --no-libtool \
-#  --macro-prefix=gl \
-#  localcharset
 
-AUTOMAKE_OPTIONS = 1.11 gnits
+AUTOMAKE_OPTIONS = 1.14 foreign
 
-SUBDIRS =
+SUBDIRS = .
+TESTS =
+XFAIL_TESTS =
+TESTS_ENVIRONMENT =
+noinst_PROGRAMS =
+check_PROGRAMS =
+EXTRA_PROGRAMS =
 noinst_HEADERS =
 noinst_LIBRARIES =
-noinst_LTLIBRARIES =
 EXTRA_DIST =
 BUILT_SOURCES =
 SUFFIXES =
@@ -49,18 +41,45 @@ MOSTLYCLEANDIRS =
 CLEANFILES =
 DISTCLEANFILES =
 MAINTAINERCLEANFILES =
-# No GNU Make output.
 
-AM_CPPFLAGS =
-AM_CFLAGS =
+CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@ $(GL_CFLAG_GNULIB_WARNINGS) @CFLAGS@
+CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@
 
-noinst_LIBRARIES += libmissing.a
+AM_CPPFLAGS = \
+  -D@gltests_WITNESS@=1 \
+  -I. -I$(srcdir) \
+  -I../.. -I$(srcdir)/../.. \
+  -I../../libmissing -I$(srcdir)/../../libmissing

The second patch changes the GLEmiter.lib_Makefile_am call to
GLEmiter.tests_Makefile_am and changes the incorrect actioncmd
argument to '${macro_prefix}tests_WITNESS' so that it is correctly
placed in AM_CPPFLAGS.

After that we get the following diff:

diff --git a/subdir-test-python/libmissing/tests/Makefile.am 
b/subdir-test-shell/libmissing/tests/Makefile.am
index cf66e59d2a..02cc8018a9 100644
--- a/subdir-test-python/libmissing/tests/Makefile.am
+++ b/subdir-test-shell/libmissing/tests/Makefile.am
@@ -22,7 +22,7 @@
 #
 # Generated by gnulib-tool.
 
-AUTOMAKE_OPTIONS = 1.11 foreign
+AUTOMAKE_OPTIONS = 1.14 foreign
 
 SUBDIRS = .
 TESTS =
@@ -42,13 +42,16 @@ CLEANFILES =
 DISTCLEANFILES =
 MAINTAINERCLEANFILES =
 
+CFLAGS = @GL_CFLAG_ALLOW_WARNINGS@ $(GL_CFLAG_GNULIB_WARNINGS) @CFLAGS@
+CXXFLAGS = @GL_CXXFLAG_ALLOW_WARNINGS@ @CXXFLAGS@
+
 AM_CPPFLAGS = \
   -D@gltests_WITNESS@=1 \
   -I. -I$(srcdir) \
   -I../.. -I$(srcdir)/../.. \
   -I../../libmissing -I$(srcdir)/../../libmissing
 
-LDADD = ../../libmissing/libmissing.a libtests.a ../../libmissing/libmissing.a
+LDADD = ../../libmissing/libmissing.a

Which is less incorrect. :)

Collin
From 6eead93425dba15bf7aeb08733256f7e1661a482 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 5 Mar 2024 01:55:08 -0800
Subject: [PATCH 1/2] gnulib-tool.py: Follow gnulib-tool changes, part 41.

Follow gnulib-tool change
2018-09-03  Bruno Haible  <br...@clisp.org>
gnulib-tool: Fix build order when $testsbase is a subdir of $sourcebase.

* pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am): Consider the dotfirst
flag.
(GLEmiter.tests_Makefile_am): Don't consider the dotfirst flag.
* pygnulib/GLImport.py (GLImport.execute): Set the dotfirst for tests.
* pygnulib/GLMakefileTable.py (GLMakefileTable.editor): Add optional
dotfirst flag to fix build order when $testsbase is a subdir of
$sourcebase.
---
 ChangeLog                   | 14 ++++++++++++++
 gnulib-tool.py.TODO         | 15 ---------------
 pygnulib/GLEmiter.py        | 14 ++++++++++++--
 pygnulib/GLImport.py        |  2 +-
 pygnulib/GLMakefileTable.py | 13 +++++++++----
 5 files changed, 36 insertions(+), 22 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 06937dcba0..565d61dafa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2024-03-05  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Follow gnulib-tool changes, part 41.
+	Follow gnulib-tool change
+	2018-09-03  Bruno Haible  <br...@clisp.org>
+	gnulib-tool: Fix build order when $testsbase is a subdir of $sourcebase.
+	* pygnulib/GLEmiter.py (GLEmiter.lib_Makefile_am): Consider the dotfirst
+	flag.
+	(GLEmiter.tests_Makefile_am): Don't consider the dotfirst flag.
+	* pygnulib/GLImport.py (GLImport.execute): Set the dotfirst for tests.
+	* pygnulib/GLMakefileTable.py (GLMakefileTable.editor): Add optional
+	dotfirst flag to fix build order when $testsbase is a subdir of
+	$sourcebase.
+
 2024-03-04  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Follow gnulib-tool changes, part 40.
diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO
index 72cf630b54..2d8719a751 100644
--- a/gnulib-tool.py.TODO
+++ b/gnulib-tool.py.TODO
@@ -660,21 +660,6 @@ Date:   Fri Jan 4 19:34:19 2019 +0100
 
 --------------------------------------------------------------------------------
 
-commit 8b1d4a63e34f3893036d82f39c5680e845de5ddf
-Author: Bruno Haible <br...@clisp.org>
-Date:   Mon Sep 3 21:19:16 2018 +0200
-
-    gnulib-tool: Fix build order when $testsbase is a subdir of $sourcebase.
-
-    Reported by Antoine Luong <antoine.lu...@c-s.fr> in
-    <https://lists.gnu.org/archive/html/bug-gnulib/2018-09/msg00008.html>.
-
-    * gnulib-tool (func_import): For the tests, set a dotfirst flag.
-    (func_emit_lib_Makefile_am): Consider the dotfirst flag.
-    (func_emit_tests_Makefile_am): Don't consider the dotfirst flag.
-
---------------------------------------------------------------------------------
-
 commit cd58dba367a3b8ffbebb23f2099a820106197fae
 Author: Bruno Haible <br...@clisp.org>
 Date:   Sun Oct 29 16:57:32 2017 +0100
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 66833c4e98..57aeff1ae4 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -800,7 +800,12 @@ AC_DEFUN([%V1%_LIBSOURCES], [
             dictionary = makefiletable[current_edit]
             if dictionary['var']:
                 if destfile == joinpath(dictionary['dir'], 'Makefile.am'):
-                    emit += '%s += %s\n' % (dictionary['var'], dictionary['val'])
+                    val = dictionary['val']
+                    if dictionary['dotfirst']:
+                        # The added subdirectory ${val} needs to be mentioned after '.'.
+                        # Since we don't have '.' among SUBDIRS so far, add it now.
+                        val = f'. {val}'
+                    emit += '%s += %s\n' % (dictionary['var'], val)
                     dictionary.pop('var')
 
         # Define two parts of cppflags variable.
@@ -1099,7 +1104,12 @@ AC_DEFUN([%V1%_LIBSOURCES], [
             dictionary = makefiletable[current_edit]
             if dictionary['var']:
                 if destfile == joinpath(dictionary['dir'], 'Makefile.am'):
-                    emit += '%s += %s\n' % (dictionary['var'], dictionary['val'])
+                    val = dictionary['val']
+                    if dictionary['dotfirst']:
+                        # The added subdirectory ${val} needs to be mentioned after '.'.
+                        # But we have '.' among SUBDIRS already, so do nothing.
+                        pass
+                    emit += '%s += %s\n' % (dictionary['var'], val)
                     dictionary.pop('var')
 
         emit += '\nAM_CPPFLAGS = \\\n'
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 9cf9a96e30..0bac4ad18a 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -1093,7 +1093,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
             if makefile_am == 'Makefile.am':
                 testsbase_dir = os.path.dirname(testsbase)
                 testsbase_base = os.path.basename(testsbase)
-                self.makefiletable.editor(testsbase_dir, 'SUBDIRS', testsbase_base)
+                self.makefiletable.editor(testsbase_dir, 'SUBDIRS', testsbase_base, True)
         self.makefiletable.editor('', 'ACLOCAL_AMFLAGS', '-I %s' % m4base)
         self.makefiletable.parent()
 
diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py
index 9f6fa548e1..a63c2d6899 100644
--- a/pygnulib/GLMakefileTable.py
+++ b/pygnulib/GLMakefileTable.py
@@ -61,18 +61,23 @@ class GLMakefileTable(object):
         result = self.table[y]
         return dict(result)
 
-    def editor(self, dir, var, val):
-        '''GLMakefileTable.editor(dir, var, val)
+    def editor(self, dir, var, val, dotfirst=False):
+        '''GLMakefileTable.editor(dir, var, val, dotfirst)
 
         This method is used to remember that ${dir}Makefile.am needs to be edited
-        to that ${var} mentions ${val}.'''
+        to that ${var} mentions ${val}.
+        If ${dotfirst} is non-empty, this mention needs to be present after '.'.
+        This is a special hack for the SUBDIRS variable, cf.
+        <https://www.gnu.org/software/automake/manual/html_node/Subdirectories.html>.'''
         if type(dir) is not str:
             raise TypeError('dir must be a string, not %s' % (type(dir).__name__))
         if type(var) is not str:
             raise TypeError('var must be a string, not %s' % (type(var).__name__))
         if type(val) is not str:
             raise TypeError('val must be a string, not %s' % (type(val).__name__))
-        dictionary = {'dir': dir, 'var': var, 'val': val}
+        if type(dotfirst) is not bool:
+            raise TypeError('dotfirst must be a bool, not %s' % (type(dotfirst).__name__))
+        dictionary = {'dir': dir, 'var': var, 'val': val, 'dotfirst': dotfirst}
         self.table += [dictionary]
 
     def parent(self):
-- 
2.44.0

From b3dde187b3b453572bc4089a3e83c0d227a45ec4 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 5 Mar 2024 02:11:51 -0800
Subject: [PATCH 2/2] gnulib-tool.py: Fix incorrect tests Makefile.am
 generation.

* pygnulib/GLImport.py: Call GLEmiter.tests_Makefile_am instead of
GLEmiter.lib_Makefile_am when creating the tests Makefile. Replace
incorrect actioncmd argument with witness_macro.
---
 ChangeLog            | 7 +++++++
 pygnulib/GLImport.py | 6 +++---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 565d61dafa..5031f2f623 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,10 @@
+2024-03-05  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Fix incorrect tests Makefile.am generation.
+	* pygnulib/GLImport.py: Call GLEmiter.tests_Makefile_am instead of
+	GLEmiter.lib_Makefile_am when creating the tests Makefile. Replace
+	incorrect actioncmd argument with witness_macro.
+
 2024-03-05  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Follow gnulib-tool changes, part 41.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 0bac4ad18a..3075dc3e47 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -1279,9 +1279,9 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
         if inctests:
             basename = joinpath(testsbase, makefile_am)
             tmpfile = self.assistant.tmpfilename(basename)
-            emit, uses_subdirs = self.emitter.lib_Makefile_am(basename,
-                                                              self.moduletable['tests'], self.moduletable, self.makefiletable,
-                                                              actioncmd, for_test)
+            emit, uses_subdirs = self.emitter.tests_Makefile_am(basename,
+                                                                self.moduletable['tests'], self.moduletable, self.makefiletable,
+                                                                '%stests_WITNESS' % macro_prefix, for_test)
             with codecs.open(tmpfile, 'wb', 'UTF-8') as file:
                 file.write(emit)
             filename, backup, flag = self.assistant.super_update(basename, tmpfile)
-- 
2.44.0

Reply via email to