]> Savannah Git Hosting - gnulib.git/commitdiff
gnulib-tool.py: Avoid adding specific modules to a testdir.
authorBruno Haible <bruno@clisp.org>
Sun, 28 Jul 2024 21:52:04 +0000 (23:52 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 28 Jul 2024 21:52:04 +0000 (23:52 +0200)
Reported by Paul Eggert in
<https://lists.gnu.org/archive/html/bug-gnulib/2024-07/msg00292.html>.

* pygnulib/GLInfo.py (GLInfo.usage): Document
--extract-usability-in-testdir option.
* pygnulib/GLModuleSystem.py (GLModule.section_label_pattern): Recognize
Usable-in-testdir section.
(GLModule.getUsabilityInTestdir): New function.
* pygnulib/GLTestDir.py (GLTestDir.execute): Invoke it to filter out
modules to avoid. Warn if such a module was specified.
* pygnulib/main.py (main): Add support for
--extract-usability-in-testdir. Provide an error message for error 24.
* pygnulib/GLError.py: Likewise.
* modules/config-h (Usable-in-testdir): New section.
* modules/lib-ignore (Usable-in-testdir): New section.
* modules/mountlist (Usable-in-testdir): New section.
* modules/non-recursive-gnulib-prefix-hack (Usable-in-testdir): New
section.
* modules/timevar (Usable-in-testdir): New section.
(Files): Remove lib/timevar.def.

ChangeLog
modules/config-h
modules/lib-ignore
modules/mountlist
modules/non-recursive-gnulib-prefix-hack
modules/timevar
pygnulib/GLError.py
pygnulib/GLInfo.py
pygnulib/GLModuleSystem.py
pygnulib/GLTestDir.py
pygnulib/main.py

index 6f0d66e02db93bf6900f24bf86af7eb361ff547f..0a03f64c1bd0edf53e9857187f8de738942a87dd 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,26 @@
+2024-07-28  Bruno Haible  <bruno@clisp.org>
+
+       gnulib-tool.py: Avoid adding specific modules to a testdir.
+       Reported by Paul Eggert in
+       <https://lists.gnu.org/archive/html/bug-gnulib/2024-07/msg00292.html>.
+       * pygnulib/GLInfo.py (GLInfo.usage): Document
+       --extract-usability-in-testdir option.
+       * pygnulib/GLModuleSystem.py (GLModule.section_label_pattern): Recognize
+       Usable-in-testdir section.
+       (GLModule.getUsabilityInTestdir): New function.
+       * pygnulib/GLTestDir.py (GLTestDir.execute): Invoke it to filter out
+       modules to avoid. Warn if such a module was specified.
+       * pygnulib/main.py (main): Add support for
+       --extract-usability-in-testdir. Provide an error message for error 24.
+       * pygnulib/GLError.py: Likewise.
+       * modules/config-h (Usable-in-testdir): New section.
+       * modules/lib-ignore (Usable-in-testdir): New section.
+       * modules/mountlist (Usable-in-testdir): New section.
+       * modules/non-recursive-gnulib-prefix-hack (Usable-in-testdir): New
+       section.
+       * modules/timevar (Usable-in-testdir): New section.
+       (Files): Remove lib/timevar.def.
+
 2024-07-28  Bruno Haible  <bruno@clisp.org>
 
        gnulib-tool.py: Fix an exception message.
index 0af7c3e2bb0bbaeba77fb131b97492ee887f1716..0d21277525c49eca4c06bc9112c6755e60c8d13e 100644 (file)
@@ -1,6 +1,10 @@
 Description:
 Assume config.h exists, to avoid -DHAVE_CONFIG_H clutter in 'make' output.
 
+Usable-in-testdir:
+# This module breaks all modules which use HAVE_CONFIG_H.
+no
+
 Files:
 m4/config-h.m4
 
index 8fe1c328c1f3acccc90bf942284e1beacb9dfb14..0c3d5e6922a6b06b155b9a31dee681a86e53777a 100644 (file)
@@ -1,6 +1,10 @@
 Description:
 If possible, ignore libraries that are not depended on.
 
+Usable-in-testdir:
+# This module leads to link errors when Sun C++ is used. FIXME
+no
+
 Files:
 m4/lib-ignore.m4
 
index f61038ec15986d564c9e302c8dd6fc0e969a9fda..99d9073151d63615a0169efa24d45d9340946083 100644 (file)
@@ -1,6 +1,10 @@
 Description:
 Return list of mounted file systems.
 
+Usable-in-testdir:
+# This module aborts the configuration on mingw. FIXME
+no
+
 Files:
 lib/mountlist.h
 lib/mountlist.c
index c188e93f4e9f4db7ac848a57e33b9278da7dd89a..4925bb99adc8e9449c9cc93679bc429d441cde19 100644 (file)
@@ -11,6 +11,10 @@ This module is deprecated. Instead,
   - remove the explicit invocation of build-aux/prefix-gnulib-mk from your build
     system.
 
+Usable-in-testdir:
+# This module represents a nonstandard way of using Automake.
+no
+
 Files:
 build-aux/prefix-gnulib-mk
 m4/non-recursive-gnulib-prefix-hack.m4
index a460a08de87f7c78596f759dc4576c858dc054b2..5f911cd27b9086091cb774231b4c222dbe28ebdd 100644 (file)
@@ -1,10 +1,13 @@
 Description:
 A simple self-profiling module based on timers.
 
+Usable-in-testdir:
+# This module lacks the required file timevar.def.
+no
+
 Files:
 lib/timevar.h
 lib/timevar.c
-lib/timevar.def
 
 Depends-on:
 c99
index 15e24a8bf21ae0e6488950fd9732786833ca097e..e57a50301fd35aab1911b19e24960fa0f1fc0656 100644 (file)
@@ -57,6 +57,7 @@ class GLError(Exception):
          21: Option --automake-subdir is only supported if the definition of AUTOMAKE_OPTIONS in Makefile.am contains 'subdir-objects'.
          22: not overwriting destination directory: <directory>
          23: module <module> doesn't exist
+         24: module <module> cannot be used in a testdir
         errinfo: additional information'''
         self.errno = errno
         self.errinfo = errinfo
@@ -113,5 +114,7 @@ class GLError(Exception):
                 message = 'not overwriting destination directory: %s' % repr(errinfo)
             elif errno == 23:
                 message = "module %s doesn't exist" % repr(errinfo)
+            elif errno == 24:
+                message = 'module %s cannot be used in a testdir' % repr(errinfo)
             self.message = '[Errno %d] %s' % (errno, message)
         return self.message
index eac4c65071ada5f066e265ce19591ebc32581d1f..9ed3ea61d40467bce71b2f96ed71ceaceae28147 100644 (file)
@@ -130,6 +130,7 @@ Usage: gnulib-tool --list
        gnulib-tool --extract-status module
        gnulib-tool --extract-notice module
        gnulib-tool --extract-applicability module
+       gnulib-tool --extract-usability-in-testdir module
        gnulib-tool --extract-filelist module
        gnulib-tool --extract-dependencies module
        gnulib-tool --extract-recursive-dependencies module
@@ -168,6 +169,7 @@ Operation modes:
       --extract-status             extract the status (obsolete etc.)
       --extract-notice             extract the notice or banner
       --extract-applicability      extract the applicability
+      --extract-usability-in-testdir  extract the usability in testdirs
       --extract-filelist           extract the list of files
       --extract-dependencies       extract the dependencies
       --extract-recursive-dependencies  extract the dependencies of the module
index 0eb875a499231d0587ec5801dcb5599f6db2a561..248d9ec80091459e196a2cb7c554785a16fc1017 100644 (file)
@@ -176,7 +176,7 @@ class GLModule:
 
     # Regular expression matching the start of a section in the module description.
     section_label_pattern: ClassVar[re.Pattern] = \
-        re.compile(r'^(Description|Comment|Status|Notice|Applicability|'
+        re.compile(r'^(Description|Comment|Status|Notice|Applicability|Usable-in-testdir|'
                    + r'Files|Depends-on|configure\.ac-early|configure\.ac|'
                    + r'Makefile\.am|Include|Link|License|Maintainer):$',
                    re.M)
@@ -459,6 +459,17 @@ class GLModule:
             self.cache['applicability'] = result
         return self.cache['applicability']
 
+    def getUsabilityInTestdir(self) -> str:
+        '''Return the usability-in-testdir of module.'''
+        if 'usability-in-testdir' not in self.cache:
+            snippet = self.sections.get('Usable-in-testdir', '')
+            result = [ line.strip()
+                       for line in snippet.split('\n')
+                       if not line.startswith('#') and line.strip() ]
+            result = lines_to_multiline(result).strip()
+            self.cache['usability-in-testdir'] = result
+        return self.cache['usability-in-testdir']
+
     def getFiles_Raw(self) -> str:
         '''Return the unmodified list of files as a string.'''
         return self.sections.get('Files', '')
index ad4549f734800fcbf08551a9ad0e287cd2a8ea40..ecedf992c6626666dc89b9e7325ab09b0e8c6b83 100644 (file)
@@ -145,25 +145,26 @@ class GLTestDir:
 
         specified_modules = self.config['modules']
         if len(specified_modules) == 0:
-            # All modules together.
-            # Except config-h, which breaks all modules which use HAVE_CONFIG_H.
-            # Except non-recursive-gnulib-prefix-hack, which represents a nonstandard
-            # way of using Automake.
-            # Except timevar, which lacks the required file timevar.def.
-            # Except mountlist, which aborts the configuration on mingw. FIXME.
-            # Except lib-ignore, which leads to link errors when Sun C++ is used. FIXME.
+            # All modules together, except those that are not usable in a testdir.
             specified_modules = self.modulesystem.list()
-            specified_modules = [module
-                                 for module in specified_modules
-                                 if module not in ['config-h', 'non-recursive-gnulib-prefix-hack', 'timevar',
-                                                   'mountlist', 'lib-ignore']]
+            specified_modules = [ module_name
+                                  for module_name in specified_modules
+                                  if self.modulesystem.find(module_name) is not None \
+                                      and self.modulesystem.find(module_name).getUsabilityInTestdir() != 'no' ]
 
         # Canonicalize the list of specified modules.
         modules = set()
-        for name in specified_modules:
-            module = self.modulesystem.find(name)
+        for module_name in specified_modules:
+            module = self.modulesystem.find(module_name)
             if module is not None:
-                modules.add(module)
+                if module.getUsabilityInTestdir() == 'no':
+                    if self.config['errors']:
+                        raise GLError(24, module_name)
+                    else:  # if not self.config['errors']
+                        sys.stderr.write('gnulib-tool: warning: ')
+                        sys.stderr.write('module %s cannot be used in a testdir\n' % module_name)
+                else:
+                    modules.add(module)
         specified_modules = sorted(modules)
 
         # Test modules which invoke AC_CONFIG_FILES cannot be used with
index 9767f386763b821fba2a05ffe216bb98cbaa25db..6953a84917d67ce663c5b11406818da975a037f0 100644 (file)
@@ -197,6 +197,10 @@ def main(temp_directory: str) -> None:
                         dest='mode_xapplicability',
                         default=None,
                         action='store_true')
+    parser.add_argument('--extract-usability-in-testdir',
+                        dest='mode_xusability_in_testdir',
+                        default=None,
+                        action='store_true')
     parser.add_argument('--extract-filelist',
                         dest='mode_xfilelist',
                         default=None,
@@ -551,6 +555,7 @@ def main(temp_directory: str) -> None:
         cmdargs.mode_xstatus,
         cmdargs.mode_xnotice,
         cmdargs.mode_xapplicability,
+        cmdargs.mode_xusability_in_testdir,
         cmdargs.mode_xfilelist,
         cmdargs.mode_xdependencies,
         cmdargs.mode_xautoconf,
@@ -625,6 +630,9 @@ def main(temp_directory: str) -> None:
     if cmdargs.mode_xapplicability != None:
         mode = 'extract-applicability'
         modules = list(cmdargs.non_option_arguments)
+    if cmdargs.mode_xusability_in_testdir != None:
+        mode = 'extract-usability-in-testdir'
+        modules = list(cmdargs.non_option_arguments)
     if cmdargs.mode_xfilelist != None:
         mode = 'extract-filelist'
         modules = list(cmdargs.non_option_arguments)
@@ -1189,6 +1197,13 @@ def main(temp_directory: str) -> None:
             if module:
                 print(module.getApplicability())
 
+    elif mode == 'extract-usability-in-testdir':
+        modulesystem = GLModuleSystem(config)
+        for name in modules:
+            module = modulesystem.find(name)
+            if module:
+                print(module.getUsabilityInTestdir())
+
     elif mode == 'extract-filelist':
         modulesystem = GLModuleSystem(config)
         for name in modules:
@@ -1459,6 +1474,8 @@ def main_with_exception_handling() -> None:
                 message += 'not overwriting destination directory: %s' % errinfo
             elif errno == 23:
                 message += "module %s doesn't exist" % errinfo
+            elif errno == 24:
+                message += 'module %s cannot be used in a testdir' % errinfo
             message += '\n%s: *** Stop.\n' % APP['name']
             sys.stderr.write(message)
             sys.exit(1)