Skip to content

Commit

Permalink
gnulib-tool.py: Avoid adding specific modules to a testdir.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bhaible committed Jul 28, 2024
1 parent 94046e1 commit 8f2cda7
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 16 deletions.
23 changes: 23 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,26 @@
2024-07-28 Bruno Haible <[email protected]>

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 <[email protected]>

gnulib-tool.py: Fix an exception message.
Expand Down
4 changes: 4 additions & 0 deletions modules/config-h
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions modules/lib-ignore
Original file line number Diff line number Diff line change
@@ -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

Expand Down
4 changes: 4 additions & 0 deletions modules/mountlist
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 4 additions & 0 deletions modules/non-recursive-gnulib-prefix-hack
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion modules/timevar
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions pygnulib/GLError.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ def __init__(self, errno: int, errinfo: Any = None) -> None:
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
Expand Down Expand Up @@ -113,5 +114,7 @@ def __repr__(self) -> str:
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
2 changes: 2 additions & 0 deletions pygnulib/GLInfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ def usage(self) -> str:
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
Expand Down Expand Up @@ -168,6 +169,7 @@ def usage(self) -> str:
--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
Expand Down
13 changes: 12 additions & 1 deletion pygnulib/GLModuleSystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -459,6 +459,17 @@ def getApplicability(self) -> str:
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', '')
Expand Down
29 changes: 15 additions & 14 deletions pygnulib/GLTestDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,26 @@ def execute(self) -> None:

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
Expand Down
17 changes: 17 additions & 0 deletions pygnulib/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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)

0 comments on commit 8f2cda7

Please sign in to comment.