patchwise 0.2.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- patchwise/__init__.py +18 -0
- patchwise/logger_setup.py +81 -0
- patchwise/main.py +101 -0
- patchwise/patch_review/__init__.py +171 -0
- patchwise/patch_review/ai_review/__init__.py +2 -0
- patchwise/patch_review/ai_review/ai_code_review.py +965 -0
- patchwise/patch_review/ai_review/ai_review.py +204 -0
- patchwise/patch_review/ai_review/llm_commit_audit.py +60 -0
- patchwise/patch_review/decorators.py +50 -0
- patchwise/patch_review/kernel_tree.py +122 -0
- patchwise/patch_review/patch_review.py +317 -0
- patchwise/patch_review/static_analysis/__init__.py +2 -0
- patchwise/patch_review/static_analysis/checkpatch.py +48 -0
- patchwise/patch_review/static_analysis/coccicheck.py +81 -0
- patchwise/patch_review/static_analysis/dt_check.py +130 -0
- patchwise/patch_review/static_analysis/dtbs_check.py +85 -0
- patchwise/patch_review/static_analysis/sparse.py +150 -0
- patchwise/patch_review/static_analysis/static_analysis.py +48 -0
- patchwise-0.2.0.dist-info/METADATA +19 -0
- patchwise-0.2.0.dist-info/RECORD +24 -0
- patchwise-0.2.0.dist-info/WHEEL +5 -0
- patchwise-0.2.0.dist-info/entry_points.txt +2 -0
- patchwise-0.2.0.dist-info/licenses/LICENSE.txt +26 -0
- patchwise-0.2.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
|
|
2
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
import re
|
|
6
|
+
import subprocess
|
|
7
|
+
import tempfile
|
|
8
|
+
from git import GitCommandError
|
|
9
|
+
|
|
10
|
+
from .static_analysis import StaticAnalysis
|
|
11
|
+
from ...patch_review.decorators import (
|
|
12
|
+
register_static_analysis_review,
|
|
13
|
+
register_long_review,
|
|
14
|
+
)
|
|
15
|
+
from ... import SANDBOX_PATH
|
|
16
|
+
from ..patch_review import Dependency
|
|
17
|
+
|
|
18
|
+
MINIMUM_CLANG_VERSION = 14
|
|
19
|
+
MINIMUM_SPARSE_VERSION = "0.6.4"
|
|
20
|
+
|
|
21
|
+
class SparseDependency(Dependency):
|
|
22
|
+
|
|
23
|
+
# TODO if installing to SANDBOX_PATH and the version still does not work, the user will need to manually clear the SANDBOX_PATH folder because SANDBOX_PATH is at the start of the PATH
|
|
24
|
+
def install_from_source(self) -> None:
|
|
25
|
+
"""
|
|
26
|
+
Install sparse from source.
|
|
27
|
+
"""
|
|
28
|
+
self.logger.info(f"Installing {self.name} from source...")
|
|
29
|
+
with tempfile.TemporaryDirectory() as tmpdir:
|
|
30
|
+
src_dir = os.path.join(tmpdir, "sparse")
|
|
31
|
+
subprocess.run(["git", "clone", "git://git.kernel.org/pub/scm/devel/sparse/sparse.git", src_dir], check=True)
|
|
32
|
+
subprocess.run(["make"], cwd=src_dir, check=True)
|
|
33
|
+
subprocess.run(["sudo", "make", f"PREFIX={SANDBOX_PATH}", "install"], cwd=src_dir, check=True)
|
|
34
|
+
|
|
35
|
+
def _do_install(self) -> None:
|
|
36
|
+
super().install_from_pkg_manager()
|
|
37
|
+
# Check if the correct version of sparse is installed
|
|
38
|
+
try:
|
|
39
|
+
super().check()
|
|
40
|
+
except ImportError as e:
|
|
41
|
+
self.logger.warning(f"{e}")
|
|
42
|
+
self.install_from_source()
|
|
43
|
+
|
|
44
|
+
@register_static_analysis_review
|
|
45
|
+
@register_long_review
|
|
46
|
+
class Sparse(StaticAnalysis):
|
|
47
|
+
"""
|
|
48
|
+
Performs static analysis on kernel commits using the sparse tool.
|
|
49
|
+
|
|
50
|
+
Methods:
|
|
51
|
+
run():
|
|
52
|
+
Runs sparse and returns the results corresponding to the patch sha.
|
|
53
|
+
"""
|
|
54
|
+
|
|
55
|
+
DEPENDENCIES = [
|
|
56
|
+
Dependency(
|
|
57
|
+
name="llvm-config",
|
|
58
|
+
min_version=MINIMUM_CLANG_VERSION,
|
|
59
|
+
),
|
|
60
|
+
Dependency(
|
|
61
|
+
name="clang",
|
|
62
|
+
min_version=MINIMUM_CLANG_VERSION,
|
|
63
|
+
),
|
|
64
|
+
Dependency(
|
|
65
|
+
name="ld.lld",
|
|
66
|
+
min_version=MINIMUM_CLANG_VERSION,
|
|
67
|
+
),
|
|
68
|
+
# Dependency(
|
|
69
|
+
# name="lld",
|
|
70
|
+
# ),
|
|
71
|
+
SparseDependency(
|
|
72
|
+
name="sparse",
|
|
73
|
+
min_version=MINIMUM_SPARSE_VERSION,
|
|
74
|
+
),
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
def setup(self) -> None:
|
|
78
|
+
pass
|
|
79
|
+
|
|
80
|
+
def run(self) -> str:
|
|
81
|
+
logger = self.logger
|
|
82
|
+
kernel_tree = str(self.repo.working_tree_dir)
|
|
83
|
+
|
|
84
|
+
logger.debug("Sparse.run() called")
|
|
85
|
+
|
|
86
|
+
logger.debug("Running defconfig")
|
|
87
|
+
super().make_config(arch="arm64") # TODO change back to _make_allmodconfig
|
|
88
|
+
|
|
89
|
+
sparse_log_pattern = re.compile(
|
|
90
|
+
r"(?P<filepath>.+):(?P<linenum>\d+):(?P<column>\d+): (?P<message>.+)"
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
# TODO use modified_files = set(self.commit.stats.files.keys())
|
|
94
|
+
diff = self.repo.git.diff(
|
|
95
|
+
"--name-only", f"{self.base_commit}..{self.commit}"
|
|
96
|
+
).splitlines()
|
|
97
|
+
files_changed = [os.path.join(kernel_tree, f.strip()) for f in diff]
|
|
98
|
+
for f in files_changed:
|
|
99
|
+
logger.debug(f"Touching {f}")
|
|
100
|
+
subprocess.run(["touch", f], check=True)
|
|
101
|
+
|
|
102
|
+
logger.debug("Running sparse check")
|
|
103
|
+
sparse_warnings = super().run_cmd_with_timer(
|
|
104
|
+
[
|
|
105
|
+
"make",
|
|
106
|
+
f"O={self.build_dir}",
|
|
107
|
+
f"-j{os.cpu_count()}",
|
|
108
|
+
"ARCH=arm64",
|
|
109
|
+
"LLVM=1",
|
|
110
|
+
"C=1",
|
|
111
|
+
"-s",
|
|
112
|
+
"CHECK=sparse",
|
|
113
|
+
],
|
|
114
|
+
cwd=str(self.repo.working_tree_dir),
|
|
115
|
+
desc="sparse check",
|
|
116
|
+
# stdout=subprocess.DEVNULL,
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
output = ""
|
|
120
|
+
for line in sparse_warnings.splitlines():
|
|
121
|
+
match = re.match(sparse_log_pattern, line)
|
|
122
|
+
# Avoids make's logs and only processes sparse warnings
|
|
123
|
+
if match:
|
|
124
|
+
filepath = match.group("filepath")
|
|
125
|
+
linenum = match.group("linenum")
|
|
126
|
+
# The git blame call below is expensive; run it only on files changed
|
|
127
|
+
if os.path.join(kernel_tree, filepath.strip()) not in files_changed:
|
|
128
|
+
continue
|
|
129
|
+
|
|
130
|
+
try:
|
|
131
|
+
blame_output = self.repo.git.blame(
|
|
132
|
+
f"-L{linenum},+1",
|
|
133
|
+
f"{self.base_commit}..{self.commit}",
|
|
134
|
+
"-l",
|
|
135
|
+
"--",
|
|
136
|
+
filepath,
|
|
137
|
+
)
|
|
138
|
+
# Only include if the current commit is blamed
|
|
139
|
+
if not blame_output.startswith("^"):
|
|
140
|
+
# Strip kernel_tree prefix from the line's filepath
|
|
141
|
+
if line.startswith(kernel_tree + "/"):
|
|
142
|
+
stripped_line = line[len(kernel_tree) + 1:]
|
|
143
|
+
else:
|
|
144
|
+
stripped_line = line
|
|
145
|
+
output += stripped_line + "\n"
|
|
146
|
+
except GitCommandError:
|
|
147
|
+
# File not found in the commit
|
|
148
|
+
continue
|
|
149
|
+
|
|
150
|
+
return output
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
|
|
2
|
+
# SPDX-License-Identifier: BSD-3-Clause
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from ...patch_review.patch_review import PatchReview
|
|
6
|
+
|
|
7
|
+
class StaticAnalysis(PatchReview):
|
|
8
|
+
"""
|
|
9
|
+
Base class for performing static analysis on kernel commits.
|
|
10
|
+
|
|
11
|
+
This class defines the interface and common methods for all static analysis
|
|
12
|
+
tools. Subclasses should override the `run` method.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
def clean_tree(self, arch: str = "arm"):
|
|
16
|
+
self.logger.debug("Cleaning kernel tree")
|
|
17
|
+
self.run_cmd_with_timer(
|
|
18
|
+
[
|
|
19
|
+
"make",
|
|
20
|
+
f"-j{os.cpu_count()}",
|
|
21
|
+
"-s",
|
|
22
|
+
"ARCH=" + arch,
|
|
23
|
+
"LLVM=1",
|
|
24
|
+
"mrproper",
|
|
25
|
+
],
|
|
26
|
+
cwd=str(self.repo.working_tree_dir),
|
|
27
|
+
desc="Cleaning tree",
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def make_config(self, config_type: str = "defconfig", arch: str = "arm", extra_args: list[str] = []) -> None:
|
|
32
|
+
self.logger.debug(f"Making {config_type}")
|
|
33
|
+
cmd = [
|
|
34
|
+
"make",
|
|
35
|
+
f"O={self.build_dir}",
|
|
36
|
+
f"-j{os.cpu_count()}",
|
|
37
|
+
"-s",
|
|
38
|
+
"ARCH=" + arch,
|
|
39
|
+
"LLVM=1",
|
|
40
|
+
config_type,
|
|
41
|
+
]
|
|
42
|
+
if extra_args:
|
|
43
|
+
cmd.extend(extra_args)
|
|
44
|
+
self.run_cmd_with_timer(
|
|
45
|
+
cmd,
|
|
46
|
+
cwd=str(self.repo.working_tree_dir),
|
|
47
|
+
desc=config_type,
|
|
48
|
+
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: patchwise
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: A tool for reviewing kernel patches
|
|
5
|
+
Author-email: David Gantman <dgantman@quicinc.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
License-File: LICENSE.txt
|
|
8
|
+
Requires-Dist: Sphinx>=8.1.3
|
|
9
|
+
Requires-Dist: litellm>=1.41.1
|
|
10
|
+
Requires-Dist: cachetools>=5.5.2
|
|
11
|
+
Requires-Dist: dtschema>=2025.2
|
|
12
|
+
Requires-Dist: yamllint>=1.26.3
|
|
13
|
+
Requires-Dist: ply>=3.11
|
|
14
|
+
Requires-Dist: GitPython>=3.1.44
|
|
15
|
+
Requires-Dist: codespell>=2.4.1
|
|
16
|
+
Requires-Dist: pytest>=8.3.5
|
|
17
|
+
Requires-Dist: rich-argparse>=1.7.0
|
|
18
|
+
Requires-Dist: tqdm>=4.67.1
|
|
19
|
+
Dynamic: license-file
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
patchwise/__init__.py,sha256=6X0vmLgrKufSfIms0idwDGdDBZR0a5-y7y7TvbbIiCw,567
|
|
2
|
+
patchwise/logger_setup.py,sha256=PjqSldinz1dNWBA2PeBnOKd8s_3OnggNqRqrzgDlknY,2692
|
|
3
|
+
patchwise/main.py,sha256=ktD1_K_HZvIQtihZ1QthMtfh1eobEDmLSCwMvfW7U6Y,3443
|
|
4
|
+
patchwise/patch_review/__init__.py,sha256=etqfGiTPPGqbZOQ1p_BIHQp7K4ensWl2_QhgBPREssA,5927
|
|
5
|
+
patchwise/patch_review/decorators.py,sha256=AnbOPKUKAO3uJgEQ3EWuNEBVKhCB9H6YO-8xv7tfrqc,1463
|
|
6
|
+
patchwise/patch_review/kernel_tree.py,sha256=FJTNFF0lEZ7vp_K2M5i_D2Kno0ZV6wtHqlgyVlcmb1s,4105
|
|
7
|
+
patchwise/patch_review/patch_review.py,sha256=4Ioox-wgs1yv7mcM0p9vEsC7yqmrT9RagM8Amev_nG0,11713
|
|
8
|
+
patchwise/patch_review/ai_review/__init__.py,sha256=tWY_uws-XNtuVoGWLMqbEiyu3pDjfEzmnZI5rnSZQr0,109
|
|
9
|
+
patchwise/patch_review/ai_review/ai_code_review.py,sha256=NIrfQuzxHXgwNCaeQIkz9prKIUNZoksia80E8ftxgO0,42118
|
|
10
|
+
patchwise/patch_review/ai_review/ai_review.py,sha256=NW1gKRjwB684td6_U9IjQg_Gs8OUnw9HkgeNcrysKRY,7019
|
|
11
|
+
patchwise/patch_review/ai_review/llm_commit_audit.py,sha256=XQiVzlkOwcEMF40O086qhe_SJH8BpnoTbGFmfCja51g,1953
|
|
12
|
+
patchwise/patch_review/static_analysis/__init__.py,sha256=tWY_uws-XNtuVoGWLMqbEiyu3pDjfEzmnZI5rnSZQr0,109
|
|
13
|
+
patchwise/patch_review/static_analysis/checkpatch.py,sha256=154kv2R9BZKoxDY8RZ4yi4ZPaefQ18dg4UMbOuRKm6Q,1525
|
|
14
|
+
patchwise/patch_review/static_analysis/coccicheck.py,sha256=ReObZwi0iiQh937xzbhV69_YU93Q7pSjCv8zYb7ER8M,3025
|
|
15
|
+
patchwise/patch_review/static_analysis/dt_check.py,sha256=rFUjb1-VVeUy_VsPrBtlS_kPJrAGaYzpgYPMncbGyOs,4792
|
|
16
|
+
patchwise/patch_review/static_analysis/dtbs_check.py,sha256=iioMySuqeAKYzm2HKyioPNHsZDb0arCAU9sbQ_d8Fhg,3042
|
|
17
|
+
patchwise/patch_review/static_analysis/sparse.py,sha256=MRVqk7UfReGeZ-6zcQcXHqeZMWio5TAZ7U51qbvtyvo,5146
|
|
18
|
+
patchwise/patch_review/static_analysis/static_analysis.py,sha256=IoJOafJOFZsF5hdv2YBoEJ3629oq5HFhfUQdsC4UpnU,1422
|
|
19
|
+
patchwise-0.2.0.dist-info/licenses/LICENSE.txt,sha256=RMOMjoFwJo1cFGnDWfRrCk4RpT99aLWlYQMMkESxuw0,1477
|
|
20
|
+
patchwise-0.2.0.dist-info/METADATA,sha256=5phV9kvdXFOWq-RsJGr_uKSKmelTfq_2pC6EZyXgHzc,561
|
|
21
|
+
patchwise-0.2.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
22
|
+
patchwise-0.2.0.dist-info/entry_points.txt,sha256=R3w48ni37bSI61BE80mVn9SyGxD3pOANEiUYyIit4_c,50
|
|
23
|
+
patchwise-0.2.0.dist-info/top_level.txt,sha256=v9mecnYOmv4jKtzG2L4dD5xI7KpkpOhyeZ40DxJtHTw,10
|
|
24
|
+
patchwise-0.2.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions are
|
|
5
|
+
met:
|
|
6
|
+
* Redistributions of source code must retain the above copyright
|
|
7
|
+
notice, this list of conditions and the following disclaimer.
|
|
8
|
+
* Redistributions in binary form must reproduce the above
|
|
9
|
+
copyright notice, this list of conditions and the following
|
|
10
|
+
disclaimer in the documentation and/or other materials provided
|
|
11
|
+
with the distribution.
|
|
12
|
+
* Neither the name of the copyright holder nor the names of its
|
|
13
|
+
contributors may be used to endorse or promote products derived
|
|
14
|
+
from this software without specific prior written permission.
|
|
15
|
+
|
|
16
|
+
THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
|
|
17
|
+
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
|
|
19
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
|
|
20
|
+
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
21
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
22
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
|
|
23
|
+
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
24
|
+
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
|
|
25
|
+
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
|
|
26
|
+
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
patchwise
|