I noticed that in a few places where gnulib-tool.sh uses
'combine_lines', gnulib-tool.py uses 'remove_backslash_newline'.

These functions behave differently. Using this Makefile:

$ cat Makefile 

FILES = file1.c\
file2.c\
file3.c

all:
        @echo $(FILES)

$ make
file1.c file2.c file3.c

The 'combine_lines' functions adds spaces when replacing the backslash
newlines. The 'remove_backslash_newline' doesn't. In other words, we
would get this string returned in gnulib-tool.py:

file1.cfile2.cfile3.c

I don't think that our module files or Makefiles are ever written like
this. But since gnulib-tool.sh accepts it, and it is valid Make,
gnulib-tool.py should accept it too.

Collin
From 9d27fa080158248a3038fb44bab8286d25166ad6 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 2 Apr 2024 03:58:37 -0700
Subject: [PATCH] gnulib-tool.py: Accept valid make syntax for escaped
 newlines.

* pygnulib/GLModuleSystem.py (GLModuleTable.add_dummy): Use
combine_lines instead of remove remove_backslash_newline so spaces are
added between each combined line.
* pygnulib/GLTestDir.py (GLTestDir.execute): Likewise.
* pygnulib/constants.py (remove_backslash_newline): Remove unused
function.
---
 ChangeLog                  | 10 ++++++++++
 pygnulib/GLModuleSystem.py |  3 ++-
 pygnulib/GLTestDir.py      |  5 +++--
 pygnulib/constants.py      |  7 -------
 4 files changed, 15 insertions(+), 10 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index d112f5ea99..4159305009 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2024-04-02  Collin Funk  <collin.fu...@gmail.com>
+
+	gnulib-tool.py: Accept valid make syntax for escaped newlines.
+	* pygnulib/GLModuleSystem.py (GLModuleTable.add_dummy): Use
+	combine_lines instead of remove remove_backslash_newline so spaces are
+	added between each combined line.
+	* pygnulib/GLTestDir.py (GLTestDir.execute): Likewise.
+	* pygnulib/constants.py (remove_backslash_newline): Remove unused
+	function.
+
 2024-04-01  Collin Funk  <collin.fu...@gmail.com>
 
 	gnulib-tool.py: Don't default to 'build-aux' for --auxdir.
diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py
index ba92d8a933..fac29883f9 100644
--- a/pygnulib/GLModuleSystem.py
+++ b/pygnulib/GLModuleSystem.py
@@ -47,6 +47,7 @@ TESTS = constants.TESTS
 joinpath = constants.joinpath
 subend = constants.subend
 lines_to_multiline = constants.lines_to_multiline
+combine_lines = constants.combine_lines
 isdir = os.path.isdir
 isfile = os.path.isfile
 filter_filelist = constants.filter_filelist
@@ -1033,7 +1034,7 @@ class GLModuleTable(object):
                 else:
                     snippet = module.getAutomakeSnippet()
                     # Extract the value of unconditional "lib_SOURCES += ..." augmentations.
-                    snippet = constants.remove_backslash_newline(snippet)
+                    snippet = combine_lines(snippet)
                     snippet = self.remove_if_blocks(snippet)
                     pattern = re.compile(r'^lib_SOURCES[\t ]*\+=([^#]*).*$', re.M)
                     for matching_rhs in pattern.findall(snippet):
diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py
index f0fe993c58..d6798f3bdc 100644
--- a/pygnulib/GLTestDir.py
+++ b/pygnulib/GLTestDir.py
@@ -57,6 +57,7 @@ copyfile = constants.copyfile
 ensure_writable = constants.ensure_writable
 movefile = constants.movefile
 lines_to_multiline = constants.lines_to_multiline
+combine_lines = constants.combine_lines
 isdir = os.path.isdir
 isfile = os.path.isfile
 normpath = os.path.normpath
@@ -755,7 +756,7 @@ class GLTestDir(object):
         path = joinpath(self.testdir, sourcebase, 'Makefile.am')
         with codecs.open(path, 'rb', 'UTF-8') as file:
             snippet = file.read()
-        snippet = constants.remove_backslash_newline(snippet)
+        snippet = combine_lines(snippet)
 
         # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
         regex_find = list()
@@ -800,7 +801,7 @@ class GLTestDir(object):
             path = joinpath(self.testdir, testsbase, 'Makefile.am')
             with codecs.open(path, 'rb', 'UTF-8') as file:
                 snippet = file.read()
-            snippet = constants.remove_backslash_newline(snippet)
+            snippet = combine_lines(snippet)
 
             # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
             regex_find = list()
diff --git a/pygnulib/constants.py b/pygnulib/constants.py
index 8f698fe01e..506d9c31dc 100644
--- a/pygnulib/constants.py
+++ b/pygnulib/constants.py
@@ -528,13 +528,6 @@ def remove_trailing_slashes(text: str) -> str:
     return result
 
 
-def remove_backslash_newline(text: str) -> str:
-    '''Given a multiline string text, join lines:
-    When a line ends in a backslash, remove the backslash and join the next
-    line to it.'''
-    return text.replace('\\\n', '')
-
-
 def combine_lines(text: str) -> str:
     '''Given a multiline string text, join lines by spaces:
     When a line ends in a backslash, remove the backslash and join the next
-- 
2.44.0

Reply via email to