In a few of the import tests gnulib-tool.py doesn't add the 'dummy'
module even though gnulib-tool.sh does.

This is because the 'dummy' module was added after GLImport saved the
modules in the GLModuleTable:

        # Transmit base_modules, final_modules, main_modules and tests_modules.
        self.moduletable.setBaseModules(base_modules)
        self.moduletable.setFinalModules(final_modules)
        self.moduletable.setMainModules(main_modules)
        self.moduletable.setTestsModules(tests_modules)

After reordering these, the output is still incorrect. gnulib-tool.py
places the 'dummy' module at the top of the Makefiles, but
gnulib-tool.sh places them at the bottom.

Changing the moduletable functions to remove the sorting here seems to
fix the issue:

-        self.tests_modules = sorted(set(modules))
+        self.tests_modules = modules

This seems to be fine since GLModuleTable.transitive_closure and
GLModuleTable.transitive_closure_separately sort and remove duplicates
before these are called.

Collin
From 92e12249d21cd943e438df71ece71a2eb1cadb01 Mon Sep 17 00:00:00 2001
From: Collin Funk <[email protected]>
Date: Sat, 30 Mar 2024 03:23:46 -0700
Subject: [PATCH] gnulib-tool.py: Don't discard the 'dummy' module.

* pygnulib/GLImport.py (GLImport.prepare): Don't set modules stored in
the GLModuleTable until after the 'dummy' module is added.
* pygnulib/GLModuleSystem.py (GLImport.setBaseModules)
(GLImport.setFinalModules, GLImport.setMainModules)
(GLImport.setTestsModules): Don't sort modules since the 'dummy' module
should be placed last in the Makefiles.
---
 ChangeLog                  | 10 ++++++++++
 pygnulib/GLImport.py       | 12 ++++++------
 pygnulib/GLModuleSystem.py |  8 ++++----
 3 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 6d31a954c7..0c5695231f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-03-30  Collin Funk  <[email protected]>
+
+	gnulib-tool.py: Don't discard the 'dummy' module.
+	* pygnulib/GLImport.py (GLImport.prepare): Don't set modules stored in
+	the GLModuleTable until after the 'dummy' module is added.
+	* pygnulib/GLModuleSystem.py (GLImport.setBaseModules)
+	(GLImport.setFinalModules, GLImport.setMainModules)
+	(GLImport.setTestsModules): Don't sort modules since the 'dummy' module
+	should be placed last in the Makefiles.
+
 2024-03-29  Collin Funk  <[email protected]>
 
 	gnulib-tool.py: Fix reading of 'gl_VC_FILES' in gnulib-cache.m4.
diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py
index 81298eeca1..c3a7597d02 100644
--- a/pygnulib/GLImport.py
+++ b/pygnulib/GLImport.py
@@ -860,12 +860,6 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
             self.moduletable.transitive_closure_separately(base_modules, final_modules)
         main_modules, tests_modules = modules
 
-        # Transmit base_modules, final_modules, main_modules and tests_modules.
-        self.moduletable.setBaseModules(base_modules)
-        self.moduletable.setFinalModules(final_modules)
-        self.moduletable.setMainModules(main_modules)
-        self.moduletable.setTestsModules(tests_modules)
-
         # Print main_modules and tests_modules.
         if verbose >= 1:
             print('Main module list:')
@@ -892,6 +886,12 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix
             # Add the dummy module to the tests-related module list if needed.
             tests_modules = self.moduletable.add_dummy(tests_modules)
 
+        # Transmit base_modules, final_modules, main_modules and tests_modules.
+        self.moduletable.setBaseModules(base_modules)
+        self.moduletable.setFinalModules(final_modules)
+        self.moduletable.setMainModules(main_modules)
+        self.moduletable.setTestsModules(tests_modules)
+
         # Check license incompatibilities.
         listing = list()
         compatibilities = dict()
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index 6ec366eecd..4add195f2a 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -1102,7 +1102,7 @@ class GLModuleTable(object):
         for module in modules:
             if type(module) is not GLModule:
                 raise TypeError('each module must be a GLModule instance')
-        self.base_modules = sorted(set(modules))
+        self.base_modules = modules
 
     def getFinalModules(self) -> list[GLModule]:
         '''Return list of final modules.'''
@@ -1113,7 +1113,7 @@ class GLModuleTable(object):
         for module in modules:
             if type(module) is not GLModule:
                 raise TypeError('each module must be a GLModule instance')
-        self.final_modules = sorted(set(modules))
+        self.final_modules = modules
 
     def getMainModules(self) -> list[GLModule]:
         '''Return list of main modules.'''
@@ -1124,7 +1124,7 @@ class GLModuleTable(object):
         for module in modules:
             if type(module) is not GLModule:
                 raise TypeError('each module must be a GLModule instance')
-        self.main_modules = sorted(set(modules))
+        self.main_modules = modules
 
     def getTestsModules(self) -> list[GLModule]:
         '''Return list of tests modules.'''
@@ -1135,4 +1135,4 @@ class GLModuleTable(object):
         for module in modules:
             if type(module) is not GLModule:
                 raise TypeError('each module must be a GLModule instance')
-        self.tests_modules = sorted(set(modules))
+        self.tests_modules = modules
-- 
2.44.0

Reply via email to