scripts/spdxcheck: Add option to display files without SPDX

Makes life easier when chasing the missing ones. Is activated with '-f'
on the command line.

# scripts/spdxcheck.py -f kernel/
Files without SPDX:
    ./kernel/cpu.c
    ./kernel/kmod.c
    ./kernel/relay.c
    ./kernel/bpf/offload.c
    ./kernel/bpf/preload/.gitignore
    ./kernel/bpf/preload/iterators/README
    ./kernel/bpf/ringbuf.c
    ./kernel/cgroup/cgroup.c
    ./kernel/cgroup/cpuset.c
    ./kernel/cgroup/legacy_freezer.c
    ./kernel/debug/debug_core.h
    ./kernel/debug/kdb/Makefile
    ./kernel/debug/kdb/kdb_bp.c
    ./kernel/debug/kdb/kdb_bt.c
    ./kernel/debug/kdb/kdb_cmds
    ./kernel/debug/kdb/kdb_debugger.c
    ./kernel/debug/kdb/kdb_io.c
    ./kernel/debug/kdb/kdb_keyboard.c
    ./kernel/debug/kdb/kdb_main.c
    ./kernel/debug/kdb/kdb_private.h
    ./kernel/debug/kdb/kdb_support.c
    ./kernel/locking/lockdep_states.h
    ./kernel/locking/mutex-debug.c
    ./kernel/locking/spinlock_debug.c
    ./kernel/sched/pelt.h

With the optional -D parameter the directory depth can be limited:

# scripts/spdxcheck.py -f -D 0 kernel/
Files without SPDX:
    ./kernel/cpu.c
    ./kernel/kmod.c
    ./kernel/relay.c

Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Thomas Gleixner 2022-05-16 12:27:27 +02:00 committed by Greg Kroah-Hartman
parent 0e7f030687
commit 67924b7141
1 changed files with 19 additions and 2 deletions

View File

@ -32,10 +32,16 @@ class dirinfo(object):
def __init__(self):
self.missing = 0
self.total = 0
self.files = []
def update(self, miss):
def update(self, fname, basedir, miss):
self.total += 1
self.missing += miss
if miss:
fname = './' + fname
bdir = os.path.dirname(fname)
if bdir == basedir.rstrip('/'):
self.files.append(fname)
# Read the spdx data from the LICENSES directory
def read_spdxdata(repo):
@ -245,7 +251,7 @@ class id_parser(object):
base += '/'
di = self.spdx_dirs.get(base, dirinfo())
di.update(fail)
di.update(fname, base, fail)
self.spdx_dirs[base] = di
def scan_git_tree(tree, basedir, dirdepth):
@ -275,6 +281,8 @@ if __name__ == '__main__':
help='Show [sub]directory statistics.')
ap.add_argument('-D', '--depth', type=int, default=-1,
help='Directory depth for -d statistics. Default: unlimited')
ap.add_argument('-f', '--files', action='store_true',
help='Show files without SPDX.')
ap.add_argument('-m', '--maxlines', type=int, default=15,
help='Maximum number of lines to scan in a file. Default 15')
ap.add_argument('-v', '--verbose', action='store_true', help='Verbose statistics output')
@ -364,6 +372,15 @@ if __name__ == '__main__':
pc = int(100 * valid / di.total)
sys.stderr.write(' %-80s: %5d of %5d %3d%%\n' %(f, valid, di.total, pc))
if ndirs and ndirs != dirsok and args.files:
if args.verbose or args.dirs:
sys.stderr.write('\n')
sys.stderr.write('Files without SPDX:\n')
for f in sorted(parser.spdx_dirs.keys()):
di = parser.spdx_dirs[f]
for f in sorted(di.files):
sys.stderr.write(' %s\n' %f)
sys.exit(0)
except Exception as ex: