xref: /llvm-project/clang/www/make_cxx_dr_status (revision cf23549edd0ac971600ceea1bb7f1454566b00a3)
1#! /usr/bin/env python3
2import sys, os, re, urllib.request
3
4latest_release = 19
5
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:
13  def __init__(self, section, issue, url, status, title):
14    self.section, self.issue, self.url, self.status, self.title = \
15        section, issue, url, status, title
16  def __repr__(self):
17    return '%s (%s): %s' % (self.issue, self.status, self.title)
18
19def parse(dr):
20  try:
21    section, issue_link, status, liaison, title = [
22        col.split('>', 1)[1].split('</TD>')[0]
23        for col in dr.split('</TR>', 1)[0].split('<TD')[1:]
24    ]
25  except Exception as ex:
26    print(f"Parse error: {ex}\n{dr}", file=sys.stderr)
27    sys.exit(1)
28  _, url, issue = issue_link.split('"', 2)
29  url = url.strip()
30  issue = int(issue.split('>', 1)[1].split('<', 1)[0])
31  title = title.replace('<issue_title>', '').replace('</issue_title>', '').replace('\r\n', '\n').strip()
32  return DR(section, issue, url, status, title)
33
34def collect_tests():
35  status_re = re.compile(r'\bcwg([0-9]+): (.*)')
36  status_map = {}
37  for test_cpp in os.listdir(dr_test_dir):
38    if not test_cpp.endswith('.cpp'):
39      continue
40    test_cpp = os.path.join(dr_test_dir, test_cpp)
41    found_any = False;
42    for match in re.finditer(status_re, open(test_cpp, 'r').read()):
43      dr_number = int(match.group(1))
44      if dr_number in status_map:
45        print("error: Comment for cwg{} encountered more than once. Duplicate found in {}".format(dr_number, test_cpp))
46        sys.exit(1)
47      status_map[dr_number] = match.group(2)
48      found_any = True
49    if not found_any:
50      print("warning:%s: no '// cwg123: foo' comments in this file" % test_cpp, file=sys.stderr)
51  return status_map
52
53def get_issues(path):
54  buffer = None
55  if not path and os.path.exists(default_issue_list_path):
56    path = default_issue_list_path
57  try:
58    if path is None:
59      print('Fetching issue list from {}'.format(issue_list_url))
60      with urllib.request.urlopen(issue_list_url) as f:
61        buffer = f.read().decode('utf-8')
62    else:
63      print('Opening issue list from file {}'.format(path))
64      with open(path, 'r') as f:
65        buffer = f.read()
66  except Exception as ex:
67     print('Unable to read the core issue list', file=sys.stderr)
68     print(ex, file=sys.stderr)
69     sys.exit(1)
70
71  return sorted((parse(dr) for dr in buffer.split('<TR>')[2:]),
72                key = lambda dr: dr.issue)
73
74
75issue_list_path  = None
76if len(sys.argv) == 1:
77  pass
78elif len(sys.argv) == 2:
79  issue_list_path = sys.argv[1]
80else:
81  print('Usage: {} [<path to cwg_index.html>]'.format(sys.argv[0]), file=sys.stderr)
82  sys.exit(1)
83
84status_map = collect_tests()
85drs = get_issues(issue_list_path)
86out_html = []
87out_html.append('''\
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) }
112    tr:target { background-color: #FFFFBB }
113    th { 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):
139  pass
140
141availability_error_occurred = False
142
143def availability(issue):
144  status = status_map.get(issue, 'unknown')
145  unresolved_status = ''
146  proposed_resolution = ''
147  unresolved_status_match = re.search(r' (open|drafting|review|tentatively ready|ready)', status)
148  if unresolved_status_match:
149    unresolved_status = unresolved_status_match.group(1)
150    proposed_resolution_match = re.search(r' (open|drafting|review|tentatively ready|ready) (\d{4}-\d{2}(?:-\d{2})?|P\d{4}R\d+)$', status)
151    if proposed_resolution_match is None:
152      raise AvailabilityError('error: issue {}: \'{}\' status should be followed by a paper number (P1234R5) or proposed resolution in YYYY-MM-DD format'.format(dr.issue, unresolved_status))
153    proposed_resolution = proposed_resolution_match.group(2)
154    status = status[:-1-len(proposed_resolution)]
155    status = status[:-1-len(unresolved_status)]
156
157  avail_suffix = ''
158  avail_style = ''
159  details = ''
160  if status.endswith(' c++11'):
161    status = status[:-6]
162    avail_suffix = ' (C++11 onwards)'
163  elif status.endswith(' c++14'):
164    status = status[:-6]
165    avail_suffix = ' (C++14 onwards)'
166  elif status.endswith(' c++17'):
167    status = status[:-6]
168    avail_suffix = ' (C++17 onwards)'
169  elif status.endswith(' c++20'):
170    status = status[:-6]
171    avail_suffix = ' (C++20 onwards)'
172  elif status.endswith(' c++23'):
173    status = status[:-6]
174    avail_suffix = ' (C++23 onwards)'
175  elif status.endswith(' c++26'):
176    status = status[:-6]
177    avail_suffix = ' (C++26 onwards)'
178  if status == 'unknown':
179    avail = 'Unknown'
180    avail_style = 'unknown'
181  elif re.match(r'^[0-9]+\.?[0-9]*', status):
182    if not proposed_resolution:
183      avail = 'Clang %s' % status
184      if float(status) > latest_release:
185        avail_style = 'unreleased'
186      else:
187        avail_style = 'full'
188    else:
189      avail = 'Not resolved'
190      details = f'Clang {status} implements {proposed_resolution} resolution'
191  elif status == 'yes':
192    if not proposed_resolution:
193      avail = 'Yes'
194      avail_style = 'full'
195    else:
196      avail = 'Not resolved'
197      details = f'Clang implements {proposed_resolution} resolution'
198  elif status == 'partial':
199    if not proposed_resolution:
200      avail = 'Partial'
201      avail_style = 'partial'
202    else:
203      avail = 'Not resolved'
204      details = f'Clang partially implements {proposed_resolution} resolution'
205  elif status == 'no':
206    if not proposed_resolution:
207      avail = 'No'
208      avail_style = 'none'
209    else:
210      avail = 'Not resolved'
211      details = f'Clang does not implement {proposed_resolution} resolution'
212  elif status == 'na':
213    avail = 'N/A'
214    avail_style = 'na'
215  elif status == 'na lib':
216    avail = 'N/A (Library DR)'
217    avail_style = 'na'
218  elif status == 'na abi':
219    avail = 'N/A (ABI constraint)'
220    avail_style = 'na'
221  elif status.startswith('sup '):
222    dup = status.split(' ', 1)[1]
223    if dup.startswith('P'):
224      avail = 'Superseded by <a href="https://wg21.link/%s">%s</a>' % (dup, dup)
225      avail_style = 'na'
226    else:
227      avail = 'Superseded by <a href="#%s">%s</a>' % (dup, dup)
228      try:
229        _, avail_style, _, _ = availability(int(dup))
230        avail_style += '-superseded'
231      except:
232        print("issue %s marked as sup %s" % (issue, dup), file=sys.stderr)
233        avail_style = 'none'
234  elif status.startswith('dup '):
235    dup = int(status.split(' ', 1)[1])
236    avail = 'Duplicate of <a href="#%s">%s</a>' % (dup, dup)
237    _, avail_style, _, _ = availability(dup)
238  else:
239    raise AvailabilityError('error: unknown status %s for issue %s' % (status, dr.issue))
240  return (avail + avail_suffix, avail_style, unresolved_status, details)
241
242count = {}
243for dr in drs:
244  if dr.status in ('concepts',):
245    # This refers to the old ("C++0x") concepts feature, which was not part
246    # of any C++ International Standard or Technical Specification.
247    continue
248
249  elif dr.status == 'extension':
250    row_style = ' class="open"'
251    avail = 'Extension'
252    avail_style = ''
253
254  elif dr.status in ('open', 'drafting', 'review', 'tentatively ready', 'ready'):
255    row_style = ' class="open"'
256    try:
257      avail, avail_style, unresolved_status, details = availability(dr.issue)
258    except AvailabilityError as e:
259      availability_error_occurred = True
260      print(e.args[0])
261      continue
262
263    if avail == 'Unknown':
264      avail = 'Not resolved'
265      avail_style = ''
266    else:
267      if unresolved_status != dr.status:
268        availability_error_occurred = True
269        print("error: issue %s is marked '%s', which differs from CWG index status '%s'" \
270             % (dr.issue, unresolved_status, dr.status))
271        continue
272  else:
273    row_style = ''
274    try:
275      avail, avail_style, unresolved_status, details = availability(dr.issue)
276    except AvailabilityError as e:
277      availability_error_occurred = True
278      print(e.args[0])
279      continue
280
281    if unresolved_status:
282      availability_error_occurred = True
283      print("error: issue %s is marked '%s', even though it is resolved in CWG index" \
284           % (dr.issue, unresolved_status))
285      continue
286
287  if not avail.startswith('Sup') and not avail.startswith('Dup'):
288    count[avail] = count.get(avail, 0) + 1
289
290  if avail_style != '':
291    avail_style = ' class="{}"'.format(avail_style)
292
293  if details != '':
294    avail = f'''
295      <details>
296        <summary>{avail}</summary>
297        {details}
298      </details>'''
299  out_html.append(f'''
300  <tr{row_style} id="{dr.issue}">
301    <td><a href="https://cplusplus.github.io/CWG/issues/{dr.issue}.html">{dr.issue}</a></td>
302    <td>{dr.status}</td>
303    <td>{dr.title}</td>
304    <td{avail_style} align="center">{avail}</td>
305  </tr>''')
306
307if availability_error_occurred:
308  exit(1)
309
310for status, num in sorted(count.items()):
311  print("%s: %s" % (status, num), file=sys.stderr)
312
313out_html.append('''\
314</table>
315
316</div>
317</body>
318</html>
319''')
320
321out_file = open(output, 'w')
322out_file.write(''.join(out_html))
323out_file.close()
324