Today's patches:
2022-08-13 Bruno Haible <[email protected]>
gnulib-tool.py: Fix some code generation details.
* pygnulib/GLEmiter.py: Don't produce Windows CR-LFs on Windows.
(GLEmiter.po_Makevars): Emit a definition of top_builddir, not
top_subdir.
(GLEmiter.po_POTFILES_in): Fix result when sourcebase is 'tests' or
something like that.
(GLEmiter.initmacro_start): Add two more newlines (mistake from
2021-04-11).
gnulib-tool.py: Reduce code duplication.
* pygnulib/constants.py (relinverse): New function.
* pygnulib/GLEmiter.py (GLEmiter.po_Makevars,
GLEmiter.tests_Makefile_am): Use it.
* pygnulib/GLTestDir.py (GLTestDir.execute): Likewise.
From 01cd78f9d682ff75cc5ab1c2d21b911bdd9215b8 Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 13 Aug 2022 13:18:06 +0200
Subject: [PATCH 1/2] gnulib-tool.py: Reduce code duplication.
* pygnulib/constants.py (relinverse): New function.
* pygnulib/GLEmiter.py (GLEmiter.po_Makevars,
GLEmiter.tests_Makefile_am): Use it.
* pygnulib/GLTestDir.py (GLTestDir.execute): Likewise.
---
ChangeLog | 8 ++++++++
pygnulib/GLEmiter.py | 18 ++++--------------
pygnulib/GLTestDir.py | 12 ++----------
pygnulib/constants.py | 15 +++++++++++++++
4 files changed, 29 insertions(+), 24 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0d04cb70e7..1687348abe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2022-08-13 Bruno Haible <[email protected]>
+
+ gnulib-tool.py: Reduce code duplication.
+ * pygnulib/constants.py (relinverse): New function.
+ * pygnulib/GLEmiter.py (GLEmiter.po_Makevars,
+ GLEmiter.tests_Makefile_am): Use it.
+ * pygnulib/GLTestDir.py (GLTestDir.execute): Likewise.
+
2022-08-12 Marc Nieper-Wißkirchen <[email protected]>
hamt: fix technically undefined behavior
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index c0fd053077..4c8f0d90f2 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -42,6 +42,7 @@ __copyright__ = constants.__copyright__
#===============================================================================
TESTS = constants.TESTS
joinpath = constants.joinpath
+relinverse = constants.relinverse
isfile = os.path.isfile
normpath = os.path.normpath
@@ -390,13 +391,7 @@ class GLEmiter(object):
emit = ''
pobase = self.config['pobase']
podomain = self.config['podomain']
- top_subdir = ''
- source = '%s/' % os.path.normpath(pobase)
- if os.path.sep in source:
- for directory in source.split(os.path.sep):
- if directory != '':
- top_subdir += '../'
- top_subdir = os.path.normpath(top_subdir)
+ top_subdir = relinverse(pobase)
emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
emit += "%s\n" % self.copyright_notice()
emit += "# Usually the message domain is the same as the package name.\n"
@@ -941,13 +936,8 @@ AC_DEFUN([%V1%_LIBSOURCES], [
else: # if not for_test
edit_check_PROGRAMS = False
- # Calculate testsbase_inverse
- counter = int()
- testsbase_inverse = ''
- while counter < len(testsbase.split('/')):
- testsbase_inverse += '../'
- counter += 1
- testsbase_inverse = os.path.normpath(testsbase_inverse)
+ # Compute testsbase_inverse
+ testsbase_inverse = relinverse(testsbase)
# Begin the generation.
emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index bf00099283..68cc5ce411 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -48,6 +48,7 @@ DIRS = constants.DIRS
UTILS = constants.UTILS
TESTS = constants.TESTS
joinpath = constants.joinpath
+relinverse = constants.relinverse
copyfile = constants.copyfile
movefile = constants.movefile
isdir = os.path.isdir
@@ -405,16 +406,7 @@ class GLTestDir(object):
file.write(emit)
# Viewed from the $testsbase subdirectory, $auxdir is different.
emit = ''
- saved_auxdir = self.config['auxdir']
- testsbase = '%s/' % os.path.normpath(testsbase)
- counter = int()
- auxdir = ''
- finish = (len(testsbase.split('/')) - 1)
- while counter < finish:
- auxdir += '../'
- counter += 1
- auxdir = os.path.normpath(joinpath(auxdir, saved_auxdir))
- testsbase = os.path.normpath(testsbase)
+ auxdir = os.path.normpath(joinpath(relinverse(testsbase), auxdir))
self.config.setAuxDir(auxdir)
# Create $testsbase/configure.ac.
emit += '# Process this file with autoconf '
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index ae27d8d41a..10e11623b4 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -299,6 +299,21 @@ def relconcat(dir1, dir2):
return os.path.normpath(os.path.join(dir1, dir2))
+def relinverse(dir):
+ '''Compute the inverse of dir. Namely, a relative pathname consisting only
+ of '..' components, such that dir/relinverse = '.'.
+ dir must be a relative pathname.'''
+ if False:
+ # This should work too.
+ return relativize(dir, '.')
+ else:
+ inverse = ''
+ for component in dir.split('/'):
+ if component != '':
+ inverse += '../'
+ return os.path.normpath(inverse)
+
+
def copyfile(src, dest):
'''Copy file src to file dest. Like shutil.copy, but ignore errors e.g. on
VFAT file systems.'''
--
2.34.1
>From aa46eb2a5344ea32a973cdc2bb7b9d81d146543f Mon Sep 17 00:00:00 2001
From: Bruno Haible <[email protected]>
Date: Sat, 13 Aug 2022 15:02:55 +0200
Subject: [PATCH 2/2] gnulib-tool.py: Fix some code generation details.
* pygnulib/GLEmiter.py: Don't produce Windows CR-LFs on Windows.
(GLEmiter.po_Makevars): Emit a definition of top_builddir, not
top_subdir.
(GLEmiter.po_POTFILES_in): Fix result when sourcebase is 'tests' or
something like that.
(GLEmiter.initmacro_start): Add two more newlines (mistake from
2021-04-11).
---
ChangeLog | 9 +++++++
pygnulib/GLEmiter.py | 64 ++++++++++++++++++--------------------------
2 files changed, 35 insertions(+), 38 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 1687348abe..e0bf24fc90 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
2022-08-13 Bruno Haible <[email protected]>
+ gnulib-tool.py: Fix some code generation details.
+ * pygnulib/GLEmiter.py: Don't produce Windows CR-LFs on Windows.
+ (GLEmiter.po_Makevars): Emit a definition of top_builddir, not
+ top_subdir.
+ (GLEmiter.po_POTFILES_in): Fix result when sourcebase is 'tests' or
+ something like that.
+ (GLEmiter.initmacro_start): Add two more newlines (mistake from
+ 2021-04-11).
+
gnulib-tool.py: Reduce code duplication.
* pygnulib/constants.py (relinverse): New function.
* pygnulib/GLEmiter.py (GLEmiter.po_Makevars,
diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py
index 4c8f0d90f2..8c8b3ed8a7 100644
--- a/pygnulib/GLEmiter.py
+++ b/pygnulib/GLEmiter.py
@@ -94,7 +94,7 @@ class GLEmiter(object):
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.\n"""
- return constants.nlconvert(emit)
+ return emit
def autoconfSnippet(self, module, toplevel,
disable_libtool, disable_gettext, replace_auxdir, indentation):
@@ -388,10 +388,9 @@ class GLEmiter(object):
Emit the contents of po/ makefile parameterization.
GLConfig: pobase, podomain.'''
- emit = ''
pobase = self.config['pobase']
podomain = self.config['podomain']
- top_subdir = relinverse(pobase)
+ emit = ''
emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
emit += "%s\n" % self.copyright_notice()
emit += "# Usually the message domain is the same as the package name.\n"
@@ -399,7 +398,7 @@ class GLEmiter(object):
emit += "DOMAIN = %s-gnulib\n\n" % podomain
emit += "# These two variables depend on the location of this directory.\n"
emit += "subdir = %s\n" % pobase
- emit += "top_subdir = %s\n" % top_subdir
+ emit += "top_builddir = %s\n" % relinverse(pobase)
emit += """
# These options get passed to xgettext.
XGETTEXT_OPTIONS = \\
@@ -438,36 +437,32 @@ EXTRA_LOCALE_CATEGORIES =
# package uses functions taking also a message context, like pgettext(), or
# if in $(XGETTEXT_OPTIONS) you define keywords with a context argument.
USE_MSGCTXT = no\n"""
- return constants.nlconvert(emit)
+ return emit
def po_POTFILES_in(self, files):
'''GLEmiter.po_POTFILES_in(files) -> str
Emit the file list to be passed to xgettext.
GLConfig: sourcebase.'''
- emit = ''
sourcebase = self.config['sourcebase'] + os.path.sep
- files = [ constants.substart('lib/', sourcebase, file)
- for file in files ]
- files = [ file
- for file in files
- if file.startswith(sourcebase) ]
+ emit = ''
emit += "## DO NOT EDIT! GENERATED AUTOMATICALLY!\n"
emit += "%s\n" % self.copyright_notice()
emit += "# List of files which contain translatable strings.\n"
- emit += '\n'.join(files)
- emit += '\n'
- return constants.nlconvert(emit)
+ for file in files:
+ if file.startswith('lib/'):
+ emit += '%s\n' % constants.substart('lib/', sourcebase, file)
+ return emit
def initmacro_start(self, macro_prefix_arg):
'''GLEmiter.initmacro_start(macro_prefix_arg) -> str
Emit the first few statements of the gl_INIT macro.'''
- emit = ''
if type(macro_prefix_arg) is not str:
raise TypeError('macro_prefix_arg must be a string, not %s'
% type(macro_prefix_arg).__name__)
module_indicator_prefix = self.config.getModuleIndicatorPrefix()
+ emit = ''
# Overriding AC_LIBOBJ and AC_REPLACE_FUNCS has the effect of storing
# platform-dependent object files in ${macro_prefix_arg}_LIBOBJS instead
# of LIBOBJS. The purpose is to allow several gnulib instantiations under
@@ -475,45 +470,38 @@ USE_MSGCTXT = no\n"""
# flexibility).
# Furthermore it avoids an automake error like this when a Makefile.am
# that uses pieces of gnulib also uses $(LIBOBJ):
- # automatically discovered file `error.c' should not be explicitly
- # mentioned.
- emit += " m4_pushdef([AC_LIBOBJ],"
- emit += " m4_defn([%V1%_LIBOBJ]))\n"
- emit += " m4_pushdef([AC_REPLACE_FUNCS],"
- emit += " m4_defn([%V1%_REPLACE_FUNCS]))\n"
+ # automatically discovered file `error.c' should not be explicitly mentioned.
+ emit += " m4_pushdef([AC_LIBOBJ], m4_defn([%s_LIBOBJ]))\n" % macro_prefix_arg
+ emit += " m4_pushdef([AC_REPLACE_FUNCS], m4_defn([%s_REPLACE_FUNCS]))\n" % macro_prefix_arg
# Overriding AC_LIBSOURCES has the same purpose of avoiding the automake
# error when a Makefile.am that uses pieces of gnulib also uses $(LIBOBJ):
- # automatically discovered file `error.c' should not be explicitly
- # mentioned
+ # automatically discovered file `error.c' should not be explicitly mentioned
# We let automake know about the files to be distributed through the
# EXTRA_lib_SOURCES variable.
- emit += " m4_pushdef([AC_LIBSOURCES],"
- emit += " m4_defn([%V1%_LIBSOURCES]))\n"
+ emit += " m4_pushdef([AC_LIBSOURCES], m4_defn([%s_LIBSOURCES]))\n" % macro_prefix_arg
# Create data variables for checking the presence of files that are
# mentioned as AC_LIBSOURCES arguments. These are m4 variables, not shell
# variables, because we want the check to happen when the configure file is
# created, not when it is run. ${macro_prefix_arg}_LIBSOURCES_LIST is the
# list of files to check for. ${macro_prefix_arg}_LIBSOURCES_DIR is the
# subdirectory in which to expect them.
- emit += " m4_pushdef([%V1%_LIBSOURCES_LIST], [])\n"
- emit += " m4_pushdef([%V1%_LIBSOURCES_DIR], [])\n"
+ emit += " m4_pushdef([%s_LIBSOURCES_LIST], [])\n" % macro_prefix_arg
+ emit += " m4_pushdef([%s_LIBSOURCES_DIR], [])\n" % macro_prefix_arg
# Scope for m4 macros.
- emit += " m4_pushdef([GL_MACRO_PREFIX], [%V1%])"
+ emit += " m4_pushdef([GL_MACRO_PREFIX], [%s])\n" % macro_prefix_arg
# Scope the GNULIB_<modulename> variables.
- emit += " m4_pushdef([GL_MODULE_INDICATOR_PREFIX],"
- emit += " [" + module_indicator_prefix + "])"
+ emit += " m4_pushdef([GL_MODULE_INDICATOR_PREFIX], [%s])\n" % module_indicator_prefix
emit += " gl_COMMON\n"
- emit = emit.replace('%V1%', macro_prefix_arg)
- return constants.nlconvert(emit)
+ return emit
def initmacro_end(self, macro_prefix_arg):
'''GLEmiter.initmacro_end(macro_prefix_arg) -> str
Emit the last few statements of the gl_INIT macro.'''
- emit = ''
if type(macro_prefix_arg) is not str:
raise TypeError('macro_prefix_arg must be a string, not %s'
% type(macro_prefix_arg).__name__)
+ emit = ''
# Check the presence of files that are mentioned as AC_LIBSOURCES
# arguments. The check is performed only when autoconf is run from the
# directory where the configure.ac resides; if it is run from a different
@@ -552,20 +540,20 @@ USE_MSGCTXT = no\n"""
AC_SUBST([%V1%_LTLIBOBJS], [$%V1%_ltlibobjs])
])\n"""
emit = emit.replace('%V1%', macro_prefix_arg)
- return constants.nlconvert(emit)
+ return emit
def initmacro_done(self, macro_prefix_arg, sourcebase_arg):
'''GLEmiter.initmacro_done(macro_prefix_arg, sourcebase_arg) -> str
Emit a few statements after the gl_INIT macro.
GLConfig: sourcebase.'''
- emit = ''
if type(macro_prefix_arg) is not str:
raise TypeError('macro_prefix_arg must be a string, not %s'
% type(macro_prefix_arg).__name__)
if type(sourcebase_arg) is not str:
raise TypeError('sourcebase_arg must be a string, not %s'
% type(sourcebase_arg).__name__)
+ emit = ''
emit += """\
# Like AC_LIBOBJ, except that the module name goes
@@ -596,7 +584,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
])\n"""
emit = emit.replace('%V1%', macro_prefix_arg)
emit = emit.replace('%V2%', sourcebase_arg)
- return constants.nlconvert(emit)
+ return emit
def lib_Makefile_am(self, destfile, modules,
moduletable, makefiletable, actioncmd, for_test):
@@ -634,7 +622,6 @@ AC_DEFUN([%V1%_LIBSOURCES], [
if type(for_test) is not bool:
raise TypeError('for_test must be a bool, not %s'
% type(for_test).__name__)
- emit = ''
sourcebase = self.config['sourcebase']
libname = self.config['libname']
pobase = self.config['pobase']
@@ -649,6 +636,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
module_indicator_prefix = self.config.getModuleIndicatorPrefix()
ac_version = self.config['ac_version']
destfile = os.path.normpath(destfile)
+ emit = ''
# When creating an includable Makefile.am snippet, augment variables with
# += instead of assigning them.
@@ -900,7 +888,6 @@ AC_DEFUN([%V1%_LIBSOURCES], [
if type(for_test) is not bool:
raise TypeError('for_test must be a bool, not %s'
% type(for_test).__name__)
- emit = ''
auxdir = self.config['auxdir']
sourcebase = self.config['sourcebase']
libname = self.config['libname']
@@ -918,6 +905,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [
ac_version = self.config['ac_version']
libtests = self.config['libtests']
single_configure = self.config['single_configure']
+ emit = ''
if libtool:
libext = 'la'
--
2.34.1