diff options
author | Nick Mathewson <nickm@torproject.org> | 2020-01-15 12:54:47 -0500 |
---|---|---|
committer | teor <teor@torproject.org> | 2020-01-16 09:23:49 +1000 |
commit | ef1744e2c938517220e8f27370c134efb78cdd0c (patch) | |
tree | 3d2773894862edab531d6e509b671957182f7a81 /scripts/maint/add_c_file.py | |
parent | 5e70c27e8560ac1885ae9d9e1b79d3838b49cc09 (diff) | |
download | tor-ef1744e2c938517220e8f27370c134efb78cdd0c.tar.gz tor-ef1744e2c938517220e8f27370c134efb78cdd0c.zip |
add_c_file: handle adding to the end of a list correctly.
Fixes bug 32962.
Diffstat (limited to 'scripts/maint/add_c_file.py')
-rwxr-xr-x | scripts/maint/add_c_file.py | 15 |
1 files changed, 12 insertions, 3 deletions
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. |