From cb06a3a076e67c146ffdbda7fbe2a14c048bca91 Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Sun, 17 Mar 2024 14:51:18 -0700 Subject: [PATCH] gnulib-tool.py: Follow gnulib-tool changes, part 63. Follow gnulib-tool change 2020-12-28 Bruno Haible gnulib-tool: Fix logic whether to add a dummy.c. * pygnulib/GLModuleSystem.py (GLModuleTable.remove_if_blocks): New function. (GLModuleTable.add_dummy): Use it to eliminate all conditional statements from the automake snippet. --- ChangeLog | 11 +++++++++++ gnulib-tool.py.TODO | 12 ------------ pygnulib/GLModuleSystem.py | 20 +++++++++++++++++++- 3 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index b1f7a3d1d3..9471f25a6e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2024-03-17 Collin Funk + + gnulib-tool.py: Follow gnulib-tool changes, part 63. + Follow gnulib-tool change + 2020-12-28 Bruno Haible + gnulib-tool: Fix logic whether to add a dummy.c. + * pygnulib/GLModuleSystem.py (GLModuleTable.remove_if_blocks): New + function. + (GLModuleTable.add_dummy): Use it to eliminate all conditional + statements from the automake snippet. + 2024-03-17 Collin Funk gnulib-tool.py: Don't print extra newlines. diff --git a/gnulib-tool.py.TODO b/gnulib-tool.py.TODO index 9a22e0ee77..8178b2fbfd 100644 --- a/gnulib-tool.py.TODO +++ b/gnulib-tool.py.TODO @@ -116,18 +116,6 @@ Date: Sun Dec 19 12:49:16 2021 +0100 -------------------------------------------------------------------------------- -commit 0be855ee827bf7e9043eeb626c4fd847704be2e6 -Author: Bruno Haible -Date: Tue Dec 29 02:48:31 2020 +0100 - - gnulib-tool: Fix logic whether to add a dummy.c. - - * gnulib-tool (func_remove_if_blocks): New function. - (func_modules_add_dummy): Use it to eliminate all conditional statements - from the automake snippet. - --------------------------------------------------------------------------------- - commit 30459fe101541698ec704acb224946d73676750e Author: Bruno Haible Date: Thu Jun 8 15:09:31 2017 +0200 diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 37433a42db..27f415a39a 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -1049,6 +1049,23 @@ class GLModuleTable(object): result = tuple([main_modules, tests_modules]) return result + def remove_if_blocks(self, snippet: str) -> str: + '''Removes if...endif blocks from an automake snippet.''' + lines = snippet.splitlines() + cleansed = [] + depth = 0 + for line in lines: + if line.startswith('if '): + depth += 1 + # Make sure gnulib-tool.py and gnulib-tool.sh produce the same + # output. + cleansed.append('') + elif line.startswith('endif'): + depth -= 1 + elif depth == 0: + cleansed.append(line) + return '\n'.join(cleansed) + def add_dummy(self, modules): '''GLModuleTable.add_dummy(modules) -> list @@ -1071,8 +1088,9 @@ class GLModuleTable(object): pass else: snippet = module.getAutomakeSnippet() - # Extract the value of "lib_SOURCES += ...". + # Extract the value of unconditional "lib_SOURCES += ..." augmentations. snippet = constants.remove_backslash_newline(snippet) + snippet = self.remove_if_blocks(snippet) pattern = re.compile('^lib_SOURCES[\t ]*\\+=([^#]*).*$', re.M) for matching_rhs in pattern.findall(snippet): files = matching_rhs.split(' ') -- 2.44.0