changeset 38839:7a3e867d5bee

gnulib-tool.py: follow gnulib-tool changes, part 13 Follow gnulib-tool change 2015-06-01 Pádraig Brady <P@draigBrady.com> gnulib-tool: concatenate lib_SOURCES to a single line
author Bruno Haible <bruno@clisp.org>
date Sat, 09 Sep 2017 14:18:56 +0200
parents afb7d857d580
children 040712a0e597
files pygnulib/GLEmiter.py pygnulib/constants.py
diffstat 2 files changed, 28 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/pygnulib/GLEmiter.py	Sat Sep 09 14:16:35 2017 +0200
+++ b/pygnulib/GLEmiter.py	Sat Sep 09 14:18:56 2017 +0200
@@ -721,6 +721,9 @@
                         (libname, libext, perhapsLT)
                     amsnippet1 += '%s_%s_DEPENDENCIES += @%sALLOCA@\n' % \
                         (libname, libext, perhapsLT)
+                amsnippet1 = constants.combine_lines_matching(
+                                 compiler('%s_%s_SOURCES' % (libname, libext)),
+                                 amsnippet1)
 
                 # Get unconditional snippet, edit it and save to amsnippet2.
                 amsnippet2 = module.getAutomakeSnippet_Unconditional()
--- a/pygnulib/constants.py	Sat Sep 09 14:16:35 2017 +0200
+++ b/pygnulib/constants.py	Sat Sep 09 14:18:56 2017 +0200
@@ -449,5 +449,30 @@
     line to it, inserting a space between them.'''
     return text.replace('\\\n', ' ')
 
+def combine_lines_matching(pattern, text):
+    '''Given a multiline string text, join lines by spaces, when the first
+    such line matches a given RegexObject pattern.
+    When a line that matches the pattern ends in a backslash, remove the
+    backslash and join the next line to it, inserting a space between them.
+    When a line that is the result of such a join ends in a backslash,
+    proceed likewise.'''
+    outerpos = 0
+    match = pattern.search(text, outerpos)
+    while match:
+        (startpos, pos) = match.span()
+        # Look how far the continuation lines extend.
+        pos = text.find('\n',pos)
+        while pos > 0 and text[pos-1] == '\\':
+            pos = text.find('\n',pos+1)
+        if pos < 0:
+            pos = len(text)
+        # Perform a combine_lines throughout the continuation lines.
+        partdone = text[:startpos] + combine_lines(text[startpos:pos])
+        outerpos = len(partdone)
+        text = partdone + text[pos:]
+        # Next round.
+        match = pattern.search(text, outerpos)
+    return text
+
 
 __all__ += ['APP', 'DIRS', 'MODES', 'UTILS']