I finally figured out why these lines are printed in Emacs
gnulib.mk.in:

+## begin gnulib module manywarnings
+ifeq (,$(OMIT_GNULIB_MODULE_manywarnings))
+
+endif
+## end   gnulib module manywarnings
+

The same thing happens for the 'warnings' module as well. This patch
fixes these added lines from gnulib-tool.py.

The shell script checks if an Automake snippet is non-empty by doing this:

if grep '[^      ]' "$tmp"/amsnippet1 "$tmp"/amsnippet2 > /dev/null ; then

But the Python script checks that the entire snippet is space
characters. I've simply added this function:

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

This is pretty similar to what the grep command is doing. The
line != '' is needed since .splitlines() removes the newline in
empty lines.

After this change the Emacs gnulib.mk.in is *almost* correct.
Hopefully these lines won't be too hard to track down. I am guessing
the issue is somewhere around
'GLModule.getAutomakeSnippet_Unconditional()' but that is just a
guess...

diff --git a/lib/gnulib.mk.in b/lib/gnulib.mk.in
index 6df7f6d9b00..49ca3229728 100644
--- a/lib/gnulib.mk.in
+++ b/lib/gnulib.mk.in
@@ -3296,7 +3296,9 @@ ifneq (,$(GL_COND_OBJ_STDIO_WRITE_CONDITION))
 libgnu_a_SOURCES += stdio-write.c
 endif
 
-EXTRA_DIST += stdio.in.h
+EXTRA_DIST += stdio-read.c stdio.in.h
+
+EXTRA_libgnu_a_SOURCES += stdio-read.c
 
 endif
 ## end   gnulib module stdio

Collin
From 2a5a782422d982e95525876ae5998f182d7a7fcd Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
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  <collin.fu...@gmail.com>
+
+	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  <collin.fu...@gmail.com>
 
 	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

Reply via email to