From 2a5a782422d982e95525876ae5998f182d7a7fcd Mon Sep 17 00:00:00 2001 From: Collin Funk Date: Mon, 18 Mar 2024 22:52:27 -0700 Subject: [PATCH 5/5] gnulib-tool.py: Don't emit empty Automake snippets. * pygnulib/GLEmiter.py (_is_nonempty_snippet): New private function to check if an Automake snippet should be emitted. (GLEmiter.lib_Makefile_am, GLEmiter.tests_Makefile_am): Use it. --- ChangeLog | 7 +++++++ pygnulib/GLEmiter.py | 11 +++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 58d7528e92..bed90aa944 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2024-03-18 Collin Funk + + gnulib-tool.py: Don't emit empty Automake snippets. + * pygnulib/GLEmiter.py (_is_nonempty_snippet): New private function to + check if an Automake snippet should be emitted. + (GLEmiter.lib_Makefile_am, GLEmiter.tests_Makefile_am): Use it. + 2024-03-18 Collin Funk gnulib-tool.py: Make sure temporary files are removed. diff --git a/pygnulib/GLEmiter.py b/pygnulib/GLEmiter.py index 16984e7d99..572a85d761 100644 --- a/pygnulib/GLEmiter.py +++ b/pygnulib/GLEmiter.py @@ -108,6 +108,13 @@ def _eliminate_NMD(snippet: str, automake_subdir: bool) -> str: return lines_to_multiline(result) +def _is_nonempty_snippet(snippet: str) -> bool: + '''Returns True if an Automake snippet is not empty, else False.''' + for line in snippet.splitlines(): + if line != '' and not (line.startswith(' ') or line.startswith('\t')): + return True + return False + #=============================================================================== # Define GLEmiter class #=============================================================================== @@ -832,7 +839,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ amsnippet2 = amsnippet2.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') # Skip the contents if it's entirely empty. - if not (amsnippet1 + amsnippet2).isspace(): + if _is_nonempty_snippet(amsnippet1 + amsnippet2): allsnippets += '## begin gnulib module %s\n' % str(module) if gnu_make: allsnippets += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % str(module) @@ -1146,7 +1153,7 @@ AC_DEFUN([%V1%_LIBSOURCES], [ amsnippet2 = amsnippet2.replace('$(GNULIB_', '$(' + module_indicator_prefix + '_GNULIB_') # Skip the contents if it's entirely empty. - if not (amsnippet1 + amsnippet2).isspace(): + if _is_nonempty_snippet(amsnippet1 + amsnippet2): snippet = '## begin gnulib module %s\n' % str(module) if gnu_make: snippet += 'ifeq (,$(OMIT_GNULIB_MODULE_%s))\n' % str(module) -- 2.44.0