llvm-project
308 строк · 10.3 Кб
1#! /usr/bin/env python3
2import sys, os, re, urllib.request3
4latest_release = 185
6clang_www_dir = os.path.dirname(__file__)7default_issue_list_path = os.path.join(clang_www_dir, 'cwg_index.html')8issue_list_url = "https://raw.githubusercontent.com/cplusplus/CWG/gh-pages/issues/cwg_index.html"9output = os.path.join(clang_www_dir, 'cxx_dr_status.html')10dr_test_dir = os.path.join(clang_www_dir, '../test/CXX/drs')11
12class DR:13def __init__(self, section, issue, url, status, title):14self.section, self.issue, self.url, self.status, self.title = \15section, issue, url, status, title16def __repr__(self):17return '%s (%s): %s' % (self.issue, self.status, self.title)18
19def parse(dr):20try:21section, issue_link, status, liaison, title = [22col.split('>', 1)[1].split('</TD>')[0]23for col in dr.split('</TR>', 1)[0].split('<TD')[1:]24]25except Exception as ex:26print(f"Parse error: {ex}\n{dr}", file=sys.stderr)27sys.exit(1)28_, url, issue = issue_link.split('"', 2)29url = url.strip()30issue = int(issue.split('>', 1)[1].split('<', 1)[0])31title = title.replace('<issue_title>', '').replace('</issue_title>', '').replace('\r\n', '\n').strip()32return DR(section, issue, url, status, title)33
34def collect_tests():35status_re = re.compile(r'\bcwg([0-9]+): (.*)')36status_map = {}37for test_cpp in os.listdir(dr_test_dir):38if not test_cpp.endswith('.cpp'):39continue40test_cpp = os.path.join(dr_test_dir, test_cpp)41found_any = False;42for match in re.finditer(status_re, open(test_cpp, 'r').read()):43dr_number = int(match.group(1))44if dr_number in status_map:45print("error: Comment for cwg{} encountered more than once. Duplicate found in {}".format(dr_number, test_cpp))46sys.exit(1)47status_map[dr_number] = match.group(2)48found_any = True49if not found_any:50print("warning:%s: no '// cwg123: foo' comments in this file" % test_cpp, file=sys.stderr)51return status_map52
53def get_issues(path):54buffer = None55if not path and os.path.exists(default_issue_list_path):56path = default_issue_list_path57try:58if path is None:59print('Fetching issue list from {}'.format(issue_list_url))60with urllib.request.urlopen(issue_list_url) as f:61buffer = f.read().decode('utf-8')62else:63print('Opening issue list from file {}'.format(path))64with open(path, 'r') as f:65buffer = f.read()66except Exception as ex:67print('Unable to read the core issue list', file=sys.stderr)68print(ex, file=sys.stderr)69sys.exit(1)70
71return sorted((parse(dr) for dr in buffer.split('<TR>')[2:]),72key = lambda dr: dr.issue)73
74
75issue_list_path = None76if len(sys.argv) == 1:77pass78elif len(sys.argv) == 2:79issue_list_path = sys.argv[1]80else:81print('Usage: {} [<path to cwg_index.html>]'.format(sys.argv[0]), file=sys.stderr)82sys.exit(1)83
84status_map = collect_tests()85drs = get_issues(issue_list_path)86out_file = open(output, 'w')87out_file.write('''\88<!DOCTYPE html>
89<!-- This file is auto-generated by make_cxx_dr_status. Do not modify. -->
90<html>
91<head>
92<META http-equiv="Content-Type" content="text/html; charset=utf-8">
93<title>Clang - C++ Defect Report Status</title>
94<link type="text/css" rel="stylesheet" href="menu.css">
95<link type="text/css" rel="stylesheet" href="content.css">
96<style type="text/css">
97.none { background-color: #FFCCCC }
98.none-superseded { background-color: rgba(255, 204, 204, 0.65) }
99.unknown { background-color: #EBCAFE }
100.unknown-superseded { background-color: rgba(234, 200, 254, 0.65) }
101.partial { background-color: #FFE0B0 }
102.partial-superseded { background-color: rgba(255, 224, 179, 0.65) }
103.unreleased { background-color: #FFFF99 }
104.unreleased-superseded { background-color: rgba(255, 255, 153, 0.65) }
105.full { background-color: #CCFF99 }
106.full-superseded { background-color: rgba(214, 255, 173, 0.65) }
107.na { background-color: #DDDDDD }
108.na-superseded { background-color: rgba(222, 222, 222, 0.65) }
109.open * { color: #AAAAAA }
110.open-superseded * { color: rgba(171, 171, 171, 0.65) }
111//.open { filter: opacity(0.2) }
112tr:target { background-color: #FFFFBB }
113th { background-color: #FFDDAA }
114</style>
115</head>
116<body>
117
118<!--#include virtual="menu.html.incl"-->
119
120<div id="content">
121
122<!--*************************************************************************-->
123<h1>C++ Defect Report Support in Clang</h1>
124<!--*************************************************************************-->
125
126<h2 id="cxxdr">C++ defect report implementation status</h2>
127
128<p>This page tracks which C++ defect reports are implemented within Clang.</p>
129
130<table width="689" border="1" cellspacing="0">
131<tr>
132<th>Number</th>
133<th>Status</th>
134<th>Issue title</th>
135<th>Available in Clang?</th>
136</tr>''')137
138class AvailabilityError(RuntimeError):139pass140
141availability_error_occurred = False142
143def availability(issue):144status = status_map.get(issue, 'unknown')145
146unresolved_status = ''147proposed_resolution = ''148unresolved_status_match = re.search(r' (open|drafting|review|tentatively ready)', status)149if unresolved_status_match:150unresolved_status = unresolved_status_match.group(1)151proposed_resolution_match = re.search(r' (open|drafting|review|tentatively ready) (\d{4}-\d{2}(?:-\d{2})?|P\d{4}R\d+)$', status)152if proposed_resolution_match is None:153raise AvailabilityError('Issue {}: \'{}\' status should be followed by a paper number (P1234R5) or proposed resolution in YYYY-MM-DD format'.format(dr.issue, unresolved_status))154proposed_resolution = proposed_resolution_match.group(2)155status = status[:-1-len(proposed_resolution)]156status = status[:-1-len(unresolved_status)]157
158avail_suffix = ''159avail_style = ''160tooltip = ''161if status.endswith(' c++11'):162status = status[:-6]163avail_suffix = ' (C++11 onwards)'164elif status.endswith(' c++14'):165status = status[:-6]166avail_suffix = ' (C++14 onwards)'167elif status.endswith(' c++17'):168status = status[:-6]169avail_suffix = ' (C++17 onwards)'170elif status.endswith(' c++20'):171status = status[:-6]172avail_suffix = ' (C++20 onwards)'173if status == 'unknown':174avail = 'Unknown'175avail_style = 'unknown'176elif re.match(r'^[0-9]+\.?[0-9]*', status):177if not proposed_resolution:178avail = 'Clang %s' % status179if float(status) > latest_release:180avail_style = 'unreleased'181else:182avail_style = 'full'183else:184avail = 'Not Resolved*'185tooltip = f' title="Clang {status} implements {proposed_resolution} resolution"'186elif status == 'yes':187if not proposed_resolution:188avail = 'Yes'189avail_style = 'full'190else:191avail = 'Not Resolved*'192tooltip = f' title="Clang implements {proposed_resolution} resolution"'193elif status == 'partial':194if not proposed_resolution:195avail = 'Partial'196avail_style = 'partial'197else:198avail = 'Not Resolved*'199tooltip = f' title="Clang partially implements {proposed_resolution} resolution"'200elif status == 'no':201if not proposed_resolution:202avail = 'No'203avail_style = 'none'204else:205avail = 'Not Resolved*'206tooltip = f' title="Clang does not implement {proposed_resolution} resolution"'207elif status == 'na':208avail = 'N/A'209avail_style = 'na'210elif status == 'na lib':211avail = 'N/A (Library DR)'212avail_style = 'na'213elif status == 'na abi':214avail = 'N/A (ABI constraint)'215avail_style = 'na'216elif status.startswith('sup '):217dup = status.split(' ', 1)[1]218if dup.startswith('P'):219avail = 'Superseded by <a href="https://wg21.link/%s">%s</a>' % (dup, dup)220avail_style = 'na'221else:222avail = 'Superseded by <a href="#%s">%s</a>' % (dup, dup)223try:224_, avail_style, _, _ = availability(int(dup))225avail_style += '-superseded'226except:227print("issue %s marked as sup %s" % (issue, dup), file=sys.stderr)228avail_style = 'none'229elif status.startswith('dup '):230dup = int(status.split(' ', 1)[1])231avail = 'Duplicate of <a href="#%s">%s</a>' % (dup, dup)232_, avail_style, _, _ = availability(dup)233else:234raise AvailabilityError('Unknown status %s for issue %s' % (status, dr.issue))235return (avail + avail_suffix, avail_style, unresolved_status, tooltip)236
237count = {}238for dr in drs:239if dr.status in ('concepts',):240# This refers to the old ("C++0x") concepts feature, which was not part241# of any C++ International Standard or Technical Specification.242continue243
244elif dr.status == 'extension':245row_style = ' class="open"'246avail = 'Extension'247avail_style = ''248
249elif dr.status in ('open', 'drafting', 'review', 'tentatively ready'):250row_style = ' class="open"'251try:252avail, avail_style, unresolved_status, tooltip = availability(dr.issue)253except AvailabilityError as e:254availability_error_occurred = True255print(e.args[0])256continue257
258if avail == 'Unknown':259avail = 'Not resolved'260avail_style = ''261else:262if unresolved_status != dr.status:263availability_error_occurred = True264print("Issue %s is marked '%s', which differs from CWG index status '%s'" \265% (dr.issue, unresolved_status, dr.status))266continue267else:268row_style = ''269try:270avail, avail_style, unresolved_status, tooltip = availability(dr.issue)271except AvailabilityError as e:272availability_error_occurred = True273print(e.args[0])274continue275
276if unresolved_status:277availability_error_occurred = True278print("Issue %s is marked '%s', even though it is resolved in CWG index" \279% (dr.issue, unresolved_status))280continue281
282if not avail.startswith('Sup') and not avail.startswith('Dup'):283count[avail] = count.get(avail, 0) + 1284
285if avail_style != '':286avail_style = ' class="{}"'.format(avail_style)287out_file.write('''288<tr%s id="%s">
289<td><a href="https://cplusplus.github.io/CWG/issues/%s.html">%s</a></td>
290<td>%s</td>
291<td>%s</td>
292<td%s%s align="center">%s</td>
293</tr>''' % (row_style, dr.issue, dr.issue, dr.issue, dr.status, dr.title, avail_style, tooltip, avail))294
295if availability_error_occurred:296exit(1)297
298for status, num in sorted(count.items()):299print("%s: %s" % (status, num), file=sys.stderr)300
301out_file.write('''\302</table>
303
304</div>
305</body>
306</html>
307''')308out_file.close()309
310