From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1851) id 0011539730EF; Wed, 23 Jun 2021 08:11:04 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0011539730EF MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Martin Liska To: gcc-cvs@gcc.gnu.org Subject: [gcc r11-8641] Sync mklog.py from master. X-Act-Checkin: gcc X-Git-Author: Martin Liska X-Git-Refname: refs/heads/releases/gcc-11 X-Git-Oldrev: 930a8839154965d3d1e1e49465c7c9e9fc8e6e01 X-Git-Newrev: 914540797a8b3fadfe9e22a64597c4f2879de56c Message-Id: <20210623081105.0011539730EF@sourceware.org> Date: Wed, 23 Jun 2021 08:11:04 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jun 2021 08:11:05 -0000 https://gcc.gnu.org/g:914540797a8b3fadfe9e22a64597c4f2879de56c commit r11-8641-g914540797a8b3fadfe9e22a64597c4f2879de56c Author: Martin Liska Date: Wed Jun 23 10:10:37 2021 +0200 Sync mklog.py from master. contrib/ChangeLog: * mklog.py: Sync. * test_mklog.py: Likewise. Diff: --- contrib/mklog.py | 63 +++++++++++++++++++++++++++++++++++++++++---------- contrib/test_mklog.py | 10 ++++++-- 2 files changed, 59 insertions(+), 14 deletions(-) diff --git a/contrib/mklog.py b/contrib/mklog.py index 1604f0516d0..674c1dcd78b 100755 --- a/contrib/mklog.py +++ b/contrib/mklog.py @@ -39,8 +39,10 @@ import requests from unidiff import PatchSet pr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?PPR [a-z+-]+\/[0-9]+)') +prnum_regex = re.compile(r'PR (?P[a-z+-]+)/(?P[0-9]+)') dr_regex = re.compile(r'(\/(\/|\*)|[Cc*!])\s+(?PDR [0-9]+)') dg_regex = re.compile(r'{\s+dg-(error|warning)') +pr_filename_regex = re.compile(r'(^|[\W_])[Pp][Rr](?P\d{4,})') identifier_regex = re.compile(r'^([a-zA-Z0-9_#].*)') comment_regex = re.compile(r'^\/\*') struct_regex = re.compile(r'^(class|struct|union|enum)\s+' @@ -51,7 +53,7 @@ fn_regex = re.compile(r'([a-zA-Z_][^()\s]*)\s*\([^*]') template_and_param_regex = re.compile(r'<[^<>]*>') md_def_regex = re.compile(r'\(define.*\s+"(.*)"') bugzilla_url = 'https://gcc.gnu.org/bugzilla/rest.cgi/bug?id=%s&' \ - 'include_fields=summary' + 'include_fields=summary,component' function_extensions = {'.c', '.cpp', '.C', '.cc', '.h', '.inc', '.def', '.md'} @@ -67,6 +69,8 @@ PATCH must be generated using diff(1)'s -up or -cp options script_folder = os.path.realpath(__file__) root = os.path.dirname(os.path.dirname(script_folder)) +firstpr = '' + def find_changelog(path): folder = os.path.split(path)[0] @@ -115,26 +119,32 @@ def sort_changelog_files(changed_file): def get_pr_titles(prs): - output = '' - for pr in prs: + output = [] + for idx, pr in enumerate(prs): pr_id = pr.split('/')[-1] r = requests.get(bugzilla_url % pr_id) bugs = r.json()['bugs'] if len(bugs) == 1: - output += '%s - %s\n' % (pr, bugs[0]['summary']) - print(output) + prs[idx] = 'PR %s/%s' % (bugs[0]['component'], pr_id) + out = '%s - %s\n' % (prs[idx], bugs[0]['summary']) + if out not in output: + output.append(out) if output: - output += '\n' - return output + output.append('') + return '\n'.join(output) -def generate_changelog(data, no_functions=False, fill_pr_titles=False): +def generate_changelog(data, no_functions=False, fill_pr_titles=False, + additional_prs=None): changelogs = {} changelog_list = [] prs = [] out = '' diff = PatchSet(data) + global firstpr + if additional_prs: + prs = [pr for pr in additional_prs if pr not in prs] for file in diff: # skip files that can't be parsed if file.path == '/dev/null': @@ -150,32 +160,52 @@ def generate_changelog(data, no_functions=False, fill_pr_titles=False): # Only search first ten lines as later lines may # contains commented code which a note that it # has not been tested due to a certain PR or DR. + this_file_prs = [] for line in list(file)[0][0:10]: m = pr_regex.search(line.value) if m: pr = m.group('pr') if pr not in prs: prs.append(pr) + this_file_prs.append(pr.split('/')[-1]) else: m = dr_regex.search(line.value) if m: dr = m.group('dr') if dr not in prs: prs.append(dr) + this_file_prs.append(dr.split('/')[-1]) elif dg_regex.search(line.value): # Found dg-warning/dg-error line break + # PR number in the file name + fname = os.path.basename(file.path) + m = pr_filename_regex.search(fname) + if m: + pr = m.group('pr') + pr2 = 'PR ' + pr + if pr not in this_file_prs and pr2 not in prs: + prs.append(pr2) + + if prs: + firstpr = prs[0] if fill_pr_titles: out += get_pr_titles(prs) + # print list of PR entries before ChangeLog entries + if prs: + if not out: + out += '\n' + for pr in prs: + out += '\t%s\n' % pr + out += '\n' + # sort ChangeLog so that 'testsuite' is at the end for changelog in sorted(changelog_list, key=lambda x: 'testsuite' in x): files = changelogs[changelog] out += '%s:\n' % os.path.join(changelog, 'ChangeLog') out += '\n' - for pr in prs: - out += '\t%s\n' % pr # new and deleted files should be at the end for file in sorted(files, key=sort_changelog_files): assert file.path.startswith(changelog) @@ -273,6 +303,9 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description=help_message) parser.add_argument('input', nargs='?', help='Patch file (or missing, read standard input)') + parser.add_argument('-b', '--pr-numbers', action='store', + type=lambda arg: arg.split(','), nargs='?', + help='Add the specified PRs (comma separated)') parser.add_argument('-s', '--no-functions', action='store_true', help='Do not generate function names in ChangeLogs') parser.add_argument('-p', '--fill-up-bug-titles', action='store_true', @@ -296,14 +329,20 @@ if __name__ == '__main__': update_copyright(data) else: output = generate_changelog(data, args.no_functions, - args.fill_up_bug_titles) + args.fill_up_bug_titles, args.pr_numbers) if args.changelog: lines = open(args.changelog).read().split('\n') start = list(takewhile(lambda l: not l.startswith('#'), lines)) end = lines[len(start):] with open(args.changelog, 'w') as f: + if not start or not start[0]: + # initial commit subject line 'component: [PRnnnnn]' + m = prnum_regex.match(firstpr) + if m: + title = f'{m.group("comp")}: [PR{m.group("num")}]' + start.insert(0, title) if start: - # appent empty line + # append empty line if start[-1] != '': start.append('') else: diff --git a/contrib/test_mklog.py b/contrib/test_mklog.py index 7e95ec1a2ab..f5e9ecd577c 100755 --- a/contrib/test_mklog.py +++ b/contrib/test_mklog.py @@ -240,6 +240,9 @@ index 4ad78c1f77b..6687b368038 100644 ''' EXPECTED4 = '''\ + + PR 50209 + gcc/ChangeLog: * ipa-icf.c: @@ -317,9 +320,10 @@ index 00000000000..dcc8999c446 EXPECTED5 = '''\ PR target/95046 - Vectorize V2SFmode operations + PR target/95046 + gcc/testsuite/ChangeLog: - PR target/95046 * gcc.target/i386/pr95046-6.c: New test. ''' @@ -377,9 +381,11 @@ index 00000000000..f3d6d11e61e ''' EXPECTED7 = '''\ -gcc/testsuite/ChangeLog: DR 2237 + +gcc/testsuite/ChangeLog: + * g++.dg/DRs/dr2237.C: New test. '''