From ffde99059e2f30c9b1030ce2cf9dae7fb41b3a73 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Wed, 1 May 2024 01:12:18 -0700 Subject: [PATCH] gnulib-tool.py: Use the GLModule's name variable directly. * pygnulib/GLModuleSystem.py (GLModule.getName): Remove function. (GLModule.__str__, GLModule.__repr__, GLModule.isNonTests) (GLModule.repeatModuleInTests, GLModule.getDependenciesRecursively) (GLModule.getShellFunc, GLModule.getShellVar) (GLModule.getConditionalName, GLModule.getApplicability) (GLModule.getDependencies, GLModule.getAutomakeSnippet_Unconditional) (GLModule.getLicense, GLModuleSystem.find) (GLModuleTable.transitive_closure): Use the GLModule's name instance variable instead of using str() or removed getName() function. * pygnulib/GLEmiter.py (GLEmiter.autoconfSnippet) (GLEmiter.preEarlyMacros, GLEmiter.lib_Makefile_am) (GLEmiter.tests_Makefile_am): Likewise. * pygnulib/GLImport.py (GLImport.gnulib_comp, GLImport.prepare): Likewise. * pygnulib/GLTestDir.py (GLTestDir.execute, GLMegaTestDir.execute): Likewise. --- ChangeLog | 20 ++++++++++++++ pygnulib/GLEmiter.py | 24 ++++++++--------- pygnulib/GLImport.py | 22 +++++++-------- pygnulib/GLModuleSystem.py | 55 +++++++++++++++++--------------------- pygnulib/GLTestDir.py | 32 +++++++++++----------- 5 files changed, 84 insertions(+), 69 deletions(-) diff --git a/ChangeLog b/ChangeLog index e2c736f854..917761a7d2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,23 @@ +2024-05-01 Collin Funk + + gnulib-tool.py: Use the GLModule's name variable directly. + * pygnulib/GLModuleSystem.py (GLModule.getName): Remove function. + (GLModule.__str__, GLModule.__repr__, GLModule.isNonTests) + (GLModule.repeatModuleInTests, GLModule.getDependenciesRecursively) + (GLModule.getShellFunc, GLModule.getShellVar) + (GLModule.getConditionalName, GLModule.getApplicability) + (GLModule.getDependencies, GLModule.getAutomakeSnippet_Unconditional) + (GLModule.getLicense, GLModuleSystem.find) + (GLModuleTable.transitive_closure): Use the GLModule's name instance + variable instead of using str() or removed getName() function. + * pygnulib/GLEmiter.py (GLEmiter.autoconfSnippet) + (GLEmiter.preEarlyMacros, GLEmiter.lib_Makefile_am) + (GLEmiter.tests_Makefile_am): Likewise. + * pygnulib/GLImport.py (GLImport.gnulib_comp, GLImport.prepare): + Likewise. + * pygnulib/GLTestDir.py (GLTestDir.execute, GLMegaTestDir.execute): + Likewise. + 2024-04-30 Paul Eggert intprops: document fix for GCC bug 68193 diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index 3fbf796aaa..38b23bbfcf 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -206,10 +206,10 @@ def autoconfSnippet(self, module: GLModule, toplevel: bool, disable_libtool: boo libtool = self.config['libtool'] include_guard_prefix = self.config['include_guard_prefix'] emit = '' - if str(module) in ['gnumakefile', 'maintainer-makefile']: + if module.name in ['gnumakefile', 'maintainer-makefile']: # These modules are meant to be used only in the top-level directory. flag = toplevel - else: # if str(module) not in ['gnumakefile', 'maintainer-makefile'] + else: # if module.name not in ['gnumakefile', 'maintainer-makefile'] flag = True if flag: snippet = module.getAutoconfSnippet() @@ -231,7 +231,7 @@ def autoconfSnippet(self, module: GLModule, toplevel: bool, disable_libtool: boo # autopoint through at least GNU gettext version 0.18.2. snippet = re.compile(r'^ *AM_GNU_GETTEXT_VERSION', re.M).sub(r'AM_GNU_GETTEXT_VERSION', snippet) emit += snippet - if str(module) == 'alloca' and libtool and not disable_libtool: + if module.name == 'alloca' and libtool and not disable_libtool: emit += 'changequote(,)dnl\n' emit += "LTALLOCA=`echo \"$ALLOCA\" | sed -e 's/\\.[^.]* /.lo /g;s/\\.[^.]*$/.lo/'`\n" emit += 'changequote([, ])dnl\n' @@ -396,7 +396,7 @@ def preEarlyMacros(self, require: bool, indentation: str, modules: list[GLModule emit = '\n' + indentation + '# Pre-early section.\n' # We need to call gl_USE_SYSTEM_EXTENSIONS before gl_PROG_AR_RANLIB. # Doing AC_REQUIRE in configure-ac.early is not early enough. - if any(str(module) == 'extensions' for module in modules): + if any(module.name == 'extensions' for module in modules): if require: emit += indentation + 'AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])\n' else: @@ -749,7 +749,7 @@ def lib_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: G amsnippet1 = amsnippet1.replace('check_PROGRAMS', 'noinst_PROGRAMS') amsnippet1 = amsnippet1.replace('${gl_include_guard_prefix}', include_guard_prefix) - if str(module) == 'alloca': + if module.name == 'alloca': amsnippet1 += '%s_%s_LIBADD += @%sALLOCA@\n' % (libname, libext, perhapsLT) amsnippet1 += '%s_%s_DEPENDENCIES += @%sALLOCA@\n' % (libname, libext, perhapsLT) amsnippet1 = combine_lines_matching(re.compile(r'%s_%s_SOURCES' % (libname, libext)), @@ -764,9 +764,9 @@ def lib_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: G '$(' + module_indicator_prefix + '_GNULIB_') # Skip the contents if it's entirely empty. if (amsnippet1 + amsnippet2).strip() != '': - allsnippets += '## begin gnulib module %s\n' % str(module) + allsnippets += '## begin gnulib module %s\n' % module.name if gnu_make: - allsnippets += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % str(module) + allsnippets += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % module.name allsnippets += '\n' if conddeps: if moduletable.isConditional(module): @@ -788,7 +788,7 @@ def lib_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: G allsnippets += amsnippet2 if gnu_make: allsnippets += 'endif\n' - allsnippets += '## end gnulib module %s\n\n' % str(module) + allsnippets += '## end gnulib module %s\n\n' % module.name # Test whether there are some source files in subdirectories. for file in module.getFiles(): @@ -1044,7 +1044,7 @@ def tests_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: amsnippet1 = amsnippet1.replace('${gl_include_guard_prefix}', include_guard_prefix) # Check if module is 'alloca'. - if libtests and str(module) == 'alloca': + if libtests and module.name == 'alloca': amsnippet1 += 'libtests_a_LIBADD += @ALLOCA@\n' amsnippet1 += 'libtests_a_DEPENDENCIES += @ALLOCA@\n' @@ -1059,9 +1059,9 @@ def tests_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: '$(' + module_indicator_prefix + '_GNULIB_') # Skip the contents if it's entirely empty. if (amsnippet1 + amsnippet2).strip() != '': - snippet = '## begin gnulib module %s\n' % str(module) + snippet = '## begin gnulib module %s\n' % module.name if gnu_make: - snippet += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % str(module) + snippet += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % module.name snippet += '\n' if conddeps: if moduletable.isConditional(module): @@ -1083,7 +1083,7 @@ def tests_Makefile_am(self, destfile: str, modules: list[GLModule], moduletable: snippet += amsnippet2 if gnu_make: snippet += 'endif\n' - snippet += '## end gnulib module %s\n\n' % str(module) + snippet += '## end gnulib module %s\n\n' % module.name # Mention long-running tests at the end. if 'longrunning-test' in module.getStatuses(): longrun_snippets += snippet diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index 63877342d2..833e186b8f 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -570,7 +570,7 @@ def gnulib_comp(self, filetable: GLFileTable, gentests: bool) -> str: m4_pattern_allow([^gl_LTLIBOBJS$])dnl a variable\n''' % (configure_ac, macro_prefix) emit += self.emitter.preEarlyMacros(True, ' ', moduletable.getFinalModules()) for module in moduletable.getFinalModules(): - emit += ' # Code from module %s:\n' % str(module) + emit += ' # Code from module %s:\n' % module.name snippet = module.getAutoconfEarlySnippet() lines = [ line for line in snippet.split('\n') @@ -762,10 +762,10 @@ def prepare(self) -> tuple[GLFileTable, dict[str, tuple[re.Pattern, str] | None] (bold_on, bold_off) = bold_escapes() print('Module list with included dependencies (indented):') for module in final_modules: - if str(module) in self.config.getModules(): - print(' %s%s%s' % (bold_on, module, bold_off)) - else: # if str(module) not in self.config.getModules() - print(' %s' % module) + if module.name in self.config.getModules(): + print(' %s%s%s' % (bold_on, module.name, bold_off)) + else: # if module.name not in self.config.getModules() + print(' %s' % module.name) # Separate modules into main_modules and tests_modules. modules = \ @@ -776,10 +776,10 @@ def prepare(self) -> tuple[GLFileTable, dict[str, tuple[re.Pattern, str] | None] if verbose >= 1: print('Main module list:') for module in main_modules: - print(' %s' % str(module)) + print(' %s' % module.name) print('Tests-related module list:') for module in tests_modules: - print(' %s' % str(module)) + print(' %s' % module.name) # Determine whether a $testsbase/libtests.a is needed. libtests = False @@ -819,10 +819,10 @@ def prepare(self) -> tuple[GLFileTable, dict[str, tuple[re.Pattern, str] | None] if license not in compatibilities['all']: if lgpl == True: if license not in compatibilities['3']: - listing.append(tuple([str(module), license])) + listing.append(tuple([module.name, license])) else: if license not in compatibilities[lgpl]: - listing.append(tuple([str(module), license])) + listing.append(tuple([module.name, license])) if listing: raise GLError(11, listing) @@ -831,14 +831,14 @@ def prepare(self) -> tuple[GLFileTable, dict[str, tuple[re.Pattern, str] | None] for module in main_modules: notice = module.getNotice().strip('\n') if notice: - print('Notice from module %s:' % str(module)) + print('Notice from module %s:' % module.name) pattern = re.compile(r'^(.*?)$', re.S | re.M) notice = pattern.sub(r' \1', notice) print(notice) # Determine script to apply to imported library files. sed_transform_lib_file = None - if 'config-h' in [ str(module) + if 'config-h' in [ module.name for module in main_modules ]: sed_transform_lib_file = (re.compile(r'^#ifdef[\t ]*HAVE_CONFIG_H[\t ]*$', re.MULTILINE), r'#if 1') diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 01ee393d12..2bfd5b252f 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -101,7 +101,7 @@ def find(self, module: str) -> GLModule | None: raise GLError(3, module) else: # if not self.config['errors'] sys.stderr.write('gnulib-tool: warning: ') - sys.stderr.write("module %s doesn't exist\n" % str(module)) + sys.stderr.write("module %s doesn't exist\n" % module.name) def file_is_module(self, filename: str) -> bool: '''Given the name of a file in the modules/ directory, return true @@ -272,18 +272,13 @@ def __lt__(self, module: object) -> bool: def __str__(self) -> str: '''x.__str__() <==> str(x)''' - result = self.getName() - return result + return self.name def __repr__(self) -> str: '''x.__repr__ <==> repr(x)''' - result = '' % (repr(self.getName()), hex(id(self))) + result = '' % (repr(self.name), hex(id(self))) return result - def getName(self) -> str: - '''Return the name of the module.''' - return self.name - def isPatched(self) -> bool: '''Check whether module was created after applying patch.''' return self.patched @@ -296,7 +291,7 @@ def isTests(self) -> bool: def isNonTests(self) -> bool: '''Check whether module is not a *-tests module.''' - result = not self.getName().endswith('-tests') + result = not self.name.endswith('-tests') return result def getTestsName(self) -> str: @@ -317,7 +312,7 @@ def repeatModuleInTests(self) -> bool: # tests contain such an invocation, the module - as part of tests - # will produce different AC_SUBSTed variable values than the same module # - as part of the main configure.ac -. - result = self.getName() == 'libtextstyle-optional' + result = self.name == 'libtextstyle-optional' return result def getDependenciesRecursively(self) -> str: @@ -343,7 +338,7 @@ def getDependenciesRecursively(self) -> str: # Remove handledmodules from inmodules. inmodules = inmodules.difference(handledmodules) - module_names = sorted([ str(module) + module_names = sorted([ module.name for module in outmodules ]) return lines_to_multiline(module_names) @@ -388,14 +383,14 @@ def getShellFunc(self) -> str: for the module.''' macro_prefix = self.config['macro_prefix'] valid_shell_id = True - for char in self.getName(): + for char in self.name: if char not in GLModule.shell_id_chars: valid_shell_id = False break if valid_shell_id: - identifier = self.getName() + identifier = self.name else: - hash_input = '%s\n' % self.getName() + hash_input = '%s\n' % self.name identifier = hashlib.md5(hash_input.encode(ENCS['default'])).hexdigest() result = 'func_%s_gnulib_m4code_%s' % (macro_prefix, identifier) return result @@ -405,14 +400,14 @@ def getShellVar(self) -> str: m4 macros for the module have been executed.''' macro_prefix = self.config['macro_prefix'] valid_shell_id = True - for char in self.getName(): + for char in self.name: if char not in GLModule.shell_id_chars: valid_shell_id = False break if valid_shell_id: - identifier = self.getName() + identifier = self.name else: - hash_input = '%s\n' % self.getName() + hash_input = '%s\n' % self.name identifier = hashlib.md5(hash_input.encode(ENCS['default'])).hexdigest() result = '%s_gnulib_enabled_%s' % (macro_prefix, identifier) return result @@ -422,14 +417,14 @@ def getConditionalName(self) -> str: GLConfig: macro_prefix.''' macro_prefix = self.config['macro_prefix'] valid_shell_id = True - for char in self.getName(): + for char in self.name: if char not in GLModule.shell_id_chars: valid_shell_id = False break if valid_shell_id: - identifier = self.getName() + identifier = self.name else: - hash_input = '%s\n' % self.getName() + hash_input = '%s\n' % self.name identifier = hashlib.md5(hash_input.encode(ENCS['default'])).hexdigest() result = '%s_GNULIB_ENABLED_%s' % (macro_prefix, identifier) return result @@ -467,7 +462,7 @@ def getApplicability(self) -> str: result = result.strip() if not result: # The default is 'main' or 'tests', depending on the module's name. - if self.getName().endswith('-tests'): + if self.name.endswith('-tests'): result = 'tests' else: result = 'main' @@ -497,8 +492,8 @@ def getDependencies(self) -> str: if 'dependencies' not in self.cache: result = '' # ${module}-tests implicitly depends on ${module}, if that module exists. - if self.getName().endswith('-tests'): - main_module = subend('-tests', '', self.getName()) + if self.name.endswith('-tests'): + main_module = subend('-tests', '', self.name) if self.modulesystem.exists(main_module): result += '%s\n' % main_module # Then the explicit dependencies listed in the module description. @@ -584,7 +579,7 @@ def getAutomakeSnippet_Unconditional(self) -> str: auxdir = self.config['auxdir'] result = '' if 'makefile-unconditional' not in self.cache: - if self.getName().endswith('-tests'): + if self.name.endswith('-tests'): # *-tests module live in tests/, not lib/. # Synthesize an EXTRA_DIST augmentation. files = self.getFiles() @@ -627,7 +622,7 @@ def getAutomakeSnippet_Unconditional(self) -> str: # If some .c file exists and is not used with AC_LIBOBJ - for example, # a .c file is preprocessed into another .c file for BUILT_SOURCES -, # automake will generate a useless dependency; this is harmless. - if str(self) != 'relocatable-prog-wrapper' and str(self) != 'pt_chown': + if self.name != 'relocatable-prog-wrapper' and self.name != 'pt_chown': extra_files = filter_filelist('\n', extra_files, '', '.c', '', '') if extra_files != '': @@ -666,13 +661,13 @@ def getLicense(self) -> str: if 'license' not in self.cache: license = self.getLicense_Raw().strip() # Warn if the License field is missing. - if not self.getName().endswith('-tests'): + if not self.name.endswith('-tests'): if not license: if self.config['errors']: - raise GLError(18, str(self)) + raise GLError(18, self.name) else: # if not self.config['errors'] - sys.stderr.write('gnulib-tool: warning: module %s lacks a License\n' % str(self)) - if str(self).startswith('parse-datetime'): + sys.stderr.write('gnulib-tool: warning: module %s lacks a License\n' % self.name) + if self.name.startswith('parse-datetime'): # These modules are under a weaker license only for the purpose of some # users who hand-edit it and don't use gnulib-tool. For the regular # gnulib users they are under a stricter license. @@ -852,7 +847,7 @@ def transitive_closure(self, modules: list[GLModule]) -> list[GLModule]: for depmodule in set(depmodules) if depmodules.count(depmodule) > 1 ] if duplicate_depmodules: - duplicate_depmodule_names = [ str(depmodule) + duplicate_depmodule_names = [ depmodule.name for depmodule in duplicate_depmodules ] message = ('gnulib-tool: warning: module %s has duplicated dependencies: %s\n' % (module, duplicate_depmodule_names)) diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index 8ddc1ea4c8..3394468016 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -221,13 +221,13 @@ def execute(self) -> None: if verbose >= 0: (bold_on, bold_off) = bold_escapes() print('Module list with included dependencies (indented):') - specified_modules_set = { str(module) + specified_modules_set = { module.name for module in specified_modules } for module in final_modules: - if str(module) in specified_modules_set: - print(' %s%s%s' % (bold_on, module, bold_off)) - else: # if str(module) not in specified_modules_set - print(' %s' % module) + if module.name in specified_modules_set: + print(' %s%s%s' % (bold_on, module.name, bold_off)) + else: # if module.name not in specified_modules_set + print(' %s' % module.name) # Generate lists of the modules. if single_configure: @@ -238,10 +238,10 @@ def execute(self) -> None: if verbose >= 1: print('Main module list:') for module in main_modules: - print(' %s' % str(module)) + print(' %s' % module.name) print('Tests-related module list:') for module in tests_modules: - print(' %s' % str(module)) + print(' %s' % module.name) # Determine whether a $testsbase/libtests.a is needed. libtests = False for module in tests_modules: @@ -267,7 +267,7 @@ def execute(self) -> None: for module in main_modules: notice = module.getNotice().strip('\n') if notice: - print('Notice from module %s:' % str(module)) + print('Notice from module %s:' % module.name) pattern = re.compile(r'^(.*)$', re.M) notice = pattern.sub(r' \1', notice) print(notice) @@ -276,7 +276,7 @@ def execute(self) -> None: for module in modules: notice = module.getNotice().strip('\n') if notice: - print('Notice from module %s:' % str(module)) + print('Notice from module %s:' % module.name) pattern = re.compile(r'^(.*)$', re.M) notice = pattern.sub(r' \1', notice) print(notice) @@ -417,10 +417,10 @@ def execute(self) -> None: emit += self.emitter.preEarlyMacros(False, '', modules) snippets = [] for module in modules: - if str(module) in ['gnumakefile', 'maintainer-makefile']: + if module.name in ['gnumakefile', 'maintainer-makefile']: # These are meant to be used only in the top-level directory. pass - # if str(module) not in ['gnumakefile', 'maintainer-makefile'] + # if module.name not in ['gnumakefile', 'maintainer-makefile'] else: snippet = module.getAutoconfEarlySnippet() lines = [ line @@ -894,16 +894,16 @@ def execute(self) -> None: # First, all modules one by one. for module in modules: - self.config.setModules([str(module)]) - GLTestDir(self.config, joinpath(self.megatestdir, str(module))).execute() - megasubdirs.append(str(module)) + self.config.setModules([module.name]) + GLTestDir(self.config, joinpath(self.megatestdir, module.name)).execute() + megasubdirs.append(module.name) # Then, all modules all together. # Except config-h, which breaks all modules which use HAVE_CONFIG_H. modules = [ module for module in modules - if str(module) != 'config-h' ] - self.config.setModules([ str(module) + if module.name != 'config-h' ] + self.config.setModules([ module.name for module in modules ]) GLTestDir(self.config, joinpath(self.megatestdir, 'ALL')).execute() megasubdirs.append('ALL') -- 2.44.0