From ef1744e2c938517220e8f27370c134efb78cdd0c Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 15 Jan 2020 12:54:47 -0500 Subject: add_c_file: handle adding to the end of a list correctly. Fixes bug 32962. --- scripts/maint/add_c_file.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'scripts/maint') diff --git a/scripts/maint/add_c_file.py b/scripts/maint/add_c_file.py index 9ec182efcc..6656d0d422 100755 --- a/scripts/maint/add_c_file.py +++ b/scripts/maint/add_c_file.py @@ -99,10 +99,14 @@ class AutomakeChunk: def __init__(self): self.lines = [] self.kind = "" + self.hasBlank = False # true if we end with a blank line. def addLine(self, line): """ Insert a line into this chunk while parsing the automake file. + + Return True if we have just read the last line in the chunk, and + False otherwise. """ m = self.pat.match(line) if m: @@ -110,10 +114,12 @@ class AutomakeChunk: raise ValueError("control line not preceded by a blank line") self.kind = m.group(1) - self.lines.append(line) if line.strip() == "": + self.hasBlank = True return True + self.lines.append(line) + return False def insertMember(self, member): @@ -145,8 +151,8 @@ class AutomakeChunk: "{}{}{}\\\n".format(prespace, member, postspace)) def insert_at_end(self, member, prespace, postspace): - lastline = self.lines[-1] - self.lines[-1] += '{}\\\n'.format(postspace) + lastline = self.lines[-1].strip() + self.lines[-1] = '{}{}{}\\\n'.format(prespace, lastline, postspace) self.lines.append("{}{}\n".format(prespace, member)) def dump(self, f): @@ -156,6 +162,9 @@ class AutomakeChunk: if not line.endswith("\n"): f.write("\n") + if self.hasBlank: + f.write("\n") + class ParsedAutomake: """A sort-of-parsed automake file, with identified chunks into which headers and c files can be inserted. -- cgit v1.2.3-54-g00ecf