From da5444f164200457ab1606cd5639cc3f4e26873c Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Wed, 13 Mar 2024 19:21:44 -0700 Subject: [PATCH] gnulib-tool.py: Fix write failure due to bad sourcebase. * pygnulib/constants.py (cleaner): Only call strip() on string objects. * pygnulib/main.py (main): Fix parsing of AMLOCAL_AMFLAGS from Makefile.am. Add some comments from gnulib-tool. --- ChangeLog | 7 +++++++ pygnulib/constants.py | 1 + pygnulib/main.py | 21 ++++++++++++++++++--- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index ace9a034f3..c77a884984 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-03-14 Collin Funk + + gnulib-tool.py: Fix write failure due to bad sourcebase. + * pygnulib/constants.py (cleaner): Only call strip() on string objects. + * pygnulib/main.py (main): Fix parsing of AMLOCAL_AMFLAGS from + Makefile.am. Add some comments from gnulib-tool. + 2024-03-13 Bruno Haible sig2str tests: Refactor. diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 918faa8cc0..a3bf8cd1d4 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -249,6 +249,7 @@ def cleaner(sequence): sequence = [ True if value == 'true' else value for value in sequence ] sequence = [ value.strip() + if type(value) is str else value for value in sequence ] return sequence diff --git a/pygnulib/main.py b/pygnulib/main.py index 7f710a2079..b145675f78 100644 --- a/pygnulib/main.py +++ b/pygnulib/main.py @@ -858,7 +858,10 @@ def main(): else: # if mode != MODE['--import'] if m4base: + # Apply func_import to a particular gnulib directory. + # Any number of additional modules can be given. if not isfile(joinpath(destdir, m4base, 'gnulib-cache.m4')): + # First use of gnulib in the given m4base. if not sourcebase: sourcebase = 'lib' if not docbase: @@ -877,8 +880,13 @@ def main(): filetable, transformers = importer.prepare() importer.execute(filetable, transformers) else: # if not m4base - m4dirs = list() - dirisnext = bool() + # Apply func_import to all gnulib directories. + # To get this list of directories, look at Makefile.am. (Not at + # configure, because it may be omitted from version control. Also, + # don't run "find $destdir -name gnulib-cache.m4", as it might be + # too expensive.) + m4dirs = [] + dirisnext = False filepath = joinpath(destdir, 'Makefile.am') if isfile(filepath): with codecs.open(filepath, 'rb', 'UTF-8') as file: @@ -888,14 +896,18 @@ def main(): aclocal_amflags = data.split() for aclocal_amflag in aclocal_amflags: if dirisnext: + # Ignore absolute directory pathnames, like /usr/local/share/aclocal. if not isabs(aclocal_amflag): - m4dirs += [aclocal_amflag] + if isfile(joinpath(destdir, joinpath(aclocal_amflag, 'gnulib-cache.m4'))): + m4dirs += [aclocal_amflag] + dirisnext = False else: # if not dirisnext if aclocal_amflag == '-I': dirisnext = True else: # if aclocal_amflag != '-I' dirisnext = False else: # if not isfile(filepath) + # No Makefile.am! Oh well. Look at the last generated aclocal.m4. filepath = joinpath(destdir, 'aclocal.m4') if isfile(filepath): pattern = re.compile(r'm4_include\(\[(.*?)\]\)') @@ -929,6 +941,8 @@ def main(): filetable, transformers = importer.prepare() importer.execute(filetable, transformers) elif len(m4dirs) == 1: + # There's only one use of gnulib here. Assume the user means it. + # Any number of additional modules can be given. m4base = m4dirs[-1] config.setM4Base(m4base) # Perform GLImport actions. @@ -936,6 +950,7 @@ def main(): filetable, transformers = importer.prepare() importer.execute(filetable, transformers) else: # if len(m4dirs) > 1 + # No further arguments. Guess the user wants to update all of them. for m4base in m4dirs: config.setM4Base(m4base) # Perform GLImport actions. -- 2.39.5