>From ad534101bdf0b188babd525c4d54c9bf250763f7 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Fri, 5 Aug 2022 23:15:39 +0200 Subject: [PATCH 06/12] gnulib-tool.py: Refactor --makefile-name option. * gnulib-tool.py (main): Rename variable 'makefile' to 'makefile_name'. * pygnulib/GLConfig.py: Rename attribute 'makefile' to 'makefile_name'. * pygnulib/GLMakefileTable.py: Update. * pygnulib/GLEmiter.py: Likewise. * pygnulib/GLImport.py: Likewise. * pygnulib/GLFileSystem.py (GLFileAssistant): Remove unused assignment. --- ChangeLog | 8 ++++++++ gnulib-tool.py | 12 ++++++------ pygnulib/GLConfig.py | 38 ++++++++++++++++++------------------- pygnulib/GLEmiter.py | 24 +++++++++++------------ pygnulib/GLFileSystem.py | 1 - pygnulib/GLImport.py | 28 +++++++++++++-------------- pygnulib/GLMakefileTable.py | 10 +++++----- 7 files changed, 64 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index c48eabe254..85938bb76f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2022-08-05 Bruno Haible + gnulib-tool.py: Refactor --makefile-name option. + * gnulib-tool.py (main): Rename variable 'makefile' to 'makefile_name'. + * pygnulib/GLConfig.py: Rename attribute 'makefile' to 'makefile_name'. + * pygnulib/GLMakefileTable.py: Update. + * pygnulib/GLEmiter.py: Likewise. + * pygnulib/GLImport.py: Likewise. + * pygnulib/GLFileSystem.py (GLFileAssistant): Remove unused assignment. + gnulib-tool.py: Fix link_if_changed function. * pygnulib/constants.py (joinpath): Fix comment. (as_link_value_at_dest): New function, extracted from link_relative. diff --git a/gnulib-tool.py b/gnulib-tool.py index 4e5a87d4f2..9c63f6147f 100755 --- a/gnulib-tool.py +++ b/gnulib-tool.py @@ -83,7 +83,7 @@ def main(): tests = None libname = None lgpl = None - makefile = None + makefile_name = None libtool = None conddeps = None macro_prefix = None @@ -365,9 +365,9 @@ def main(): action='append', choices=['2', '3orGPLv2', '3'], nargs='?') - # makefile + # makefile-name parser.add_argument("--makefile-name", - dest="makefile", + dest="makefile_name", default=None, type=str) # single-configure @@ -555,7 +555,7 @@ def main(): or cmdargs.excl_privileged_tests != None or cmdargs.excl_unportable_tests != None or cmdargs.avoids != None or cmdargs.lgpl != None - or cmdargs.makefile != None))): + or cmdargs.makefile_name != None))): message = '%s: *** ' % constants.APP['name'] message += 'invalid options for --%s mode\n' % mode message += 'Try \'gnulib-tool --help\' for more information.\n' @@ -629,7 +629,7 @@ def main(): if lgpl == None: lgpl = True libtool = cmdargs.libtool - makefile = cmdargs.makefile + makefile_name = cmdargs.makefile_name avoids = cmdargs.avoids if avoids != None: avoids = [ module @@ -655,7 +655,7 @@ def main(): excl_test_categories=excl_test_categories, libname=libname, lgpl=lgpl, - makefile=makefile, + makefile_name=makefile_name, libtool=libtool, conddeps=conddeps, macro_prefix=macro_prefix, diff --git a/pygnulib/GLConfig.py b/pygnulib/GLConfig.py index baf61029c9..34788f0f74 100644 --- a/pygnulib/GLConfig.py +++ b/pygnulib/GLConfig.py @@ -56,7 +56,7 @@ class GLConfig(object): sourcebase=None, m4base=None, pobase=None, docbase=None, testsbase=None, modules=None, avoids=None, files=None, incl_test_categories=None, excl_test_categories=None, libname=None, - lgpl=None, makefile=None, libtool=None, conddeps=None, macro_prefix=None, + lgpl=None, makefile_name=None, libtool=None, conddeps=None, macro_prefix=None, podomain=None, witness_c_macro=None, vc_files=None, symbolic=None, lsymbolic=None, configure_ac=None, ac_version=None, libtests=None, single_configure=None, verbose=None, dryrun=None, @@ -130,10 +130,10 @@ class GLConfig(object): self.resetLGPL() if lgpl != None: self.setLGPL(lgpl) - # makefile - self.resetMakefile() - if makefile != None: - self.setMakefile(makefile) + # makefile_name + self.resetMakefileName() + if makefile_name != None: + self.setMakefileName(makefile_name) # libtool self.resetLibtool() if libtool != None: @@ -671,7 +671,7 @@ class GLConfig(object): def setInclTestCategory(self, category, enable): '''Enable or disable the given test category.''' - if (enable): + if enable: self.enableInclTestCategory(category) else: self.disableInclTestCategory(category) @@ -855,26 +855,26 @@ class GLConfig(object): include_guard_prefix = 'GL' self.table['include_guard_prefix'] = include_guard_prefix - # Define makefile methods. - def getMakefile(self): + # Define makefile_name methods. + def getMakefileName(self): '''Return the name of makefile in automake syntax in the source-base and tests-base directories. Default is 'Makefile.am'.''' - return self.table['makefile'] + return self.table['makefile_name'] - def setMakefile(self, makefile): + def setMakefileName(self, makefile_name): '''Specify the name of makefile in automake syntax in the source-base and tests-base directories. Default is 'Makefile.am'.''' - if type(makefile) is str: - if makefile: - self.table['makefile'] = makefile - else: # if type of makefile is not str - raise TypeError('makefile must be a string, not %s' - % type(makefile).__name__) - - def resetMakefile(self): + if type(makefile_name) is str: + if makefile_name: + self.table['makefile_name'] = makefile_name + else: # if type of makefile_name is not str + raise TypeError('makefile_name must be a string, not %s' + % type(makefile_name).__name__) + + def resetMakefileName(self): '''Reset the name of makefile in automake syntax in the source-base and tests-base directories. Default is 'Makefile.am'.''' - self.table['makefile'] = '' + self.table['makefile_name'] = '' # Define podomain methods. def getPoDomain(self): diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index 97bb585e3f..9d9ca458ee 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -604,7 +604,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ Emit the contents of the library Makefile. Returns str and a bool variable which shows if subdirectories are used. - GLConfig: localpath, sourcebase, libname, pobase, auxdir, makefile, libtool, + GLConfig: localpath, sourcebase, libname, pobase, auxdir, makefile_name, libtool, macro_prefix, podomain, conddeps, witness_c_macro. destfile is a filename relative to destdir of Makefile being generated. @@ -638,7 +638,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ libname = self.config['libname'] pobase = self.config['pobase'] auxdir = self.config['auxdir'] - makefile = self.config['makefile'] + makefile_name = self.config['makefile_name'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] podomain = self.config['podomain'] @@ -651,9 +651,9 @@ AC_DEFUN([%V1%_LIBSOURCES], [ # When creating an includable Makefile.am snippet, augment variables with # += instead of assigning them. - if makefile: + if makefile_name: assign = '+=' - else: # if not makefile + else: # if not makefile_name assign = '=' if libtool: libext = 'la' @@ -732,7 +732,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ and file.count('/') > 1): uses_subdirs = True break - if not makefile: + if not makefile_name: subdir_options = '' # If there are source files in subdirectories, prevent collision of the # object files (example: hash.c and libxml/hash.c). @@ -740,7 +740,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ subdir_options = ' subdir-objects' emit += 'AUTOMAKE_OPTIONS = 1.9.6 gnits%s\n' % subdir_options emit += '\n' - if not makefile: + if not makefile_name: emit += 'SUBDIRS =\n' emit += 'noinst_HEADERS =\n' emit += 'noinst_LIBRARIES =\n' @@ -758,7 +758,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ emit += 'BUILT_SOURCES =\n' emit += 'SUFFIXES =\n' emit += 'MOSTLYCLEANFILES %s core *.stackdump\n' % assign - if not makefile: + if not makefile_name: emit += 'MOSTLYCLEANDIRS =\n' emit += 'CLEANFILES =\n' emit += 'DISTCLEANFILES =\n' @@ -788,10 +788,10 @@ AC_DEFUN([%V1%_LIBSOURCES], [ if for_test: cppflags_part2 = ' -DGNULIB_STRICT_CHECKING=1' cppflags = '%s%s' % (cppflags_part1, cppflags_part2) - if not makefile: + if not makefile_name: emit += 'AM_CPPFLAGS =%s\n' % cppflags emit += 'AM_CFLAGS =\n' - else: # if makefile + else: # if makefile_name if cppflags: emit += 'AM_CPPFLAGS +=%s\n' % cppflags emit += '\n' @@ -807,7 +807,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ insnippets = bool(pattern.findall(allsnippets)) # Then test if $sourcebase/Makefile.am (if it exists) specifies it. path = joinpath(sourcebase, 'Makefile.am') - if makefile and isfile(path): + if makefile_name and isfile(path): with codecs.open(path, 'rb', 'UTF-8') as file: data = file.read() inmakefile = bool(pattern.findall(data)) @@ -866,7 +866,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ Emit the contents of the tests Makefile. Returns str and a bool variable which shows if subdirectories are used. - GLConfig: localpath, modules, libname, auxdir, makefile, libtool, + GLConfig: localpath, modules, libname, auxdir, makefile_name, libtool, sourcebase, m4base, testsbase, macro_prefix, witness_c_macro, single_configure, libtests. @@ -901,7 +901,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ m4base = self.config['m4base'] pobase = self.config['pobase'] testsbase = self.config['testsbase'] - makefile = self.config['makefile'] + makefile_name = self.config['makefile_name'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] podomain = self.config['podomain'] diff --git a/pygnulib/GLFileSystem.py b/pygnulib/GLFileSystem.py index bee38223d5..82f5f085b9 100644 --- a/pygnulib/GLFileSystem.py +++ b/pygnulib/GLFileSystem.py @@ -173,7 +173,6 @@ class GLFileAssistant(object): self.original = None self.rewritten = None self.added = list() - self.makefile = list() self.config = config self.transformers = transformers self.filesystem = GLFileSystem(self.config) diff --git a/pygnulib/GLImport.py b/pygnulib/GLImport.py index bf8171ea6b..dda10c1b76 100644 --- a/pygnulib/GLImport.py +++ b/pygnulib/GLImport.py @@ -193,7 +193,7 @@ class GLImport(object): if tempdict['gl_TESTS_BASE']: self.cache.setTestsBase(cleaner(tempdict['gl_TESTS_BASE'])) if tempdict['gl_MAKEFILE_NAME']: - self.cache.setMakefile(cleaner(tempdict['gl_MAKEFILE_NAME'])) + self.cache.setMakefileName(cleaner(tempdict['gl_MAKEFILE_NAME'])) if tempdict['gl_MACRO_PREFIX']: self.cache.setMacroPrefix(cleaner(tempdict['gl_MACRO_PREFIX'])) if tempdict['gl_PO_DOMAIN']: @@ -364,7 +364,7 @@ class GLImport(object): conddeps = self.config.checkCondDeps() libname = self.config.getLibName() lgpl = self.config.getLGPL() - makefile = self.config.getMakefile() + makefile_name = self.config.getMakefileName() libtool = self.config.checkLibtool() macro_prefix = self.config.getMacroPrefix() witness_c_macro = self.config.getWitnessCMacro() @@ -406,8 +406,8 @@ class GLImport(object): actioncmd += ' --lgpl' else: # if lgpl != True actioncmd += ' --lgpl=%s' % lgpl - if makefile: - actioncmd += ' --makefile-name=%s' % makefile + if makefile_name: + actioncmd += ' --makefile-name=%s' % makefile_name if conddeps: actioncmd += ' --conditional-dependencies' else: # if not conddeps @@ -479,7 +479,7 @@ class GLImport(object): testsbase = self.config['testsbase'] lgpl = self.config['lgpl'] libname = self.config['libname'] - makefile = self.config['makefile'] + makefile_name = self.config['makefile_name'] conddeps = self.config['conddeps'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] @@ -532,7 +532,7 @@ class GLImport(object): emit += 'gl_LGPL\n' else: # if lgpl != True emit += 'gl_LGPL([%s])\n' % lgpl - emit += 'gl_MAKEFILE_NAME([%s])\n' % makefile + emit += 'gl_MAKEFILE_NAME([%s])\n' % makefile_name if conddeps: emit += 'gl_CONDITIONAL_DEPENDENCIES\n' if libtool: @@ -562,7 +562,7 @@ class GLImport(object): testsbase = self.config['testsbase'] lgpl = self.config['lgpl'] libname = self.config['libname'] - makefile = self.config['makefile'] + makefile_name = self.config['makefile_name'] conddeps = self.config['conddeps'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] @@ -768,7 +768,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix lgpl = self.config['lgpl'] copyrights = self.config['copyrights'] libname = self.config['libname'] - makefile = self.config['makefile'] + makefile_name = self.config['makefile_name'] conddeps = self.config['conddeps'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] @@ -1004,7 +1004,7 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix lgpl = self.config['lgpl'] copyrights = self.config['copyrights'] libname = self.config['libname'] - makefile = self.config['makefile'] + makefile_name = self.config['makefile_name'] conddeps = self.config['conddeps'] libtool = self.config['libtool'] macro_prefix = self.config['macro_prefix'] @@ -1102,10 +1102,10 @@ AC_DEFUN([%s_FILE_LIST], [\n''' % macro_prefix include_guard_prefix = self.config['include_guard_prefix'] # Determine makefile name. - if not makefile: + if not makefile_name: makefile_am = 'Makefile.am' - else: # if makefile - makefile_am = makefile + else: # if makefile_name + makefile_am = makefile_name # Create normal Makefile.ams. for_test = False @@ -1414,14 +1414,14 @@ in _a_LDFLAGS or _la_LDFLAGS when linking a library.''') if makefile_am == 'Makefile.am': print(' - add "%s/Makefile" to AC_CONFIG_FILES in %s,' % (sourcebase, configure_ac)) else: # if makefile_am != 'Makefile.am' - print(' - "include %s" from within "%s/Makefile.am",' % (makefile, sourcebase)) + print(' - "include %s" from within "%s/Makefile.am",' % (makefile_name, sourcebase)) if pobase: print(' - add "%s/Makefile.in to AC_CONFIG_FILES in %s,' % (pobase, configure_ac)) if inctests: if makefile_am == 'Makefile.am': print(' - add "%s/Makefile" to AC_CONFIG_FILES in %s,' % (testsbase, configure_ac)) else: # if makefile_am != 'Makefile.am' - print(' - "include %s" from within "%s/Makefile.am",' % (makefile, testsbase)) + print(' - "include %s" from within "%s/Makefile.am",' % (makefile_name, testsbase)) # Print makefile edits. current_edit = int() makefile_am_edits = self.makefiletable.count() diff --git a/pygnulib/GLMakefileTable.py b/pygnulib/GLMakefileTable.py index abaeaf9d2e..d23f5710cb 100644 --- a/pygnulib/GLMakefileTable.py +++ b/pygnulib/GLMakefileTable.py @@ -81,18 +81,18 @@ class GLMakefileTable(object): Add a special row to Makefile.am table with the first parent directory which contains or will contain Makefile.am file. GLConfig: sourcebase, m4base, testsbase, incl_test_categories, - excl_test_categories, makefile.''' + excl_test_categories, makefile_name.''' m4base = self.config['m4base'] sourcebase = self.config['sourcebase'] testsbase = self.config['testsbase'] - makefile = self.config['makefile'] + makefile_name = self.config['makefile_name'] inctests = self.config.checkInclTestCategory(TESTS['tests']) dir1 = '%s%s' % (m4base, os.path.sep) mfd = 'Makefile.am' - if not makefile: + if not makefile_name: mfx = 'Makefile.am' - else: # if makefile - mfx = makefile + else: # if makefile_name + mfx = makefile_name dir2 = '' while (dir1 and (joinpath(self.config['destdir'], dir1, mfd) -- 2.34.1