interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / evidence / MAX-INTEROP / G1 / license_inventory.py

62 lines · 2732 bytes Raw Blame History
1#!/usr/bin/env python3
2"""File-level licence inventory of a git tree (from git objects, not the
3working tree, which may be sparse). Throwaway diagnostic.
4usage: license_inventory.py REPO REV OUT_TSV"""
5import collections, hashlib, os, re, subprocess, sys
6
7repo, rev, out = sys.argv[1:4]
8spdx = re.compile(r"SPDX-License-Identifier:\s*([^\n*#]+)")
9tree = subprocess.run(["git", "-C", repo, "ls-tree", "-r", "--format=%(objectmode) %(objectname) %(path)", rev],
10 capture_output=True, text=True, check=True).stdout.splitlines()
11entries = [l.split(" ", 2) for l in tree]
12lic = [p for _, _, p in entries if re.search(r"(^|/)(LICENSE|LICENCE|COPYING|MAX_LICENSE|NOTICE)[^/]*$", p)]
13lic_dirs = collections.defaultdict(list)
14for p in lic:
15 lic_dirs[os.path.dirname(p)].append(p)
16
17def nearest(p):
18 d = os.path.dirname(p)
19 while True:
20 if d in lic_dirs:
21 return ",".join(lic_dirs[d])
22 if not d:
23 return ""
24 d = os.path.dirname(d)
25
26def classify(b):
27 if b.startswith(b"version https://git-lfs"):
28 return "LFS-POINTER", ""
29 t = b[:4096].decode("utf-8", "replace")
30 m = spdx.search(t)
31 if m:
32 return "SPDX", m.group(1).strip().rstrip("-*/ ").strip()
33 if "Apache License" in t and "LLVM" in t:
34 return "HEADER", "Apache-2.0 WITH LLVM-exception"
35 if re.search(r"MAX (Community )?License|MAX Platform", t):
36 return "HEADER", "MAX License"
37 if "Apache License" in t:
38 return "HEADER", "Apache-2.0"
39 if "MIT License" in t or "Permission is hereby granted, free of charge" in t:
40 return "HEADER", "MIT"
41 if b"\0" in b[:4096]:
42 return "NONE", "binary"
43 return "NONE", "no-header"
44
45cat = subprocess.Popen(["git", "-C", repo, "cat-file", "--batch"], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
46counts = collections.Counter()
47with open(out, "w") as fo:
48 fo.write("path\tmode\tblob_sha256\tkind\tlicence\tgoverning_licence_file\n")
49 for mode, obj, path in entries:
50 if mode == "160000": # submodule
51 fo.write(f"{path}\t{mode}\t\tSUBMODULE\t\t\n"); counts[("SUBMODULE", "", "")] += 1; continue
52 cat.stdin.write((obj + "\n").encode()); cat.stdin.flush()
53 hdr = cat.stdout.readline().split()
54 n = int(hdr[2]); b = cat.stdout.read(n); cat.stdout.read(1)
55 kind, l = classify(b)
56 gov = nearest(path) if kind in ("NONE", "LFS-POINTER") else ""
57 fo.write(f"{path}\t{mode}\t{hashlib.sha256(b).hexdigest()}\t{kind}\t{l}\t{gov}\n")
58 counts[(kind, l, gov)] += 1
59cat.stdin.close(); cat.wait()
60print(f"repo={repo} rev={rev} files={len(entries)} licence_files={lic}")
61for (k, l, g), c in counts.most_common():
62 print(f"{c}\t{k}\t{l}\t{g}")