diff options
author | Ross Burton <ross.burton@arm.com> | 2023-10-27 16:29:39 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-10-27 17:48:11 +0100 |
commit | 116c0442128b27a33ef0b5b88f974d6ad78651bc (patch) | |
tree | 4b71faaa8e911b1a3bf00d520f7782f6e7019ec9 | |
parent | af339676ee8b364849dc8eb8f5b8ff5f0db40f4e (diff) | |
download | poky-116c0442128b27a33ef0b5b88f974d6ad78651bc.tar.gz |
scripts/patchreview: rework patch detection
A previous patch[1] added the ability to allow the search pattern for
patches to be changed, so that patchreview can be used across the entire
meta-oe repository by changing the patterns.
However, this means the caller needs to write long patterns when calling
patchreview.
Instead, we can see if the specified directory contains a layer by
checking if conf/layer.conf exists. If it does, then search for patches
inside this directory. If it doesn't, assume that the specified
directory is a repository that contains sublayers (such as
meta-openembedded) and look through each of the directories that match
the pattern meta-*.
This means patchreview can both scan either a single layer (eg
.../poky/meta) or a repository of sublayers (eg .../meta-openembedded).
[1] oe-core 599046ea9302af0cf856d3fcd827f6a2be75b7e1
(From OE-Core rev: a3a868519beab1b9cac94fefd7dbeffb09d047e9)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rwxr-xr-x | scripts/contrib/patchreview.py | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/scripts/contrib/patchreview.py b/scripts/contrib/patchreview.py index 43de105adc..af66e32e02 100755 --- a/scripts/contrib/patchreview.py +++ b/scripts/contrib/patchreview.py | |||
@@ -41,7 +41,7 @@ def blame_patch(patch): | |||
41 | "--format=%s (%aN <%aE>)", | 41 | "--format=%s (%aN <%aE>)", |
42 | "--", patch)).decode("utf-8").splitlines() | 42 | "--", patch)).decode("utf-8").splitlines() |
43 | 43 | ||
44 | def patchreview(path, patches): | 44 | def patchreview(patches): |
45 | import re, os.path | 45 | import re, os.path |
46 | 46 | ||
47 | # General pattern: start of line, optional whitespace, tag with optional | 47 | # General pattern: start of line, optional whitespace, tag with optional |
@@ -56,11 +56,10 @@ def patchreview(path, patches): | |||
56 | 56 | ||
57 | for patch in patches: | 57 | for patch in patches: |
58 | 58 | ||
59 | fullpath = os.path.join(path, patch) | ||
60 | result = Result() | 59 | result = Result() |
61 | results[fullpath] = result | 60 | results[patch] = result |
62 | 61 | ||
63 | content = open(fullpath, encoding='ascii', errors='ignore').read() | 62 | content = open(patch, encoding='ascii', errors='ignore').read() |
64 | 63 | ||
65 | # Find the Signed-off-by tag | 64 | # Find the Signed-off-by tag |
66 | match = sob_re.search(content) | 65 | match = sob_re.search(content) |
@@ -198,21 +197,40 @@ def histogram(results): | |||
198 | for k in bars: | 197 | for k in bars: |
199 | print("%-20s %s (%d)" % (k.capitalize() if k else "No status", bars[k], counts[k])) | 198 | print("%-20s %s (%d)" % (k.capitalize() if k else "No status", bars[k], counts[k])) |
200 | 199 | ||
200 | def gather_patches(candidate): | ||
201 | # candidate can either be the path to a layer directly (eg meta-intel), or a | ||
202 | # repository that contains other layers (meta-arm). We can determine what by | ||
203 | # looking for a conf/layer.conf file. If that file exists then it's a layer, | ||
204 | # otherwise its a repository of layers and we can assume they're called | ||
205 | # meta-*. | ||
206 | |||
207 | if (candidate / "conf" / "layer.conf").exists(): | ||
208 | print(f"{candidate} is a layer") | ||
209 | scan = [candidate] | ||
210 | else: | ||
211 | print(f"{candidate} is not a layer, checking for sub-layers") | ||
212 | scan = [d for d in candidate.iterdir() if d.is_dir() and (d.name == "meta" or d.name.startswith("meta-"))] | ||
213 | print(f"Found layers {' '.join((d.name for d in scan))}") | ||
214 | |||
215 | patches = [] | ||
216 | for directory in scan: | ||
217 | filenames = subprocess.check_output(("git", "-C", directory, "ls-files", "recipes-*/**/*.patch", "recipes-*/**/*.diff"), universal_newlines=True).split() | ||
218 | patches += [os.path.join(directory, f) for f in filenames] | ||
219 | return patches | ||
201 | 220 | ||
202 | if __name__ == "__main__": | 221 | if __name__ == "__main__": |
203 | import argparse, subprocess, os | 222 | import argparse, subprocess, os, pathlib |
204 | 223 | ||
205 | args = argparse.ArgumentParser(description="Patch Review Tool") | 224 | args = argparse.ArgumentParser(description="Patch Review Tool") |
206 | args.add_argument("-b", "--blame", action="store_true", help="show blame for malformed patches") | 225 | args.add_argument("-b", "--blame", action="store_true", help="show blame for malformed patches") |
207 | args.add_argument("-v", "--verbose", action="store_true", help="show per-patch results") | 226 | args.add_argument("-v", "--verbose", action="store_true", help="show per-patch results") |
208 | args.add_argument("-g", "--histogram", action="store_true", help="show patch histogram") | 227 | args.add_argument("-g", "--histogram", action="store_true", help="show patch histogram") |
209 | args.add_argument("-j", "--json", help="update JSON") | 228 | args.add_argument("-j", "--json", help="update JSON") |
210 | args.add_argument("-p", "--pattern", nargs=1, action="extend", default=["recipes-*/**/*.patch", "recipes-*/**/*.diff"], help="pattern to search recipes patch") | 229 | args.add_argument("directory", type=pathlib.Path, metavar="DIRECTORY", help="directory to scan (layer, or repository of layers)") |
211 | args.add_argument("directory", help="directory to scan") | ||
212 | args = args.parse_args() | 230 | args = args.parse_args() |
213 | 231 | ||
214 | patches = subprocess.check_output(("git", "-C", args.directory, "ls-files") + tuple(args.pattern)).decode("utf-8").split() | 232 | patches = gather_patches(args.directory) |
215 | results = patchreview(args.directory, patches) | 233 | results = patchreview(patches) |
216 | analyse(results, want_blame=args.blame, verbose=args.verbose) | 234 | analyse(results, want_blame=args.blame, verbose=args.verbose) |
217 | 235 | ||
218 | if args.json: | 236 | if args.json: |