add_c_file: handle adding to the end of a list correctly.

Fixes bug 32962.
This commit is contained in:
Nick Mathewson 2020-01-15 12:54:47 -05:00 committed by teor
parent 5e70c27e85
commit ef1744e2c9
No known key found for this signature in database
GPG Key ID: 10FEAA0E7075672A

View File

@ -99,10 +99,14 @@ class AutomakeChunk:
def __init__(self): def __init__(self):
self.lines = [] self.lines = []
self.kind = "" self.kind = ""
self.hasBlank = False # true if we end with a blank line.
def addLine(self, line): def addLine(self, line):
""" """
Insert a line into this chunk while parsing the automake file. 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) m = self.pat.match(line)
if m: if m:
@ -110,10 +114,12 @@ class AutomakeChunk:
raise ValueError("control line not preceded by a blank line") raise ValueError("control line not preceded by a blank line")
self.kind = m.group(1) self.kind = m.group(1)
self.lines.append(line)
if line.strip() == "": if line.strip() == "":
self.hasBlank = True
return True return True
self.lines.append(line)
return False return False
def insertMember(self, member): def insertMember(self, member):
@ -145,8 +151,8 @@ class AutomakeChunk:
"{}{}{}\\\n".format(prespace, member, postspace)) "{}{}{}\\\n".format(prespace, member, postspace))
def insert_at_end(self, member, prespace, postspace): def insert_at_end(self, member, prespace, postspace):
lastline = self.lines[-1] lastline = self.lines[-1].strip()
self.lines[-1] += '{}\\\n'.format(postspace) self.lines[-1] = '{}{}{}\\\n'.format(prespace, lastline, postspace)
self.lines.append("{}{}\n".format(prespace, member)) self.lines.append("{}{}\n".format(prespace, member))
def dump(self, f): def dump(self, f):
@ -156,6 +162,9 @@ class AutomakeChunk:
if not line.endswith("\n"): if not line.endswith("\n"):
f.write("\n") f.write("\n")
if self.hasBlank:
f.write("\n")
class ParsedAutomake: class ParsedAutomake:
"""A sort-of-parsed automake file, with identified chunks into which """A sort-of-parsed automake file, with identified chunks into which
headers and c files can be inserted. headers and c files can be inserted.