changeset 38837:c3fece354ba9

gnulib-tool.py: Define and use two new global functions. * pygnulib/constants.py (remove_backslash_newline, combine_lines): New functions.
author Bruno Haible <bruno@clisp.org>
date Sat, 09 Sep 2017 12:48:58 +0200
parents 42df2563bf2b
children afb7d857d580
files pygnulib/GLModuleSystem.py pygnulib/GLTestDir.py pygnulib/constants.py
diffstat 3 files changed, 17 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/pygnulib/GLModuleSystem.py	Sat Sep 09 12:27:40 2017 +0200
+++ b/pygnulib/GLModuleSystem.py	Sat Sep 09 12:48:58 2017 +0200
@@ -707,7 +707,7 @@
             else:  # if not tests module
                 # TODO: unconditional automake snippet for nontests modules
                 snippet = self.getAutomakeSnippet_Conditional()
-                snippet = snippet.replace('\\\n', ' ')
+                snippet = constants.combine_lines(snippet)
                 pattern = compiler(
                     '^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M)
                 mentioned_files = pattern.findall(snippet)
@@ -1149,7 +1149,7 @@
             if type(module) is not GLModule:
                 raise(TypeError('each module must be a GLModule instance'))
             snippet = module.getAutomakeSnippet()
-            snippet = snippet.replace('\\\n', '')
+            snippet = constants.remove_backslash_newline(snippet)
             pattern = compiler(
                 '^lib_SOURCES[\t ]*\\+=[\t ]*(.*?)$', re.S | re.M)
             files = pattern.findall(snippet)
--- a/pygnulib/GLTestDir.py	Sat Sep 09 12:27:40 2017 +0200
+++ b/pygnulib/GLTestDir.py	Sat Sep 09 12:48:58 2017 +0200
@@ -727,6 +727,7 @@
         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)
         cleaned_files = list()
         tests_cleaned_files = list()
         built_sources = list()
@@ -736,7 +737,6 @@
 
         # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
         regex_find = list()
-        snippet = snippet.replace('\\\n', '')
         pattern = compiler('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
         regex_find += pattern.findall(snippet)
         pattern = compiler('^MOSTLYCLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
@@ -765,10 +765,10 @@
             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)
 
             # Extract the value of "CLEANFILES += ..." and "MOSTLYCLEANFILES += ...".
             regex_find = list()
-            snippet = snippet.replace('\\\n', '')
             pattern = compiler('^CLEANFILES[\t ]*\\+=(.*?)$', re.S | re.M)
             regex_find += pattern.findall(snippet)
             pattern = compiler(
--- a/pygnulib/constants.py	Sat Sep 09 12:27:40 2017 +0200
+++ b/pygnulib/constants.py	Sat Sep 09 12:48:58 2017 +0200
@@ -437,4 +437,17 @@
     return(text)
 
 
+def remove_backslash_newline(text):
+    '''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):
+    '''Given a multiline string text, join lines by spaces:
+    When a line ends in a backslash, remove the backslash and join the next
+    line to it, inserting a space between them.'''
+    return text.replace('\\\n', ' ')
+
+
 __all__ += ['APP', 'DIRS', 'MODES', 'UTILS']