8000 gh-112301: Add Warning Count to Warning Check Tooling by nohlson · Pull Request #122711 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-112301: Add Warning Count to Warning Check Tooling #122711

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 50 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5148727
Create simple warning check tool and add to ubuntu build and test job
nohlson Jul 13, 2024
3bd5a10
Add flags to check warnings script to fail on regression or improvement
nohlson Jul 13, 2024
6813003
Remove redundant comment
nohlson Jul 13, 2024
ab4d754
Rename warnigore file to warningignore
nohlson Jul 13, 2024
615d228
Use regex to extract json arrays
nohlson Jul 13, 2024
fc0a60b
Trim whitespace
nohlson Jul 13, 2024
7793d80
Test on github unexpected improvement
nohlson Jul 13, 2024
99715d2
Add config for improve fail check
nohlson Jul 13, 2024
bc44ec2
Revert to prod check warning state
nohlson Jul 13, 2024
e2ca75f
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 13, 2024
bd1634e
Refactor creating set of files with warnings to a dedicated function
nohlson Jul 17, 2024
b07b1d6
Move cflags configure option to top level build configuration
nohlson Jul 23, 2024
e1954a5
Add json diagnostics to ubuntu configuration as first argument
nohlson Jul 23, 2024
5935143
Add newline to news
nohlson Jul 23, 2024
7f1a238
Create simple warning check tool and add to ubuntu build and test job
nohlson Jul 13, 2024
144136e
Add macos warning checks to GitHub actions
nohlson Jul 22, 2024
3dd40fd
Revert reusable-macos.yml for environment variables
nohlson Jul 22, 2024
1158f53
Update paths
nohlson Jul 22, 2024
cb51b4f
Test unexpected improvement
nohlson Jul 22, 2024
77e0f6e
Remove warning ignore
nohlson Jul 22, 2024
3e1d75f
Add json output option to macos configure job
nohlson Jul 22, 2024
b5cd58a
Add common dictionary format when parsing warnings
nohlson Jul 23, 2024
02f313e
Remove configure option for macos job
nohlson Jul 23, 2024
83d1ed7
Print out json version of compiler output
nohlson Jul 23, 2024
08a6f6d
Remove old version of warning ignore file
nohlson Jul 23, 2024
7be8ee6
Remove compiler output print diagnostic
nohlson Jul 24, 2024
8b0a2ee
📜🤖 Added by blurb_it.
blurb-it[bot] Jul 24, 2024
49cbd87
Remove superfluous comment
nohlson Jul 24, 2024
522f27c
oMerge branch 'main' into add-macos-warnings-tracking-tooling
nohlson Jul 30, 2024
b654a84
Add period to news
nohlson Jul 30, 2024
7780da6
Merge branch 'main' into add-macos-warnings-tracking-tooling
nohlson Jul 31, 2024
3688c5c
Make warning ignore file optional
nohlson Jul 31, 2024
cb1f276
Add write compiler output to log and file
nohlson Jul 31, 2024
fb91e3e
Fix formatting and update regex
nohlson Jul 31, 2024
f35ba60
Fix comment formatting
nohlson Aug 5, 2024
294dd61
Add warning count to check warnigns tooling
nohlson Aug 5, 2024
4056985
Remove duplicate warnings from check warning tooling
nohlson Aug 5, 2024
dad672b
Merge branch 'main' into add-warning-count-to-warning-ignore-files
nohlson Aug 5, 2024
4164b81
Trim trailing whitespace
nohlson Aug 6, 2024
8b07ae8
📜🤖 Added by blurb_it.
blurb-it[bot] Aug 6, 2024
17858b9
Reformat news
nohlson Aug 6, 2024
f483e04
Merge branch 'main' into add-warning-count-to-warning-ignore-files
nohlson Aug 6, 2024
55e20bd
Update helpers for function argument types
nohlson Aug 6, 2024
566e8cd
Format line length
nohlson Aug 6, 2024
f8ae75e
Use named tuple for warning filename and count
nohlson Aug 12, 2024
cbf069b
Use proper type
nohlson Aug 12, 2024
26b40d3
Update function signatures and make files with expected warnings list…
nohlson Aug 13, 2024
ca519a3
Update Tools/build/check_warnings.py
nohlson Aug 14, 2024
f370442
Update Tools/build/check_warnings.py
nohlson Aug 14, 2024
644c117
Add parsing of option from clang output
nohlson Aug 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add ability to ignore warnings per file with warning count in warning checking tooling.
Patch by Nate Ohlson.
2 changes: 2 additions & 0 deletions Tools/build/.warningignore_macos
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Files listed will be ignored by the compiler warning checker
# for the macOS/build and test job.
# Keep lines sorted lexicographically to help avoid merge conflicts.
# Format example:
# /path/to/file (number of warnings in file)
2 changes: 2 additions & 0 deletions Tools/build/.warningignore_ubuntu
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Files listed will be ignored by the compiler warning checker
# for the Ubuntu/build and test job.
# Keep lines sorted lexicographically to help avoid merge conflicts.
# Format example:
# /path/to/file (number of warnings in file)
54 changes: 40 additions & 14 deletions Tools/build/check_warnings.py
8000
Original file line number Diff line numberDiff line change
Expand Up @@ -9,6 +9,11 @@
import re
import sys
from pathlib import Path
from typing import NamedTuple

class FileWarnings(NamedTuple):
name: str
count: int


def extract_warnings_from_compiler_output_clang(
Expand All @@ -19,7 +24,8 @@ def extract_warnings_from_compiler_output_clang(
"""
# Regex to find warnings in the compiler output
clang_warning_regex = re.compile(
r"(?P<file>.*):(?P<line>\d+):(?P<column>\d+): warning: (?P<message>.*)"
r"(?P<file>.*):(?P<line>\d+):(?P<column>\d+): warning: "
r"(?P<message>.*) (?P<option>\[-[^\]]+\])$"
)
compiler_warnings = []
for line in compiler_output.splitlines():
Expand All @@ -30,6 +36,7 @@ def extract_warnings_from_compiler_output_clang(
"line": match.group("line"),
"column": match.group("column"),
"message": match.group("message"),
"option": match.group("option").lstrip("[").rstrip("]"),
}
)

Expand All @@ -49,9 +56,7 @@ def extract_warnings_from_compiler_output_json(
"""
# Regex to find json arrays at the top level of the file
# in the compiler output
json_arrays = re.findall(
r"\[(?:[^[\]]|\[[^\]]*\])*\]", compiler_output
)
json_arrays = re.findall(r"\[(?:[^[\]]|\[[^]]*])*]", compiler_output)
compiler_warnings = []
for array in json_arrays:
try:
Expand All @@ -74,6 +79,7 @@ def extract_warnings_from_compiler_output_json(
"line": location[key]["line"],
"column": location[key]["column"],
"message": warning["message"],
"option": warning["option"],
}
)
# Found a caret, start, or end in location so
Expand All @@ -92,18 +98,26 @@ def extract_warnings_from_compiler_output_json(
def get_warnings_by_file(warnings: list[dict]) -> dict[str, list[dict]]:
"""
Returns a dictionary where the key is the file and the data is the warnings
in that file
in that file. Does not include duplicate warnings for a file from list of
provided warnings.
"""
warnings_by_file = defaultdict(list)
warnings_added = set()
for warning in warnings:
warnings_by_file[warning["file"]].append(warning)
warning_key = (
f"{warning['file']}-{warning['line']}-"
f"{warning['column']}-{warning['option']}"
)
if warning_key not in warnings_added:
warnings_added.add(warning_key)
warnings_by_file[warning["file"]].append(warning)

return warnings_by_file


def get_unexpected_warnings(
files_with_expected_warnings: set[str],
files_with_warnings: dict[str, list[dict]],
files_with_expected_warnings: set[FileWarnings],
files_with_warnings: set[FileWarnings],
) -> int:
"""
Returns failure status if warnings discovered in list of warnings
Expand All @@ -112,7 +126,14 @@ def get_unexpected_warnings(
"""
unexpected_warnings = []
for file in files_with_warnings.keys():
if file not in files_with_expected_warnings:
found_file_in_ignore_list = False
for ignore_file in files_with_expected_warnings:
if file == ignore_file.name:
if len(files_with_warnings[file]) > ignore_file.count:
unexpected_warnings.extend(files_with_warnings[file])
found_file_in_ignore_list = True
break
if not found_file_in_ignore_list:
unexpected_warnings.extend(files_with_warnings[file])

if unexpected_warnings:
Expand All @@ -125,22 +146,24 @@ def get_unexpected_warnings(


def get_unexpected_improvements(
files_with_expected_warnings: set[str],
files_with_warnings: dict[str, list[dict]],
files_with_expected_warnings: set[FileWarnings],
files_with_warnings: set[FileWarnings],
) -> int:
"""
Returns failure status if there are no warnings in the list of warnings
for a file that is in the list of files with expected warnings
"""
unexpected_improvements = []
for file in files_with_expected_warnings:
if file not in files_with_warnings.keys():
if file.name not in files_with_warnings.keys():
unexpected_improvements.append(file)
elif len(files_with_warnings[file.name]) < file.count:
unexpected_improvements.append(file)

if unexpected_improvements:
print("Unexpected improvements:")
for file in unexpected_improvements:
print(file)
print(file.name)
return 1

return 0
Expand Down Expand Up @@ -214,8 +237,11 @@ def main(argv: list[str] | None = None) -> int:
with Path(args.warning_ignore_file_path).open(
encoding="UTF-8"
) as clean_files:
# Files with expected warnings are stored as a set of tuples
# where the first element is the file name and the second element
# is the number of warnings expected in that file
files_with_expected_warnings = {
file.strip()
FileWarnings(file.strip().split()[0], int(file.strip().split()[1]))
for file in clean_files
if file.strip() and not file.startswith("#")
}
Expand Down
Loading
0