summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorRoss Burton <ross.burton@arm.com>2023-10-27 16:29:40 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2023-10-27 17:48:11 +0100
commit62c80e3a79beaf521cb6e3e5e036e7aa40358a7c (patch)
tree0461399e74b5586cace625b18e279cc141e52d12 /scripts
parent116c0442128b27a33ef0b5b88f974d6ad78651bc (diff)
downloadpoky-62c80e3a79beaf521cb6e3e5e036e7aa40358a7c.tar.gz
scripts/contrib/patchreview: add commit and recipe count fields to JSON
The autobuilder scripts post-process the generated JSON to inject recipe and commit counts into the data. We can do this easily in patchreview instead. (From OE-Core rev: 77c96e43090cbf485aec612cc2315b85e5635dda) Signed-off-by: Ross Burton <ross.burton@arm.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/contrib/patchreview.py32
1 files changed, 22 insertions, 10 deletions
diff --git a/scripts/contrib/patchreview.py b/scripts/contrib/patchreview.py
index af66e32e02..36038d06d2 100755
--- a/scripts/contrib/patchreview.py
+++ b/scripts/contrib/patchreview.py
@@ -197,7 +197,7 @@ def histogram(results):
197 for k in bars: 197 for k in bars:
198 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]))
199 199
200def gather_patches(candidate): 200def find_layers(candidate):
201 # candidate can either be the path to a layer directly (eg meta-intel), or a 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 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, 203 # looking for a conf/layer.conf file. If that file exists then it's a layer,
@@ -205,19 +205,26 @@ def gather_patches(candidate):
205 # meta-*. 205 # meta-*.
206 206
207 if (candidate / "conf" / "layer.conf").exists(): 207 if (candidate / "conf" / "layer.conf").exists():
208 print(f"{candidate} is a layer") 208 return [candidate.absolute()]
209 scan = [candidate]
210 else: 209 else:
211 print(f"{candidate} is not a layer, checking for sub-layers") 210 return [d.absolute() for d in candidate.iterdir() if d.is_dir() and (d.name == "meta" or d.name.startswith("meta-"))]
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 211
212# TODO these don't actually handle dynamic-layers/
213
214def gather_patches(layers):
215 patches = [] 215 patches = []
216 for directory in scan: 216 for directory in layers:
217 filenames = subprocess.check_output(("git", "-C", directory, "ls-files", "recipes-*/**/*.patch", "recipes-*/**/*.diff"), universal_newlines=True).split() 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] 218 patches += [os.path.join(directory, f) for f in filenames]
219 return patches 219 return patches
220 220
221def count_recipes(layers):
222 count = 0
223 for directory in layers:
224 output = subprocess.check_output(["git", "-C", directory, "ls-files", "recipes-*/**/*.bb"], universal_newlines=True)
225 count += len(output.splitlines())
226 return count
227
221if __name__ == "__main__": 228if __name__ == "__main__":
222 import argparse, subprocess, os, pathlib 229 import argparse, subprocess, os, pathlib
223 230
@@ -229,7 +236,9 @@ if __name__ == "__main__":
229 args.add_argument("directory", type=pathlib.Path, metavar="DIRECTORY", help="directory to scan (layer, or repository of layers)") 236 args.add_argument("directory", type=pathlib.Path, metavar="DIRECTORY", help="directory to scan (layer, or repository of layers)")
230 args = args.parse_args() 237 args = args.parse_args()
231 238
232 patches = gather_patches(args.directory) 239 layers = find_layers(args.directory)
240 print(f"Found layers {' '.join((d.name for d in layers))}")
241 patches = gather_patches(layers)
233 results = patchreview(patches) 242 results = patchreview(patches)
234 analyse(results, want_blame=args.blame, verbose=args.verbose) 243 analyse(results, want_blame=args.blame, verbose=args.verbose)
235 244
@@ -242,8 +251,11 @@ if __name__ == "__main__":
242 251
243 row = collections.Counter() 252 row = collections.Counter()
244 row["total"] = len(results) 253 row["total"] = len(results)
245 row["date"] = subprocess.check_output(["git", "-C", args.directory, "show", "-s", "--pretty=format:%cd", "--date=format:%s"]).decode("utf-8").strip() 254 row["date"] = subprocess.check_output(["git", "-C", args.directory, "show", "-s", "--pretty=format:%cd", "--date=format:%s"], universal_newlines=True).strip()
246 row["commit"] = subprocess.check_output(["git", "-C", args.directory, "show", "-s", "--pretty=format:%H"]).decode("utf-8").strip() 255 row["commit"] = subprocess.check_output(["git", "-C", args.directory, "show-ref", "--hash", "HEAD"], universal_newlines=True).strip()
256 row['commit_count'] = subprocess.check_output(["git", "-C", args.directory, "rev-list", "--count", "HEAD"], universal_newlines=True).strip()
257 row['recipe_count'] = count_recipes(layers)
258
247 for r in results.values(): 259 for r in results.values():
248 if r.upstream_status in status_values: 260 if r.upstream_status in status_values:
249 row[r.upstream_status] += 1 261 row[r.upstream_status] += 1