From 0f23f389f4102a183c0cf7a3599f0f1318e7aaed Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 9 Sep 2017 12:48:58 +0200 Subject: [PATCH] gnulib-tool.py: Define and use two new global functions. * pygnulib/constants.py (remove_backslash_newline, combine_lines): New functions. --- pygnulib/GLModuleSystem.py | 4 ++-- pygnulib/GLTestDir.py | 4 ++-- pygnulib/constants.py | 13 +++++++++++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/pygnulib/GLModuleSystem.py b/pygnulib/GLModuleSystem.py index 6dab6dd56e..59109cce7e 100644 --- a/pygnulib/GLModuleSystem.py +++ b/pygnulib/GLModuleSystem.py @@ -707,7 +707,7 @@ Include:|Link:|License:|Maintainer:)' 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 @@ class GLModuleTable(object): 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) diff --git a/pygnulib/GLTestDir.py b/pygnulib/GLTestDir.py index 61407502ab..fded6d7656 100644 --- a/pygnulib/GLTestDir.py +++ b/pygnulib/GLTestDir.py @@ -727,6 +727,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) cleaned_files = list() tests_cleaned_files = list() built_sources = list() @@ -736,7 +737,6 @@ class GLTestDir(object): # 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 @@ 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) # 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( diff --git a/pygnulib/constants.py b/pygnulib/constants.py index 61d86a2192..596d1481bb 100644 --- a/pygnulib/constants.py +++ b/pygnulib/constants.py @@ -437,4 +437,17 @@ def nlremove(text): 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'] -- 2.39.5