|
44 | 44 | logger = logging.getLogger(__name__)
|
45 | 45 |
|
46 | 46 |
|
| 47 | +EXPLANATION = textwrap.dedent(''' |
| 48 | + ------------------------- |
| 49 | +
|
| 50 | + Non-constant global variables are generally not supported |
| 51 | + in the CPython repo. We use a tool to analyze the C code |
| 52 | + and report if any unsupported globals are found. The tool |
| 53 | + may be run manually with: |
| 54 | +
|
| 55 | + ./python Tools/c-analyzer/check-c-globals.py --format summary [FILE] |
| 56 | +
|
| 57 | + Occasionally the tool is unable to parse updated code. |
| 58 | + If this happens then add the file to the "EXCLUDED" list |
| 59 | + in Tools/c-analyzer/cpython/_parser.py and create a new |
| 60 | + issue for fixing the tool (and CC ericsnowcurrently |
| 61 | + on the issue). |
| 62 | +
|
| 63 | + If the tool reports an unsupported global variable and |
| 64 | + it is actually const (and thus supported) then first try |
| 65 | + fixing the declaration appropriately in the code. If that |
| 66 | + doesn't work then add the variable to the "should be const" |
| 67 | + section of Tools/c-analyzer/cpython/_parser.py. |
| 68 | +
|
| 69 | + If the tool otherwise reports an unsupported global variable |
| 70 | + then first try to make it non-global, possibly adding to |
| 71 | + PyInterpreterState (for core code) or module state (for |
| 72 | + extension modules). In an emergency, you can add the |
| 73 | + variable to Tools/c-analyzer/cpython/globals-to-fix.tsv |
| 74 | + to get CI passing, but doing so should be avoided. If |
| 75 | + this course it taken, be sure to create an issue for |
| 76 | + eliminating the global (and CC ericsnowcurrently). |
| 77 | +''') |
| 78 | + |
| 79 | + |
47 | 80 | #######################################
|
48 | 81 | # table helpers
|
49 | 82 |
|
@@ -324,71 +357,45 @@ def cmd_check(filenames, *,
|
324 | 357 | if track_progress:
|
325 | 358 | filenames = track_progress(filenames)
|
326 | 359 |
|
327 |
| - logger.info('analyzing files...') |
328 |
| - analyzed = _analyze(filenames, **kwargs) |
329 |
| - analyzed.fix_filenames(relroot, normalize=False) |
330 |
| - decls = filter_forward(analyzed, markpublic=True) |
331 |
| - |
332 |
| - logger.info('checking analysis results...') |
333 |
| - failed = [] |
334 |
| - for data, failure in _check_all(decls, checks, failfast=failfast): |
335 |
| - if data is None: |
336 |
| - printer.info('stopping after one failure') |
337 |
| - break |
338 |
| - if div is not None and len(failed) > 0: |
339 |
| - printer.info(div) |
340 |
| - failed.append(data) |
341 |
| - handle_failure(failure, data) |
342 |
| - handle_after() |
343 |
| - |
344 |
| - printer.info('-------------------------') |
345 |
| - logger.info(f'total failures: {len(failed)}') |
346 |
| - logger.info('done checking') |
347 |
| - |
348 |
| - if fmt == 'summary': |
349 |
| - print('Categorized by storage:') |
350 |
| - print() |
351 |
| - from .match import group_by_storage |
352 |
| - grouped = group_by_storage(failed, ignore_non_match=False) |
353 |
| - for group, decls in grouped.items(): |
| 360 | + try: |
| 361 | + logger.info('analyzing files...') |
| 362 | + analyzed = _analyze(filenames, **kwargs) |
| 363 | + analyzed.fix_filenames(relroot, normalize=False) |
| 364 | + decls = filter_forward(analyzed, markpublic=True) |
| 365 | + |
| 366 | + logger.info('checking analysis results...') |
| 367 | + failed = [] |
| 368 | + for data, failure in _check_all(decls, checks, failfast=failfast): |
| 369 | + if data is None: |
| 370 | + printer.info('stopping after one failure') |
| 371 | + break |
| 372 | + if div is not None and len(failed) > 0: |
| 373 | + printer.info(div) |
| 374 | + failed.append(data) |
| 375 | + handle_failure(failure, data) |
| 376 | + handle_after() |
| 377 | + |
| 378 | + printer.info('-------------------------') |
| 379 | + logger.info(f'total failures: {len(failed)}') |
| 380 | + logger.info('done checking') |
| 381 | + |
| 382 | + if fmt == 'summary': |
| 383 | + print('Categorized by storage:') |
354 | 384 | print()
|
355 |
| - print(group) |
356 |
| - for decl in decls: |
357 |
| - print(' ', _fmt_one_summary(decl)) |
358 |
| - print(f'subtotal: {len(decls)}') |
| 385 | + from .match import group_by_storage |
| 386 | + grouped = group_by_storage(failed, ignore_non_match=False) |
| 387 | + for group, decls in grouped.items(): |
| 388 | + print() |
| 389 | + print(group) |
| 390 | + for decl in decls: |
| 391 | + print(' ', _fmt_one_summary(decl)) |
| 392 | + print(f'subtotal: {len(decls)}') |
| 393 | + except Exception: |
| 394 | + print(EXPLANATION) |
| 395 | + raise # re-raise |
359 | 396 |
|
360 | 397 | if len(failed) > 0:
|
361 |
| - print(textwrap.dedent(''' |
362 |
| - ------------------------- |
363 |
| -
|
364 |
| - Non-constant global variables are generally not supported |
365 |
| - in the CPython repo. We use a tool to analyze the C code |
366 |
| - and report if any unsupported globals are found. The tool |
367 |
| - may be run manually with: |
368 |
| -
|
369 |
| - ./python Tools/c-analyzer/check-c-globals.py --format summary [FILE] |
370 |
| -
|
371 |
| - Occasionally the tool is unable to parse updated code. |
372 |
| - If this happens then add the file to the "EXCLUDED" list |
373 |
| - in Tools/c-analyzer/cpython/_parser.py and create a new |
374 |
| - issue for fixing the tool (and CC ericsnowcurrently |
375 |
| - on the issue). |
376 |
| -
|
377 |
| - If the tool reports an unsupported global variable and |
378 |
| - it is actually const (and thus supported) then first try |
379 |
| - fixing the declaration appropriately in the code. If that |
380 |
| - doesn't work then add the variable to the "should be const" |
381 |
| - section of Tools/c-analyzer/cpython/_parser.py. |
382 |
| -
|
383 |
| - If the tool otherwise reports an unsupported global variable |
384 |
| - then first try to make it non-global, possibly adding to |
385 |
| - PyInterpreterState (for core code) or module state (for |
386 |
| - extension modules). In an emergency, you can add the |
387 |
| - variable to Tools/c-analyzer/cpython/globals-to-fix.tsv |
388 |
| - to get CI passing, but doing so should be avoided. If |
389 |
| - this course it taken, be sure to create an issue for |
390 |
| - eliminating the global (and CC ericsnowcurrently). |
391 |
| - ''')) |
| 398 | + print(EXPLANATION) |
392 | 399 | sys.exit(len(failed))
|
393 | 400 |
|
394 | 401 |
|
|
0 commit comments