|
4 | 4 | import os.path
|
5 | 5 | import re
|
6 | 6 | import sys
|
7 |
| -import textwrap |
8 | 7 |
|
9 | 8 | from c_common import fsutil
|
10 | 9 | from c_common.logging import VERBOSITY, Printer
|
|
44 | 43 | logger = logging.getLogger(__name__)
|
45 | 44 |
|
46 | 45 |
|
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/ignored.tsv. |
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 |
| - |
80 | 46 | #######################################
|
81 | 47 | # table helpers
|
82 | 48 |
|
@@ -357,45 +323,40 @@ def cmd_check(filenames, *,
|
357 | 323 | if track_progress:
|
358 | 324 | filenames = track_progress(filenames)
|
359 | 325 |
|
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:') |
| 326 | + logger.info('analyzing files...') |
| 327 | + analyzed = _analyze(filenames, **kwargs) |
| 328 | + analyzed.fix_filenames(relroot, normalize=False) |
| 329 | + decls = filter_forward(analyzed, markpublic=True) |
| 330 | + |
| 331 | + logger.info('checking analysis results...') |
| 332 | + failed = [] |
| 333 | + for data, failure in _check_all(decls, checks, failfast=failfast): |
| 334 | + if data is None: |
| 335 | + printer.info('stopping after one failure') |
| 336 | + break |
| 337 | + if div is not None and len(failed) > 0: |
| 338 | + printer.info(div) |
| 339 | + failed.append(data) |
| 340 | + handle_failure(failure, data) |
| 341 | + handle_after() |
| 342 | + |
| 343 | + printer.info('-------------------------') |
| 344 | + logger.info(f'total failures: {len(failed)}') |
| 345 | + logger.info('done checking') |
| 346 | + |
| 347 | + if fmt == 'summary': |
| 348 | + print('Categorized by storage:') |
| 349 | + print() |
| 350 | + from .match import group_by_storage |
| 351 | + grouped = group_by_storage(failed, ignore_non_match=False) |
| 352 | + for group, decls in grouped.items(): |
384 | 353 | print()
|
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 |
| 354 | + print(group) |
| 355 | + for decl in decls: |
| 356 | + print(' ', _fmt_one_summary(decl)) |
| 357 | + print(f'subtotal: {len(decls)}') |
396 | 358 |
|
397 | 359 | if len(failed) > 0:
|
398 |
| - print(EXPLANATION) |
399 | 360 | sys.exit(len(failed))
|
400 | 361 |
|
401 | 362 |
|
|
0 commit comments