Re: [PATCH 02/10] checkpatch: cache SPDX license checks and gate on SPDX_LICENSE_TAG
From: Joe Perches
Date: Wed Dec 02 2026 - 20:52:57 EST
On Tue, 2026-12-01 at 14:53 -0800, Bart Van Assche wrote:
> Memoize is_SPDX_License_valid() results in %spdx_license_cache keyed by
memoize is a word? Maybe cache or remember.
> license string, and gate the call site in process() on
> show_type("SPDX_LICENSE_TAG").
>
> Avoid launching a new Python interpreter for scripts/spdxcheck.py (~140 ms
> per call) when checking repeated license expressions across multiple files
> or when SPDX_LICENSE_TAG warnings are ignored.
>
> Signed-off-by: Bart Van Assche <bvanassche@xxxxxxx>
> ---
> scripts/checkpatch.pl | 15 ++++++++++-----
> 1 file changed, 10 insertions(+), 5 deletions(-)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index 543fd002ee29..3602e79fc091 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.p;
> @@ -1323,15 +1323,19 @@ sub is_maintained_obsolete {
> return $maintained_status{$filename} =~ /obsolete/i;
> }
>
> +my %spdx_license_cache = ();
> +
> sub is_SPDX_License_valid {
> my ($license) = @_;
>
> return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
>
> - my $root_path = abs_path($root);
> - my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
> - return 0 if ($status ne "");
> - return 1;
> + if (!exists($spdx_license_cache{$license})) {
> + my $root_path = abs_path($root);
> + my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
> + $spdx_license_cache{$license} = ($status ne "") ? 0 : 1;
> + }
> + return $spdx_license_cache{$license};
> }
This bit is useful
>
> my $camelcase_seeded = 0;
> @@ -3996,7 +4000,8 @@ sub process {
> "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
> } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
> my $spdx_license = $1;
> - if (!is_SPDX_License_valid($spdx_license)) {
> + if (show_type("SPDX_LICENSE_TAG") &&
I'd rather not add a bunch of show_type calls to tests
> + !is_SPDX_License_valid($spdx_license)) {
> WARN("SPDX_LICENSE_TAG",
> "'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
> }