mklog.py: improve parsing of struct names (ignore GTY).

Message ID 3ffd3b82-c0bb-4b5c-089b-6c5ea913e080@suse.cz
State New
Headers show
Series
  • mklog.py: improve parsing of struct names (ignore GTY).
Related show

Commit Message

Martin Liška May 19, 2020, 10:34 a.m.
Hi.

It's a small tweak to the newly added script.

Installed.

Martin

	* mklog.py: Skip GTY for struct names.  Make flake8 happy.
	* test_mklog.py: Add test for GTY.
---
  contrib/ChangeLog     |  5 +++++
  contrib/mklog.py      | 12 ++++++++----
  contrib/test_mklog.py | 29 +++++++++++++++++++++++++++++
  3 files changed, 42 insertions(+), 4 deletions(-)

Patch

diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index ca2834e541f..5ef08f41a92 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -1,3 +1,8 @@ 
+2020-05-19  Martin Liska  <mliska@suse.cz>
+
+	* mklog.py: Skip GTY for struct names.  Make flake8 happy.
+	* test_mklog.py: Add test for GTY.
+
 2020-05-19  Martin Liska  <mliska@suse.cz>
 
 	* gcc-changelog/git_update_version.py:
diff --git a/contrib/mklog.py b/contrib/mklog.py
index cc3f937c253..45559afbe6b 100755
--- a/contrib/mklog.py
+++ b/contrib/mklog.py
@@ -27,18 +27,21 @@ 
 # Author: Martin Liska <mliska@suse.cz>
 
 import argparse
-import bs4
 import os
 import re
-import requests
 import sys
 
+import bs4
+
+import requests
+
 from unidiff import PatchSet
 
 pr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?P<pr>PR [a-z+-]+\/[0-9]+)')
 identifier_regex = re.compile(r'^([a-zA-Z0-9_#].*)')
 comment_regex = re.compile(r'^\/\*')
-struct_regex = re.compile(r'^((class|struct|union|enum)\s+[a-zA-Z0-9_]+)')
+struct_regex = re.compile(r'^(class|struct|union|enum)\s+'
+                          r'(GTY\(.*\)\s+)?([a-zA-Z0-9_]+)')
 macro_regex = re.compile(r'#\s*(define|undef)\s+([a-zA-Z0-9_]+)')
 super_macro_regex = re.compile(r'^DEF[A-Z0-9_]+\s*\(([a-zA-Z0-9_]+)')
 fn_regex = re.compile(r'([a-zA-Z_][^()\s]*)\s*\([^*]')
@@ -73,7 +76,7 @@  def extract_function_name(line):
     m = struct_regex.search(line)
     if m:
         # Struct declaration
-        return m.group(1)
+        return m.group(1) + ' ' + m.group(3)
     m = macro_regex.search(line)
     if m:
         # Macro definition
@@ -117,6 +120,7 @@  def get_pr_titles(prs):
     output += '\n'
     return output
 
+
 def generate_changelog(data, no_functions=False, fill_pr_titles=False):
     changelogs = {}
     changelog_list = []
diff --git a/contrib/test_mklog.py b/contrib/test_mklog.py
index ca7b9e79d95..774b6ea62d0 100755
--- a/contrib/test_mklog.py
+++ b/contrib/test_mklog.py
@@ -319,6 +319,31 @@  gcc/testsuite/ChangeLog:
 
 '''
 
+PATCH6 = '''\
+diff --git a/gcc/cgraph.h b/gcc/cgraph.h
+index 5ddeb65269b..cfae6e91da9 100644
+--- a/gcc/cgraph.h
++++ b/gcc/cgraph.h
+@@ -937,7 +937,8 @@ struct GTY((tag ("SYMTAB_FUNCTION"))) cgraph_node : public symtab_node
+       split_part (false), indirect_call_target (false), local (false),
+       versionable (false), can_change_signature (false),
+       redefined_extern_inline (false), tm_may_enter_irr (false),
+-      ipcp_clone (false), m_uid (uid), m_summary_id (-1)
++      ipcp_clone (false), declare_variant_alt (false),
++      calls_declare_variant_alt (false), m_uid (uid), m_summary_id (-1)
+   {}
+ 
+   /* Remove the node from cgraph and all inline clones inlined into it.
+
+'''
+
+EXPECTED6 = '''\
+gcc/ChangeLog:
+
+	* cgraph.h (struct cgraph_node):
+
+'''
+
 class TestMklog(unittest.TestCase):
     def test_macro_definition(self):
         changelog = generate_changelog(PATCH1)
@@ -343,3 +368,7 @@  class TestMklog(unittest.TestCase):
     def test_pr_bugzilla_download(self):
         changelog = generate_changelog(PATCH5, fill_pr_titles=True)
         assert changelog == EXPECTED5
+
+    def test_gty_in_struct(self):
+        changelog = generate_changelog(PATCH6, fill_pr_titles=True)
+        assert changelog == EXPECTED6