gcc-changelog: Support multiline parentheses wrapping

contrib/ChangeLog:

	* gcc-changelog/git_commit.py: Support wrapping of functions
	in parentheses that can take multiple lines.
	* gcc-changelog/test_email.py: Add tests for it.
	* gcc-changelog/test_patches.txt: Add 2 patches.
This commit is contained in:
Martin Liska 2021-01-13 16:54:02 +01:00
parent 285fa338b0
commit 7d7ef413ef
3 changed files with 100 additions and 2 deletions

View File

@ -214,6 +214,7 @@ class ChangeLogEntry:
self.lines = []
self.files = []
self.file_patterns = []
self.opened_parentheses = 0
def parse_file_names(self):
# Whether the content currently processed is between a star prefix the
@ -223,8 +224,14 @@ class ChangeLogEntry:
for line in self.lines:
# If this line matches the star prefix, start the location
# processing on the information that follows the star.
# Note that we need to skip macro names that can be in form of:
#
# * config/i386/i386.md (*fix_trunc<mode>_i387_1,
# *add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0,
# *fist<mode>2_<rounding>_1, *<code><mode>3_1):
#
m = star_prefix_regex.match(line)
if m:
if m and len(m.group('spaces')) == 1:
in_location = True
line = m.group('content')
@ -328,6 +335,7 @@ class GitCommit:
self.parse_changelog()
self.parse_file_names()
self.check_for_empty_description()
self.check_for_broken_parentheses()
self.deduce_changelog_locations()
self.check_file_patterns()
if not self.errors:
@ -496,7 +504,8 @@ class GitCommit:
else:
m = star_prefix_regex.match(line)
if m:
if len(m.group('spaces')) != 1:
if (len(m.group('spaces')) != 1 and
last_entry.opened_parentheses == 0):
msg = 'one space should follow asterisk'
self.errors.append(Error(msg, line))
else:
@ -508,6 +517,7 @@ class GitCommit:
msg = f'empty group "{needle}" found'
self.errors.append(Error(msg, line))
last_entry.lines.append(line)
self.process_parentheses(last_entry, line)
else:
if last_entry.is_empty:
msg = 'first line should start with a tab, ' \
@ -515,6 +525,18 @@ class GitCommit:
self.errors.append(Error(msg, line))
else:
last_entry.lines.append(line)
self.process_parentheses(last_entry, line)
def process_parentheses(self, last_entry, line):
for c in line:
if c == '(':
last_entry.opened_parentheses += 1
elif c == ')':
if last_entry.opened_parentheses == 0:
msg = 'bad wrapping of parenthesis'
self.errors.append(Error(msg, line))
else:
last_entry.opened_parentheses -= 1
def parse_file_names(self):
for entry in self.changelog_entries:
@ -538,6 +560,12 @@ class GitCommit:
msg = 'missing description of a change'
self.errors.append(Error(msg, line))
def check_for_broken_parentheses(self):
for entry in self.changelog_entries:
if entry.opened_parentheses != 0:
msg = 'bad parentheses wrapping'
self.errors.append(Error(msg, entry.lines[0]))
def get_file_changelog_location(self, changelog_file):
for file in self.info.modified_files:
if file[0] == changelog_file:

View File

@ -408,3 +408,11 @@ class TestGccChangelog(unittest.TestCase):
def test_modification_of_old_changelog(self):
email = self.from_patch_glob('0001-fix-old-ChangeLog.patch')
assert not email.errors
def test_multiline_parentheses(self):
email = self.from_patch_glob('0001-Add-macro.patch')
assert not email.errors
def test_multiline_bad_parentheses(self):
email = self.from_patch_glob('0002-Wrong-macro-changelog.patch')
assert email.errors[0].message == 'bad parentheses wrapping'

View File

@ -3418,4 +3418,66 @@ index 6553720acad..2c170ef014a 100644
--
2.29.2
=== 0001-Add-macro.patch ===
From 9b7eedc932fe594547fb060b36dfd9e4178c4f9b Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Wed, 13 Jan 2021 16:26:45 +0100
Subject: [PATCH 1/2] Add macro.
gcc/ChangeLog:
* config/i386/i386.md (*fix_trunc<mode>_i387_1, *add<mode>3_eq,
*add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0, *add<mode>3_eq,
*fist<mode>2_<rounding>_1, *<code><mode>3_1, *<code>di3_doubleword):
Use ix86_pre_reload_split instead of can_create_pseudo_p in condition.
* config/i386/sse.md
(*fix_trunc<mode>_i387_1, *add<mode>3_eq,
*add<mode>3_ne, *add<mode>3_eq_0, *add<mode>3_ne_0, *add<mode>3_eq,
*fist<mode>2_<rounding>_1): This should also work.
---
gcc/config/i386/i386.md | 1 +
gcc/config/i386/sse.md | 1 +
2 files changed, 2 insertions(+)
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index b60784a2908..ac63591b33f 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -1 +1,2 @@
+
diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md
index 7f03fc491c3..0e17997db26 100644
--- a/gcc/config/i386/sse.md
+++ b/gcc/config/i386/sse.md
@@ -1 +1,2 @@
+
--
2.29.2
=== 0002-Wrong-macro-changelog.patch ===
From 3542802111d4c6752ac7233ef96655b7fb78aae4 Mon Sep 17 00:00:00 2001
From: Martin Liska <mliska@suse.cz>
Date: Wed, 13 Jan 2021 16:54:58 +0100
Subject: [PATCH 2/2] Wrong macro changelog
gcc/ChangeLog:
* config/i386/i386.md (*fix_trunc<mode>_i387_1,
(foo): Change it.
---
gcc/config/i386/i386.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md
index ac63591b33f..ff4d61764e7 100644
--- a/gcc/config/i386/i386.md
+++ b/gcc/config/i386/i386.md
@@ -1 +1,2 @@
+
--
2.29.2