From patchwork Tue Dec 1 03:49:04 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 106682 Received: from mail-pl1-f171.google.com (mail-pl1-f171.google.com [209.85.214.171]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.4078.1796096957301988237 for ; Mon, 30 Nov 2026 19:49:17 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=K68iX7D0; spf=pass (domain: konsulko.com, ip: 209.85.214.171, mailfrom: tim.orling@konsulko.com) Received: by mail-pl1-f171.google.com with SMTP id d9443c01a7336-2f041f88577so60858705ad.1 for ; Mon, 30 Nov 2026 19:49:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1796096957; x=1796701757; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=MHbmkknTI/DlqLvsyTUwzHWkpjnjRC2avoOOsA53Lmc=; b=K68iX7D0W7kbMCqbaOBdVdoUILJNocX2bCF9vwmsDeXuUTesH/T9WXsMJVP0fdZQC5 NFajOX77SQr2V6wXGFPnvnPnzUpawHcFlCAcx0uQPmc2bw+L7/+Uzjhvue/uHjaBOsHe F8stGXQ4wwy9t41v+ww65VQFg0eZrutURNPfQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096957; x=1796701757; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=MHbmkknTI/DlqLvsyTUwzHWkpjnjRC2avoOOsA53Lmc=; b=nCtsDF0GD6X+2f//sd/5Uz1VlN++oVSvNIVhHTbTz5TULty/KZyk0RLyDVjGhmOu98 lxLxpsd67EazFFBzvB/7ROfs1AuS7aJuzQoKPwINek1mqXJLWpVGMXVe7cRKmAxl+ba0 zGrDAwOuEeRFtnU/QvWTdiQPPCA6RnSst5GmAxPzcQ4MxN3XRBiKZMy3/o1MpLdlSXb2 TmJ/Jht1bG7oyVcN3RILJHhtxBu2ac+eT/XeuX+kTllZLOCBOCf75QUPKjJXdEuu1g3l koNSfMKEBiE/gZHrWzqoyI5wYqLFsw+hdenERk8YnF57MejCZAke6vmD4yGo91XunLQ9 Lq4w== X-Gm-Message-State: APuU4Z9XbmrASMIkPgwndanXgo4Q6uNwmd7QuFbu9bPVNABlpnWehXUf ZFhHuBo9Nzwr6KPaaHx/ypJFebDXObj9nzZro73OgMBCwgNs4TX+PPH+XpARrZ7tbOD98Y7gQNP iBEKvPfM= X-Gm-Gg: AZFdTZeVADg0mZm1MSlxbQZPq6QPt9HCS+CDb3+4LlV6ajjAVkICaUy6cQCwdDvMwp6 YAYZe1KinBLmQFd2wHe43rHuTxEUXy7yr5Rwpzg3eqQx+z+QBEiMMMWQlFOs4KUM54feEp3ttfr ciUBr8TmhMXBGUnilVFdNJWcB9BcvSToJWvgl6wDPWt4O1ehFvwRi7Tv/DjG/04ZpAa1VeB+zjw MwvygmCXKZjTTtUT9vP7uhBmA32ywnOGmOlhB/RuYNNJZHHB1NJyOf+x+eYeKrSkY1ikMMZco42 cg/s6eXhh9LY5j006DG++N2v3Zjh7OwvnOgl1TjLEGtelaa2B32vukv6c4YChwbaBP47i3MqERj 1Hn/iin1dscQKTv21PpnQf6GpnlHP7NPC4OE75QfN9YmVZJ7R6qM7mgFsawo6uJhJUYkNXN4RGD eGuiQ+bcJO7Ha2h7yq+2XrxELUj2c9netEUmoZOWAB8TB7CEqpgm9k1jsrGbVQOHxPCeALrGpR8 EytgWvhpkjAMMlVCHol+MMtpgvaX+ehIvZjXB/KawR+uSRxdRKunM3AbOsH0ts4a1PHPFx4p2AX +PMf/zPaf0mGalfQE+HOiPkmPy3fwXCSmxjI2lzLOiw2STPFAi5AxxbJcPx/arljD1BPpDH6NDu ODjGThPDwxwTGm+E0iOjUzSJ3rpQ8QaHnC2DEz6NXgbLybqgu3gADrlFpUG+iZS1sgAqkH9iC1N Gus5LfrTKBFM4= X-Received: by 2002:a17:903:2c50:b0:2e6:7c6:8d40 with SMTP id d9443c01a7336-2f03f1a466fmr352182375ad.27.1796096956716; Mon, 30 Nov 2026 19:49:16 -0800 (PST) Return-Path: Received: from localhost (c-24-20-171-118.hsd1.or.comcast.net. [24.20.171.118]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03ee84285sm172761605ad.3.2026.11.30.19.49.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:49:16 -0800 (PST) From: Tim Orling To: openembedded-core@lists.openembedded.org Cc: Tim Orling , Bruce Ashfield Subject: [PATCH 1/7] license_finder: keep all license files of the nearest directory Date: Mon, 30 Nov 2026 19:49:04 -0800 Message-ID: <20261201034910.25521-2-tim.orling@konsulko.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201034910.25521-1-tim.orling@konsulko.com> References: <20261201034910.25521-1-tim.orling@konsulko.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 03:49:20 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251657 find_license_files() with first_only returned only the first license file, in name order, of the nearest directory. github.com/klauspost/pgzip has LICENSE (MIT) and GO_LICENSE (BSD-3-Clause), so go-mod-update-modules left out MIT. Return every license file of that directory. The top-down search that recipetool uses is unchanged. AI-Generated: Claude Opus 5.5 Signed-off-by: Tim Orling --- meta/lib/oe/license_finder.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py index 9c217cf891..d08d4af5d2 100644 --- a/meta/lib/oe/license_finder.py +++ b/meta/lib/oe/license_finder.py @@ -127,7 +127,10 @@ def _crunch_license(licfile): def find_license_files(srctree, first_only=False, bottom=""): """ Search srctree for files that look like they could be licenses. - If first_only is True, only return the first file found. + If first_only is True, only return the first file found. When searching + upwards from bottom, return all files from the first directory that has + any instead, because a directory can hold several licenses, for example + LICENSE for the project and GO_LICENSE for code copied from Go. If bottom is not empty, start at bottom and continue upwards to the top. """ licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10'] @@ -144,11 +147,10 @@ def find_license_files(srctree, first_only=False, bottom=""): for name in sorted(files): if name.endswith(skip_extensions): continue - for spec in licspecs: - if fnmatch.fnmatch(name, spec): - licfiles.append(os.path.join(srcdir, name)) - if first_only: - return licfiles + if any(fnmatch.fnmatch(name, spec) for spec in licspecs): + licfiles.append(os.path.join(srcdir, name)) + if first_only and licfiles: + return licfiles srcdir = os.path.dirname(srcdir) return licfiles From patchwork Tue Dec 1 03:49:05 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 106683 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by mx.groups.io with SMTP id smtpd.msgproc02-g2.4015.1796096959624805033 for ; Mon, 30 Nov 2026 19:49:19 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=GgnZ2Y6I; spf=pass (domain: konsulko.com, ip: 209.85.214.180, mailfrom: tim.orling@konsulko.com) Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2f0634667aaso43578125ad.0 for ; Mon, 30 Nov 2026 19:49:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1796096959; x=1796701759; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=uCi6NGdQOPYA+uw+n5bV1vWrqSHtKLCyLzDWkHsjdpc=; b=GgnZ2Y6IVSpUeKDiOscMdoFAmH4d/A5mtG5Piu7GSuz2rwOiQ2Awwyc8OX3/LzysXE r5siKodyhkYZ/XqM6E+1Xq916Puu7c8Hs0Nms0UpASfaY3SOF/taez5e7RNl2pcFzQji qwXvhdLetByyDUxy/aPYQS1+qZj49MDttU9ro= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096959; x=1796701759; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=uCi6NGdQOPYA+uw+n5bV1vWrqSHtKLCyLzDWkHsjdpc=; b=V4fn7JMsz/2aBrEbSZrDSHxRZtFl7gE92wNOwdaWUIf95aUgADamnX01q9UN6847kD 0jonN9H2Ug5ZKbg3EOWowcAylWhWstXLccIgCbZBFqeQTwLiFI/e3QcFLDcIpOXxEfzo qGalW6tN+S4WWlS7aFqZy0rnQ1sEqSY2QQULmYUoge7iAvGLFcnSGw1U+E1RHltgLe5I eXR/smyIxDQKVEcivOUwMh+hbOR97tyk/AHDktVfj1ADehw2eF3oDMM7ZKkWFXRO+oSv TqzkSQ44bdWvX7eWOh7THu4DkSE7W7ukDWwzKd1T3tds5Ke/8axUMDmbm03DtWYzC6G2 70dw== X-Gm-Message-State: APuU4Z9cxPsrU7QOcEdTDRy+MZyqPTdrCp0DyZ4KzWVc4qfLXhvbdWxn 1wc9nma1gAM83BCULabikKv6zVBhPs3FpAFs/grDBSTIJRahfJCIK/Tp48iPLT0ABZY01QuOfZr 7mPvi X-Gm-Gg: AZFdTZegqkq1UMTkdaOiOaISjtjGpcK0P5zcXPoOlBagLf6UZR+n+96rE30b/ZOCfB+ 9ZVFxHHw7QXPU1peJ4gMZd4KWSyyJI+IH47pdDojQ8Qg1D9UmHNL/eKRwOO81U9/0xgUsMauqwJ BXQOZSOhiCDDaDXY+/yMUx2GTjeUFPU6QYuwy8sdojXw+oLMN+5To41ZihN6b8hviBrpshVIb8S 1D4bwIyZe5iS4FNk6Mr5HpmF4VNOGLwyfx088jlrkSnq+DYMKtTT2cO8EeSIZi1+J4nJk/p5eiR 9QuTWR129Fhj74ajj3Vkt/V49JP/oKB94ZWK4yPSPiKUcxBm85ETwZ+IeSByVgODpLwqS/f2D1G ryBznHbL3fW9NM6EApptRJjrT78zZgFmnLWkQvwA7OmdNpIoNX3zWQwomv2JqNcSoQXIXjvuyGr 65hx7+oRbFE4G26EWYHIdh/rYGVfU3TLlqiMBwKZJIEFce5j7LQKQVnVSbE64B/QrKSoSh7z02i MyE1RD9Fq/DuydWxYdaGJ6Cu6Ow+KpX4zAT294I3j+qqCF6DazM0AS4T+w1LT9qkXiJ5rgEA2vf JvsBIKXPxXcwhqNIMrcrGJUvzXmCBHFGvtjpOe9dK3SdJPmm4bCbMbMVphlFFj2/dImtVVPlq2X LgIvHI7sBq8MX7wYIFLPV+RhEMSUqhowcT5WxL1u4iWXWK1F1SwdsPCj95I6jjWPrQZE= X-Received: by 2002:a17:903:1a43:b0:2ed:3032:ec21 with SMTP id d9443c01a7336-2f03f1b9c14mr266299725ad.21.1796096958629; Mon, 30 Nov 2026 19:49:18 -0800 (PST) Return-Path: Received: from localhost (c-24-20-171-118.hsd1.or.comcast.net. [24.20.171.118]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03ee84425sm177662485ad.6.2026.11.30.19.49.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:49:18 -0800 (PST) From: Tim Orling To: openembedded-core@lists.openembedded.org Cc: Tim Orling , Bruce Ashfield Subject: [PATCH 2/7] licensecheck: add recipe Date: Mon, 30 Nov 2026 19:49:05 -0800 Message-ID: <20261201034910.25521-3-tim.orling@konsulko.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201034910.25521-1-tim.orling@konsulko.com> References: <20261201034910.25521-1-tim.orling@konsulko.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 03:49:21 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251658 Add licensecheck 0.3.1, the license detection library that pkg.go.dev uses, for go-mod-update-modules. main.go is a small front end that prints, as JSON, the licenses found in each file and how much of the file they cover. The library is BSD-3-Clause; main.go is MIT. AI-Generated: Claude Fable 5.2 (maintainers.inc entry, CVE_PRODUCT) Signed-off-by: Tim Orling --- meta/conf/distro/include/maintainers.inc | 1 + .../licensecheck/files/main.go | 49 +++++++++++++++++++ .../licensecheck/licensecheck_0.3.1.bb | 31 ++++++++++++ 3 files changed, 81 insertions(+) create mode 100644 meta/recipes-devtools/licensecheck/files/main.go create mode 100644 meta/recipes-devtools/licensecheck/licensecheck_0.3.1.bb diff --git a/meta/conf/distro/include/maintainers.inc b/meta/conf/distro/include/maintainers.inc index 62de04001e..8024be3383 100644 --- a/meta/conf/distro/include/maintainers.inc +++ b/meta/conf/distro/include/maintainers.inc @@ -473,6 +473,7 @@ RECIPE_MAINTAINER:pn-libxvmc = "Unassigned " RECIPE_MAINTAINER:pn-libxxf86vm = "Unassigned " RECIPE_MAINTAINER:pn-libyaml = "Wang Mingyu " RECIPE_MAINTAINER:pn-libzip = "Igor Opaniuk " +RECIPE_MAINTAINER:pn-licensecheck = "Tim Orling " RECIPE_MAINTAINER:pn-lighttpd = "Unassigned " RECIPE_MAINTAINER:pn-linux-dummy = "Unassigned " RECIPE_MAINTAINER:pn-linux-firmware = "Vivek Puar " diff --git a/meta/recipes-devtools/licensecheck/files/main.go b/meta/recipes-devtools/licensecheck/files/main.go new file mode 100644 index 0000000000..5b38107af7 --- /dev/null +++ b/meta/recipes-devtools/licensecheck/files/main.go @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: MIT +// +// Command licensecheck prints the licenses that github.com/google/licensecheck +// finds in each file, one JSON object per file. +package main + +import ( + "encoding/json" + "fmt" + "os" + + "github.com/google/licensecheck" +) + +type match struct { + ID string `json:"id"` + Start int `json:"start"` + End int `json:"end"` + IsURL bool `json:"url,omitempty"` +} + +type result struct { + File string `json:"file"` + Percent float64 `json:"percent"` + Matches []match `json:"matches"` + Error string `json:"error,omitempty"` +} + +func main() { + if len(os.Args) < 2 { + fmt.Fprintln(os.Stderr, "usage: licensecheck FILE...") + os.Exit(2) + } + enc := json.NewEncoder(os.Stdout) + for _, f := range os.Args[1:] { + r := result{File: f, Matches: []match{}} + data, err := os.ReadFile(f) + if err != nil { + r.Error = err.Error() + } else { + cov := licensecheck.Scan(data) + r.Percent = cov.Percent + for _, m := range cov.Match { + r.Matches = append(r.Matches, match{m.ID, m.Start, m.End, m.IsURL}) + } + } + enc.Encode(r) + } +} diff --git a/meta/recipes-devtools/licensecheck/licensecheck_0.3.1.bb b/meta/recipes-devtools/licensecheck/licensecheck_0.3.1.bb new file mode 100644 index 0000000000..a8fe6ef22f --- /dev/null +++ b/meta/recipes-devtools/licensecheck/licensecheck_0.3.1.bb @@ -0,0 +1,31 @@ +SUMMARY = "Identify the licenses in license files" +DESCRIPTION = "A command line front end for the Go licensecheck library, which \ +pkg.go.dev uses to detect the licenses of Go modules. For each file, it lists \ +every license that it finds, where in the file, and how much of the file the \ +licenses cover. go-mod-update-modules.bbclass uses it to identify the licenses \ +of Go module dependencies." +HOMEPAGE = "https://github.com/google/licensecheck" +BUGTRACKER = "https://github.com/google/licensecheck/issues" +SECTION = "devel" + +# No CPE in the NVD yet. Name the vendor, as other projects are also +# called licensecheck. +CVE_PRODUCT = "google:licensecheck" + +LICENSE = "BSD-3-Clause AND MIT" +LIC_FILES_CHKSUM = "file://src/${GO_IMPORT}/LICENSE;md5=a413d6b3884e141783f23d00d5838777 \ + file://src/${GO_IMPORT}/cmd/licensecheck/main.go;beginline=1;endline=1;md5=6ec41034e04432ee375d0e14fba596f4" + +SRC_URI = "git://github.com/google/licensecheck;protocol=https;nobranch=1;destsuffix=${GO_SRCURI_DESTSUFFIX} \ + file://main.go;subdir=${GO_SRCURI_DESTSUFFIX}/cmd/licensecheck" +SRCREV = "16aaea36649f556bae5a5ee972c247f58a0de1c4" + +GO_IMPORT = "github.com/google/licensecheck" +GO_INSTALL = "${GO_IMPORT}/cmd/licensecheck" + +# The library only uses the standard library +export GO111MODULE = "off" + +inherit go + +BBCLASSEXTEND = "native" From patchwork Tue Dec 1 03:49:06 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 106684 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.4079.1796096961261812029 for ; Mon, 30 Nov 2026 19:49:21 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=IFeBOxwq; spf=pass (domain: konsulko.com, ip: 209.85.216.52, mailfrom: tim.orling@konsulko.com) Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-3b51a9606e8so3207833a91.3 for ; Mon, 30 Nov 2026 19:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1796096960; x=1796701760; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=nlNE8hOAbi1LC8p/dmlcarkSh8NdzdYfkvUw2dGzVEk=; b=IFeBOxwqGZd6VL8XGqHaVxjHNrrzcSFXEqqD0g6X6AMS0IuqNy1fIhL9LqpdGcB2WE DU9oXTpuy59/6y3CYr1QSH8iELMnec06kgaUvXrgs6yg4QekOOnqm7mryyFxakSDFH8p o8DUTQlRMyiTFyEOhFjDgEKy4VwVgC547W5N8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096960; x=1796701760; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=nlNE8hOAbi1LC8p/dmlcarkSh8NdzdYfkvUw2dGzVEk=; b=Oi0XYgC7EBOno65nYXdgx7l6Cjw7InPRZarnr+mbpm6pCTtE07MzPQBtinJy+at4eD wZ8usqYnstVkHhY5FTMfCe/YJwhNlZBaagNNwb0dxx0Ovd5aGqItzUmv+IDWDWnqxm65 1xtyXATEcUoRv5wyIrh9FRYntJ4RS2oU+ARG8dtdgKiPyzzEPdxyvQG6/2oovcFYcvDr 5AQNbhCVLFpOFWg5I4avi14n1KSxKr8vxw7H9aZzs4edmSU+kRHJ2+IGkq1Z+PEtcqgy c1kvNTeGTn/1mZpMc3LX09z0yKZx5wUFAVrBNH3dhVs00nkYa5DWg1DWBCn5frxSlDBo +0fg== X-Gm-Message-State: APuU4Z9wpGxgZDQzdaP5zF9YcApCSfz9Jbi6dQDo/O6pF+mjtyFbW/bV ALCZe+FFRnx6OG9Suhzs0S/iI7yw4bAE133WrFZ9u6I8r5C0xSXmraKWBowzujC0HaDFn9OmFH6 lc2YLobc= X-Gm-Gg: AZFdTZdakItctpOTlWpwALhw2y48SoQNAdj8Uy+sjAN17ttxMLIFqCzqH8Po3E3BDkp UM68uGKhNVAcPgdvTB6HhthynVhms6fa1Jt7ZbtPa+tiQdH2Si/GhbW0gyEBdUI2i2zZQVYNaF1 hGMWpKLQCOmgjWAPG9wfxkSL7liEb8pwuPRbbA+b0rXpQ64Ssm4YLiCxvtc6lvHEVhkpFtPH4yr +G/1zivCnqWcxs2Dsv0FfBSrRrEFHWu2Ts3BgcgbGaka1ymiL2N0Ysb+g/1kKcI6xPMKKSMpbz6 6ZehDnPyvxDBfFiczey1LkpB4rUdmJYXyLW5v33zJutjjEXk2q9Hr8C7/7cMhjJvVu5MVlY9++5 U8kZRat2NGNt7YWHIyogdjRYpI72B1vRSiQMHyJH0ZpwizzymMKhbFGQ8vPMpxYNORsQAWobPN2 EORl5XTX+ZqsYd9taPbQXEHsd7tYMcHD5N7OXXs+xRamvksDn0cBbP7fkVK3UZnUjffKENXTxpi fUOkVwVqZiJI3s6si+VixqWXZ6XRnLIAmTZoJaRekK2v6yyAGJRBAto40KIymJ19miHKUZ9f6mo K5zsS9gG7dWSXnBNWS0qwm1Btm7k5q+nJPhBiZyhlv74vq4KP/Lt+s8hNXcydwgkjj7ZQ8ymxx/ zY1M4FUB0qeBmaoAK3Eqzia0ztD9Uawyu7F/WkuBuNFQ3e7Q8FxUXmVbqHRM76Bw+VQGoV3Q/tx JCTo7m3IlhbGjK X-Received: by 2002:a17:90b:380e:b0:3a6:e99b:bbdb with SMTP id 98e67ed59e1d1-3b41c9493ccmr35997167a91.50.1796096960595; Mon, 30 Nov 2026 19:49:20 -0800 (PST) Return-Path: Received: from localhost (c-24-20-171-118.hsd1.or.comcast.net. [24.20.171.118]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b41ad0a33fsm56191519a91.6.2026.11.30.19.49.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:49:20 -0800 (PST) From: Tim Orling To: openembedded-core@lists.openembedded.org Cc: Tim Orling , Bruce Ashfield Subject: [PATCH 3/7] license_finder: do not match files that have no license text Date: Mon, 30 Nov 2026 19:49:06 -0800 Message-ID: <20261201034910.25521-4-tim.orling@konsulko.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201034910.25521-1-tim.orling@konsulko.com> References: <20261201034910.25521-1-tim.orling@konsulko.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 03:49:30 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251659 _crunch_license() drops titles, copyright lines and URLs, so a file with nothing else hashes as an empty text, as does common-licenses/Proprietary. Such a file matched "Proprietary", which is not an SPDX identifier, and go-mod-update-modules failed with "Unknown Expression 'Proprietary'". Return None when no text is left, and do not register None as the hash of a known license. An exact copy of a license file still matches by its plain md5. AI-Generated: Claude Opus 5.5 Signed-off-by: Tim Orling --- meta/lib/oe/license_finder.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py index d08d4af5d2..cd290adf59 100644 --- a/meta/lib/oe/license_finder.py +++ b/meta/lib/oe/license_finder.py @@ -55,7 +55,8 @@ def _crunch_known_licenses(d): md5sums[md5value] = fn # Also hash a "crunched" version md5value = _crunch_license(path) - md5sums[md5value] = fn + if md5value: + md5sums[md5value] = fn return md5sums @@ -115,6 +116,11 @@ def _crunch_license(licfile): if line: lictext.append(line) + # Only titles, copyright lines or URLs: there is no license text to + # compare, and an empty text would match every other empty text + if not lictext: + return None + m = hashlib.md5() try: m.update(' '.join(lictext).encode('utf-8')) From patchwork Tue Dec 1 03:49:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 106685 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.4081.1796096963275891683 for ; Mon, 30 Nov 2026 19:49:23 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=J07eAir0; spf=pass (domain: konsulko.com, ip: 209.85.210.180, mailfrom: tim.orling@konsulko.com) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-8b3577deeb0so5054273b3a.3 for ; Mon, 30 Nov 2026 19:49:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1796096963; x=1796701763; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=HXcMUxovbgkqBQI1x0UnlKV+2O+wpgswJ1q3n80N9+I=; b=J07eAir0/ZWoW2pC+oyzHrzpETiS8bsHrPUGRByEHWqXh2+6uqXg8zbu1CRuTSmmJk cXGQcIDHRyaImziaksW9kJv3++zd1MMBkN+WB+Td4HeRhncJRuti06rj/ERoFfjNUnqh rdVCF+yrnHOeViJdBPbecugDWMNDTsoD1Vd/Q= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096963; x=1796701763; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=HXcMUxovbgkqBQI1x0UnlKV+2O+wpgswJ1q3n80N9+I=; b=pZxqO+HFoQuLMiscZEOQA24y+m+OwLIBCFlpee2T4ybLbvJnCjZjnSAbvG7syZNj0+ GrDAy5In+lDfxncxzsa7pqpVkb90Ms7tLVrRlUU90RSr0A/P47nxuKXwOJ2GBZP7eFUz RfvcuGPFtyT356aq9YoeaoZWZPXDKtD1Yaypk40afIuMwaMAlwqRARc3Qrax8Cs0Flo/ vD0ZbNcUUAwEV5DHxvNjAWLAoJmT3cMugiEAVksElkojy7/mRzKlv46cPA47G88DPl0g UmGk8lc0ab9FEjMDgt6pHkdufe9sv69S2fT7WPSH93DUgyB/nO2Kqjsu7CWVVDrJDjxv dewg== X-Gm-Message-State: APuU4Z8YkwaYAaUgCWiZVR2KNFIJDmSspkl9HjZ+QX6SesuetaX3oISy sGU5qhxugcTUpTf1eHpEX0dZ0b1iG1QgLkpWITowloXazpx8DLIXD2zv/sVb18UtNdUA9xBBP7n mHU6Tyb8= X-Gm-Gg: AZFdTZcYoIpmVViCYHRR1jCbpoC1IjXo3tNpNACtasMIodyoYTcUrwg8W5qwyE5sRZb fGy1wWptf4coJbQSKlegVOiFJv/AzRYdE/CHsee7ewaTVE+juKoqSuUgG591oarNyQuvFLl2ag1 U+Ppy9GbmWAk08vmnEKsLDsP3tyTy6HE9nwE/jCYy8zh8j7YqT+3HENgmNEsx1C+2+UE/DJM0wH ShPdVl6dXR7ONf8j6Zb1VEIjENL1ZN66/+Ec1pkczxKbu6P8ZTETV1uA3IUVKqofVn9Dhi7CAbz yBryiJP4b2J1Bq2prEv4PNomxgvuPHJmVuQIo9v6KLDzQxS0vDsDUr6/LF75hRn3arx92WYNyKQ T0gvstaUUGmHry54d01TrfPGSksSjZ8Ts4o7JNYLO4xdaq62sMIvyXFjMIwdqNKbbFGOgXdA4ug j5WPFQjfEPz8DRed8jY2nc/Fo+Zmc0MSZX1NGVD13XAldZsnsa1kMcbtmPU7EM1Mx82OpWq1Tru p2suZFot4u5uBeapN3pSvlag3aCKPO8tOMXLKQMMFT5+i1+pveGNL0nJkNRS8MDyJMuDYvzbBO3 lFveB7EXNVtU2k6s97HsIuvSx114M2KrywRjFObt7pb+uL7/4mtbnQXOucSmWNXe5UP/lCEA/KB Tv7hrnrjXYQ9wN+hJZTom2IIlbGGisioVIMhdaBuXWg/9ipf5il0lSWEuaOzM1+ix+n53TY70iP 2D36A18g6kwDg= X-Received: by 2002:a05:6a00:348f:b0:88d:3f61:20e9 with SMTP id d2e1a72fcca58-8c87d124ee2mr28118385b3a.48.1796096962551; Mon, 30 Nov 2026 19:49:22 -0800 (PST) Return-Path: Received: from localhost (c-24-20-171-118.hsd1.or.comcast.net. [24.20.171.118]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c873c1cfafsm19178575b3a.50.2026.11.30.19.49.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:49:22 -0800 (PST) From: Tim Orling To: openembedded-core@lists.openembedded.org Cc: Tim Orling , Bruce Ashfield Subject: [PATCH 4/7] go-mod-update-modules: identify licenses with licensecheck Date: Mon, 30 Nov 2026 19:49:07 -0800 Message-ID: <20261201034910.25521-5-tim.orling@konsulko.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201034910.25521-1-tim.orling@konsulko.com> References: <20261201034910.25521-1-tim.orling@konsulko.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 03:49:30 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251660 A hash finds a license only when the text matches common-licenses, and only one license per file. Go modules often ship a variant of a license text, or several licenses in one file, which become spdx=Unknown and need a line each in license-hashes.csv. Add GO_MOD_LICENSE_SCANNER. Set to "licensecheck", do_update_modules scans each license file with licensecheck-native and: - uses an SPDX-License-Identifier line as it is - otherwise declares every license found that has a text in COMMON_LICENSE_DIR or LICENSE_PATH, with -only or -or-later for the GNU licenses - joins them with OR only when the file offers a choice and they cover at least 80% of it, and with AND otherwise - names a public domain dedication LicenseRef-PD - warns when it finds less than the hash match - leaves out files such as COPYRIGHT or NOTICE that add no license to the ones that the module's other license files declare AI-Generated: Claude Opus 5.5 Signed-off-by: Tim Orling --- .../go-mod-update-modules.bbclass | 43 +++++++++ meta/lib/oe/license_finder.py | 93 +++++++++++++++++++ 2 files changed, 136 insertions(+) diff --git a/meta/classes-recipe/go-mod-update-modules.bbclass b/meta/classes-recipe/go-mod-update-modules.bbclass index fc618dd750..bcb80e130d 100644 --- a/meta/classes-recipe/go-mod-update-modules.bbclass +++ b/meta/classes-recipe/go-mod-update-modules.bbclass @@ -12,6 +12,13 @@ do_update_modules[network] = "1" # # These files are machine-generated and should not be modified. +# Set to "licensecheck" to identify the licenses with licensecheck-native, the +# license detection that pkg.go.dev uses. It finds every license in a file, +# also when a file holds several, and texts that differ from the ones in +# common-licenses. +GO_MOD_LICENSE_SCANNER ??= "" +do_update_modules[depends] += "${@'licensecheck-native:do_populate_sysroot' if d.getVar('GO_MOD_LICENSE_SCANNER') == 'licensecheck' else ''}" + python do_update_modules() { import subprocess, tempfile, json, re, urllib.parse from oe.license_finder import find_licenses_up @@ -77,6 +84,42 @@ python do_update_modules() { for node, file, md5 in find_licenses_up(pkg_dir, mod_dir, d, first_only=True, extra_hashes=extra_hashes): lic_files[os.path.join(path, file)] = (node, md5) + scanner = d.getVar("GO_MOD_LICENSE_SCANNER") + if scanner not in ("", "licensecheck"): + bb.fatal(f"GO_MOD_LICENSE_SCANNER: unsupported value {scanner!r}") + if scanner: + from oe.license_finder import scan_licenses + tool = os.path.join(d.getVar("STAGING_BINDIR_NATIVE"), "licensecheck") + scanned = scan_licenses([os.path.join(mod_cache_dir, f) for f in lic_files], tool, d) + found_ids = {} + for lic_file, (node, md5) in list(lic_files.items()): + new, ids = scanned[os.path.join(mod_cache_dir, lic_file)] + found_ids[lic_file] = ids + if new is None: + continue + if not isinstance(node, oe.spdx_license.UnknownId): + old = {i.to_string() for i in node.iter() if isinstance(i, oe.spdx_license.LicenseId)} + if not old <= ids: + bb.warn(f"{lic_file}: the hash matches {node.to_string()}, licensecheck finds {new.to_string()}") + lic_files[lic_file] = (new, md5) + + # Files such as COPYRIGHT or NOTICE next to the license files often + # hold no license text. Leave out a file that is not identified when + # the other license files of its module declare every license that + # licensecheck finds in it, so that no license is left out. + for lic_file, (node, md5) in list(lic_files.items()): + if not isinstance(node, oe.spdx_license.UnknownId): + continue + licdir = os.path.dirname(lic_file) + declared = set() + for other, (onode, _) in lic_files.items(): + if other != lic_file and os.path.dirname(other) == licdir \ + and not isinstance(onode, oe.spdx_license.UnknownId): + declared |= {i.to_string() for i in onode.iter() if isinstance(i, oe.spdx_license.LicenseId)} + if declared and found_ids[lic_file] <= declared: + bb.note(f"{lic_file}: no license beyond {' '.join(sorted(declared))}, left out") + del lic_files[lic_file] + licenses = [] lic_files_chksum = [] for lic_file in lic_files: diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py index cd290adf59..e8e44dab4a 100644 --- a/meta/lib/oe/license_finder.py +++ b/meta/lib/oe/license_finder.py @@ -218,3 +218,96 @@ def find_licenses(srctree, d, first_only=False, extra_hashes={}): def find_licenses_up(srcdir, topdir, d, first_only=False, extra_hashes={}): licfiles = find_license_files(topdir, first_only, srcdir) return match_licenses(licfiles, topdir, d, extra_hashes) + + +# licensecheck still uses SPDX's deprecated GNU identifiers +_DEPRECATED_GNU = {'GPL-1.0', 'GPL-2.0', 'GPL-3.0', 'LGPL-2.0', 'LGPL-2.1', 'LGPL-3.0', + 'AGPL-1.0', 'AGPL-3.0', 'GFDL-1.1', 'GFDL-1.2', 'GFDL-1.3'} +_LATER_RE = re.compile(r'(or|\(at\s+your\s+option\))\s+any\s+later\s+version', re.I) +# A choice between licenses, not GPL's "at your option, any later version" +_CHOICE_RE = re.compile(r'at\s+your\s+option,?\s+(under\s+)?either|dual[-\s]licen[sc]ed|' + r'licensed\s+under\s+either|you\s+(may|can)\s+choose\s+(either|between)', re.I) +_PUBLIC_DOMAIN_RE = re.compile(r'(dedicated|released|put|placed)\s+(in)?to\s+the\s+public\s+domain', re.I) +_SPDX_HEADER_RE = re.compile(r'SPDX-License-Identifier:\s*([^\s`*][^\n`*]*)') + + +def _available_licenses(d): + lic_dirs = [d.getVar('COMMON_LICENSE_DIR')] + (d.getVar('LICENSE_PATH') or "").split() + return {fn for lic_dir in lic_dirs if os.path.isdir(lic_dir) for fn in os.listdir(lic_dir)} + + +def _licensecheck_expression(result, text, available, min_percent): + """Turn one licensecheck result into an SPDX expression, or None.""" + ids = [] + for m in result.get('matches', []): + if m.get('url'): + continue + ident = m['id'] + if ident in _DEPRECATED_GNU: + near = text[m['start']:m['end'] + 2000] + later = _LATER_RE.search(near) or _LATER_RE.search(text[:2000]) + ident += '-or-later' if later else '-only' + if ident not in ids: + ids.append(ident) + if not ids or any(i not in available for i in ids): + return None, set(ids) + # A match is a complete license text, even when other text lowers the + # coverage. Offer a choice only when the licenses cover most of the file. + choice = result.get('percent', 0) >= min_percent and _CHOICE_RE.search(text) + op = ' OR ' if len(ids) > 1 and choice else ' AND ' + return op.join(sorted(ids)), set(ids) + + +def scan_licenses(paths, licensecheck, d, min_percent=80.0): + """ + Identify the licenses in files with the licensecheck tool. + + Returns a dict that maps each path to (node, ids): node is an + oe.spdx_license node, or None when the licenses in the file are not + identified with confidence; ids is the set of license identifiers that + were found, also when node is None. + + An SPDX-License-Identifier line is used as it is. Otherwise every + license that licensecheck finds is used, if each one has a text in + COMMON_LICENSE_DIR or LICENSE_PATH. The licenses are joined with OR when + they cover at least min_percent of the file and the file offers a choice + between them, and with AND otherwise. A file without a license that only + dedicates the code to the public domain is LicenseRef-PD. + """ + import json + import subprocess + + available = _available_licenses(d) + results = {} + paths = list(paths) + for i in range(0, len(paths), 200): + chunk = paths[i:i + 200] + output = subprocess.check_output([licensecheck] + chunk, text=True) + for line in output.splitlines(): + r = json.loads(line) + results[r['file']] = r + + scanned = {} + for path in paths: + with open(path, 'r', errors='replace') as f: + text = f.read() + node = None + header = _SPDX_HEADER_RE.search(text) + expr = header.group(1).strip() if header else None + ids = set(re.findall(r'[A-Za-z0-9.+-]+', expr)) - {'AND', 'OR', 'WITH'} if expr else set() + # Use the header only when each license has a text; exceptions have none + lics = set(re.findall(r'[A-Za-z0-9.+-]+', re.sub(r'\bWITH\s+\S+', '', expr or ''))) - {'AND', 'OR'} + if not expr or any(i not in available for i in lics): + expr, ids = _licensecheck_expression(results.get(path, {}), text, available, min_percent) + if not ids and _PUBLIC_DOMAIN_RE.search(text): + expr, ids = 'LicenseRef-PD', {'LicenseRef-PD'} + if expr: + try: + node = oe.spdx_license.parse(expr) + except oe.spdx_license.ParseError: + node = None + if node is not None and any( + isinstance(n, oe.spdx_license.LicenseId) and n.deprecated for n in node.iter()): + node = None + scanned[path] = (node, ids) + return scanned From patchwork Tue Dec 1 03:49:08 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 106686 Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.4082.1796096965042216298 for ; Mon, 30 Nov 2026 19:49:25 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=GJP0yIjL; spf=pass (domain: konsulko.com, ip: 209.85.214.169, mailfrom: tim.orling@konsulko.com) Received: by mail-pl1-f169.google.com with SMTP id d9443c01a7336-2f0414c1062so67094505ad.2 for ; Mon, 30 Nov 2026 19:49:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1796096964; x=1796701764; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=eT7FnU6d9ac93qKLpEsYnpi8A1FUUv1QyvlAKsf3deM=; b=GJP0yIjLFGv/IrRx+CzicVowE44Y4EjSp42azDCFdbD89xuNtUxkHSGL7973rPSszL PcYaXjVKPhaARJcCruPbjaCPWayQGI4Hl2dh4EniaD41Q4S2TD3c/b7CCWiNt1viDWU/ 5D2yFPj/cet9XLzFtBWakRx8NT3R8YzdNYArM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096964; x=1796701764; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=eT7FnU6d9ac93qKLpEsYnpi8A1FUUv1QyvlAKsf3deM=; b=IdBWwt/07Tv056eUspsrTh9jmUztbU7z0eYTKTOinaazWOixZypHIWQWQdQEzNmgSs hXHPkPysL41RHlJ0rPt0cZGiEbB3x/IRz7sq5JRJn9mGAtbDiMQoeZevbzvqxi0yMsCk SMrnjwUZiKdy0L1/oPAuEEnFYZ0FJkoyLvTbnYuVJ+pdhgpBw2ZuDVobhKoZTCA4moXp XKt/a8lb6T37rtqGC5oIxFedri22ZX3upmiwaAAJlV3Bf8dwCcP+wdoCd0B28szGRcXw eZfoKeP3g7HKSUNLmo3lo20ov4kRBrDRScuDJ2Q3e96VsXUVtPymobiyTTRut2Zj9Xnj ohyg== X-Gm-Message-State: APuU4Z//4gZnUuTR+nXrGelEapJuJZ3184cALQkhxOguX1ADoIrnuhmL /e1Iy8J7wFgopN/m4E9ruHpCVZ5iP26JTsNC4bWhKd8cP89JU7hEsM1O2/nV396ABPCgCU6de1D EbsRXvNw= X-Gm-Gg: AZFdTZdq3OVlUNN6j3Kc4w9XtrH4IQG/sE/WxbxC4Z//lE1Zadku5urfK5vsOqJOmw1 /9vX6m9XAv+xY7mdlKJjQ57l22gENkArsIJoIBkV+tBNfVF1BzWdT1LOLukNq/vpl89qYHQmXWk 8iQVu8sef3NWOzA9MuMLuBqAe4fuYEx9CIMXrmE1tCCj22JhfpeDns9JCBFuzHR7WrSallmJIP0 lXXDwsY64CYyWJjUvJox4XSFcj+kQtCBYfkpsb8E0c0530pYWF4JR96/A5TcrHwSpawdtHfvjUt sJkZuP3ToegGUof3rzWDlJCKzvZWahTgxtcHLZlw9gbRs+1VmblRCJPWPnVLWIWTv+hWqG99YGA iD+58v80ZChrUGEl5UZkOUSWFrgR5NFgoXSAm8S+wNe3qTAWtDLF/cjH6saZsKY3KJUmU557zz8 r5R+RCd+Cdo++/c4u2Z33qzq2lFXI6fZLGPAf5fLvX/D4G6sE4FMeyToIq/+zy2+0S8Jj9WOndg ga/IFlp1ivb+/D+RIvBAm+oYqJBX1zz2KSMoBVTMrJDqpdr2b8Pm/8/1Vs9Ie6Tu27QsYbkf45g sxqhIWafUJaQGzYXKKU1A25dYrvYIla9cIJkksiAUDYMFu8H8frgGJ2IAvIBdSZxSXfOvnnuTK/ VlHN/Z9H2O9C6TpHhctQx3nU1TY2aC3bYKOP4UM8kNkRO03/5x39ZE5PDnr5EFEQ9lbLjnD6w/i DvgxppfskMyCs= X-Received: by 2002:a17:902:ec8b:b0:2e9:7ff5:5462 with SMTP id d9443c01a7336-2f03f1187f6mr308642215ad.22.1796096964436; Mon, 30 Nov 2026 19:49:24 -0800 (PST) Return-Path: Received: from localhost (c-24-20-171-118.hsd1.or.comcast.net. [24.20.171.118]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f0742996aesm143935145ad.11.2026.11.30.19.49.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:49:24 -0800 (PST) From: Tim Orling To: openembedded-core@lists.openembedded.org Cc: Tim Orling , Bruce Ashfield Subject: [PATCH 5/7] go-mod-update-modules: add GO_MOD_LICENSE_STRICT Date: Mon, 30 Nov 2026 19:49:08 -0800 Message-ID: <20261201034910.25521-6-tim.orling@konsulko.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201034910.25521-1-tim.orling@konsulko.com> References: <20261201034910.25521-1-tim.orling@konsulko.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 03:49:31 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251661 A license file that is not identified only gives a warning, which is easy to miss in an upgrade. Add GO_MOD_LICENSE_STRICT. Set to "1", do_update_modules fails without writing the files, and lists the unidentified files and the md5,SPDX lines to complete and add to a license-hashes.csv. AI-Generated: Claude Opus 5.5 Signed-off-by: Tim Orling --- meta/classes-recipe/go-mod-update-modules.bbclass | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/meta/classes-recipe/go-mod-update-modules.bbclass b/meta/classes-recipe/go-mod-update-modules.bbclass index bcb80e130d..030099fb0f 100644 --- a/meta/classes-recipe/go-mod-update-modules.bbclass +++ b/meta/classes-recipe/go-mod-update-modules.bbclass @@ -19,6 +19,10 @@ do_update_modules[network] = "1" GO_MOD_LICENSE_SCANNER ??= "" do_update_modules[depends] += "${@'licensecheck-native:do_populate_sysroot' if d.getVar('GO_MOD_LICENSE_SCANNER') == 'licensecheck' else ''}" +# Set to "1" to fail, without writing the files, when the license of a file is +# not identified. The error lists the hashes to add to a license-hashes.csv. +GO_MOD_LICENSE_STRICT ??= "0" + python do_update_modules() { import subprocess, tempfile, json, re, urllib.parse from oe.license_finder import find_licenses_up @@ -120,6 +124,15 @@ python do_update_modules() { bb.note(f"{lic_file}: no license beyond {' '.join(sorted(declared))}, left out") del lic_files[lic_file] + unknown = [(f, md5) for f, (node, md5) in lic_files.items() + if isinstance(node, oe.spdx_license.UnknownId)] + if unknown and bb.utils.to_boolean(d.getVar("GO_MOD_LICENSE_STRICT")): + bb.fatal("Licenses not identified, %s-licenses.inc not written:\n%s\n" + "Once each license is verified, add md5,SPDX lines like these to a " + "files/license-hashes.csv in a layer:\n%s" % ( + bpn, "\n".join(f" {f}" for f, _ in unknown), + "\n".join(sorted({f" {md5},Unknown" for _, md5 in unknown})))) + licenses = [] lic_files_chksum = [] for lic_file in lic_files: From patchwork Tue Dec 1 03:49:09 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 106687 Received: from mail-pf1-f180.google.com (mail-pf1-f180.google.com [209.85.210.180]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.4083.1796096967018826951 for ; Mon, 30 Nov 2026 19:49:27 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=J4FSiWNZ; spf=pass (domain: konsulko.com, ip: 209.85.210.180, mailfrom: tim.orling@konsulko.com) Received: by mail-pf1-f180.google.com with SMTP id d2e1a72fcca58-8b5c3288e6cso4442805b3a.3 for ; Mon, 30 Nov 2026 19:49:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1796096966; x=1796701766; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=dkPBzj0C5i9zpMG12KsJkIl2Msqcd9st4uQS9CT4l5I=; b=J4FSiWNZVWaA+SIZvO85oj0AdrDrMVL4vACTeGKFVU84c1F2PwaAXo3My8cLimBfMP PRoLxlIbiqaWdKOnZIR0+2Ou+NfmU9j+vGns/QeKin3nGYUuRbrKkZcG6cdE8AycMl98 s03NSYlmch/te9XrnAKiGilU0mdR7cr76aifs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096966; x=1796701766; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=dkPBzj0C5i9zpMG12KsJkIl2Msqcd9st4uQS9CT4l5I=; b=tlhpZdQ2rVmQfUHmhSS8mhe/4z3cjyA5cST4sI2bv2YslHxEEWHjaaMLkOU4S+oBfK kkrYVrcr+dTDlhnS4hI2MLlKTsoiT1DXlfrGMrY1TCQwvzIrvKkJGXtoK3+qldAJXiPo 0admHagkswkR63IoCLjcIiUjdaZUiTl8YYzNJqCvCYMuoV9ejnlKYEOJYCGeTi/+nUDS NgQKy5dAY5VlOUdKeQnjFak1QWfdSsoerj+LJ5CbKwpYcd95I0DfJOqmluYQLGwlyW2w 53FMFQXiVRsXg9V87l/Kz5V+NRKemC+Gl/iUTGG6dOb8DsOh4l6xrb9dyEPbHA9NDyXJ jdQQ== X-Gm-Message-State: APuU4Z/3AxDWBbiVS9rpN8a0fG9oaBYmq2MZMqu/b9q/iDyxeLCWpTVx ng6LiZR5mE6K7+mNwggWSUKHwdORS8XKq/KQ/iDLvkSeATpZ20lf4gK8hhzuBT7Z/jwvuT4uHkL EOqmGvBI= X-Gm-Gg: AZFdTZdb+rHQ+VulRSdTIURAu6VLtJOJNBtbuk7gBoNOBvjlGyG5nyl0b9tOKy6MUpX PQQ6V1idJ8BaXCY3dMetLxrQf/SveGzgSzSbKBmxk6vvBmS7i0HymmlErxlFhgpzHHonuK6xBq+ Wi5nn/bQJwGKEqtOrEDD/IzpKNlRtkmvBvfP+qgiyGRNu/zL/L2WAi6kIE0MTVkhSQ+pAfWW8Il k5HQfxwNE2MDY43zK4N/4BrybQKZLKmSlNEiN0p2pgJqEhzgNmRtuzeW0m0VxCJuRp3lT3//AiG a36YjWS2AvaQLXjb7z5JIhheONCycQEl8sJlF03o9CHaAJga7TEcT2PPzuBMHrbBCJNYqf2s1cM McFQ5E/fi73g5i8gEp58O7rfNVw4SzamjiqysygT6cGXGdjh3u9O0ftT3mVs7N647P1wnJEjqWV pfPkwr83GBuCwy9mnS/7E83MK6oOcYTyQYpw1spSmvsEplm1cw8Nd9G2l8k4uWoZ9myaez+tuvz GjtGFGVTDu6jJd8rLpSD/0CBtUiWiYEaMcqIYQ1LnJ5YxPKsV1xcm1JHWTLhG8aD7mNWSuAjo/N JoznJQI+js/YRUjFMSm+OU8gQX6s2klDUXhdSTv3X9qMMUpDu1xNOsO7mrEaGS25USRT966gRT1 braJJ4IKU7zMnyobEsSkj5aQn4lyudKIk25B/9oJnx2WLcIPMQxp2u0Vu/2B/iQ/5H3U= X-Received: by 2002:a05:6300:8052:b0:3e2:827c:2fe2 with SMTP id adf61e73a8af0-4014a470489mr34459981637.1.1796096966424; Mon, 30 Nov 2026 19:49:26 -0800 (PST) Return-Path: Received: from localhost (c-24-20-171-118.hsd1.or.comcast.net. [24.20.171.118]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-8c87353b333sm18709196b3a.40.2026.11.30.19.49.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:49:26 -0800 (PST) From: Tim Orling To: openembedded-core@lists.openembedded.org Cc: Tim Orling , Bruce Ashfield Subject: [PATCH 6/7] go-mod-update-modules: name unidentified licenses with a LicenseRef Date: Mon, 30 Nov 2026 19:49:09 -0800 Message-ID: <20261201034910.25521-7-tim.orling@konsulko.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201034910.25521-1-tim.orling@konsulko.com> References: <20261201034910.25521-1-tim.orling@konsulko.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 03:49:31 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251662 A license file that is not identified was written as "Unknown", which has no license text, so do_populate_lic failed. Name it LicenseRef-go--, warn, and point NO_GENERIC_LICENSE at the module's own text, so that the recipe builds and its SBOM names the file. GO_MOD_LICENSE_STRICT still fails first. AI-Generated: Claude Opus 5.5 Signed-off-by: Tim Orling --- .../go-mod-update-modules.bbclass | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/meta/classes-recipe/go-mod-update-modules.bbclass b/meta/classes-recipe/go-mod-update-modules.bbclass index 030099fb0f..9ec41c7b57 100644 --- a/meta/classes-recipe/go-mod-update-modules.bbclass +++ b/meta/classes-recipe/go-mod-update-modules.bbclass @@ -133,13 +133,31 @@ python do_update_modules() { bpn, "\n".join(f" {f}" for f, _ in unknown), "\n".join(sorted({f" {md5},Unknown" for _, md5 in unknown})))) + # Name a license that is not identified LicenseRef-go--, + # with NO_GENERIC_LICENSE pointing at the module's own text, as + # "Unknown" has no text and would fail do_populate_lic. + for lic_file, (node, md5) in list(lic_files.items()): + if not isinstance(node, oe.spdx_license.UnknownId): + continue + module, _, rest = lic_file.partition('@') + in_module = rest.partition('/')[2] + name = re.sub(r'[^A-Za-z0-9.-]+', '-', f"go-{unescape_path(module)}-{in_module}").strip('-') + node = oe.spdx_license.parse("LicenseRef-" + name) + bb.warn(f"{lic_file}: license not identified, using its own text as {node.to_string()}") + lic_files[lic_file] = (node, md5) + + lic_dirs = [d.getVar("COMMON_LICENSE_DIR")] + (d.getVar("LICENSE_PATH") or "").split() + no_generic = {} + for lic_file, (node, _) in lic_files.items(): + for ref in node.iter(): + if isinstance(ref, oe.spdx_license.LicenseRef) and not any( + os.path.isfile(os.path.join(ld, n)) for ld in lic_dirs for n in (ref.name, ref.ident)): + no_generic.setdefault(ref.name, f"pkg/mod/{lic_file}") + licenses = [] lic_files_chksum = [] for lic_file in lic_files: node, license_md5 = lic_files[lic_file] - if isinstance(node, oe.spdx_license.UnknownId): - bb.warn(f"Unknown license: {lic_file} {license_md5}") - licenses.append(node) lic_files_chksum.append( f'file://pkg/mod/{lic_file};md5={license_md5};spdx={urllib.parse.quote_plus(node.to_string())}') @@ -156,6 +174,10 @@ python do_update_modules() { for lic in sorted(lic_files_chksum, key=fold_uri): f.write(' ' + lic + ' \\\n') f.write('"\n') + if no_generic: + f.write('\n') + for name in sorted(no_generic): + f.write(f'NO_GENERIC_LICENSE[{name}] = "{no_generic[name]}"\n') # # Sources From patchwork Tue Dec 1 03:49:10 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tim Orling X-Patchwork-Id: 106688 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by mx.groups.io with SMTP id smtpd.msgproc01-g2.4084.1796096969160428289 for ; Mon, 30 Nov 2026 19:49:29 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@konsulko.com header.s=google header.b=coLGt0oS; spf=pass (domain: konsulko.com, ip: 209.85.214.170, mailfrom: tim.orling@konsulko.com) Received: by mail-pl1-f170.google.com with SMTP id d9443c01a7336-2f0634667aaso43578485ad.0 for ; Mon, 30 Nov 2026 19:49:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=konsulko.com; s=google; t=1796096968; x=1796701768; darn=lists.openembedded.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=vrCW14bAvd4DItom0y9dRhlmuypRJyuTd+Rj7VCJnWk=; b=coLGt0oSMNA7UaY7L+GGU/IewBp9EKe6GFRUH1PqWky9BoM/InAPAZA5WqTaZgK86X eesyAZgiynZYfqifA/nBgeR02EgkzkTn5FzjSgvFN9z8OB9T/60C68VuJ4pfXNl+W22G 1Pv3+27Iqv2p++qH2bQNrZnp2X5ihFwJJBP5k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796096968; x=1796701768; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=vrCW14bAvd4DItom0y9dRhlmuypRJyuTd+Rj7VCJnWk=; b=HEvpiIdz37oEVkOcWNVIQ4fXKTZi2hpuMbFuoceFwt/xkUEDTAU2CRDa3/PLVHW7EN Qr34HArwuZ7iYWN/AW24c6E06cIlJ8zPmkD1vgEvcrBfGVegMRR6SKxTeK1WTtFVECgw VvBqkf3x4x9/ZO36YPpZJGq4A/E8SyDxpc1uc1Ra5o7NrJphMCkemHS0FfLjoJcf7v4W ZYSXw1dtMM7+E6C5JsgNRxFBcJq9+H+emdNMvMNuOJpXA/y7XE/h71iPWUBRJ5ABvh7g mvROce2g3NfV+1nQi0pZNv1RcWm/GcgnEWgUBoGw6DprL8YIp6yKoJCSCgB8GKoneP1s zzNA== X-Gm-Message-State: APuU4Z/HRDAv8+yRwcDAXIKUgYyLChpxTZMYGQHP2W7zxjORotFoa3Zc s3REikgVLxRgEWf42Lfv1MDaBH0To/v/Da9RNXKSfAe9o4WuE5NUdXKAVE8nBR+WFe0fSvr+9ZG qPCgD1hA= X-Gm-Gg: AZFdTZeGkmx6wovcKQAa4s1+cAJBCqkIhY2WHTJZpF42xv1MR2jsdc4jXCleIZy6/Mx IJBwRhFxmxW2nGOo4QgkSgH99hvAYm6g2GOc1LBt9S6iBvbN3FrUzeVj4hnbwali/VCHkOWIjhP 0Zj5EMXqLNN9wew/npQSjSaXdvCg5cqc4eWo3roOj3SmKc31vJNauX7Ip77c+EWVMI4UcYtf493 v6VwPMdvNC36qVPl1u7u8/FInxKZXDqcINHUFdXzyuHGqUk6j3lwcfyPFYQYPNhjxZYlHbXtHwi fAzAxt3zZxOAUTGKfU9AQ2JiqwdZhS4W6EfkcUU0FfuQRRrBhTnLqqa6X6dDfF9gqghUUBs9V7I 90hZNCzzMUJIdvuch+qvoNiKMfyp663MeoBDb+YMJJhOs25A0+fnkXxKKsD0g7PXbXUzrOFm4Bl mQYW5+0fAggnvBDFcTwIWUnoi7NlaTeihRabPT5zEcV08XogIrT+Thd81XuttzyiR5PZ/rkZ4Xd RL4MLpMFG1WfNw+cRqonXBrY8S5Mgga2QUE8tA94tb5huQucXsW74jCLrubjkGoI5snCu75qarg X/ef3drHbGOwLIdopwnloz8jm7u9BAQffGN5oPNKhkXcN3AuYBzxO9l9NmGEq3njULlzuiW++/i B0hrC4KmMkkh/Lhm5lKkYEm6YkxVcwg1HB2we/RW3b0TSlszVGT4IjCRYNp61hGs7Pg== X-Received: by 2002:a17:90b:4490:b0:3b0:a7b5:c044 with SMTP id 98e67ed59e1d1-3b41c7bbef0mr22954130a91.1.1796096968447; Mon, 30 Nov 2026 19:49:28 -0800 (PST) Return-Path: Received: from localhost (c-24-20-171-118.hsd1.or.comcast.net. [24.20.171.118]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b420e1307csm54507177a91.7.2026.11.30.19.49.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Nov 2026 19:49:28 -0800 (PST) From: Tim Orling To: openembedded-core@lists.openembedded.org Cc: Tim Orling , Bruce Ashfield Subject: [PATCH 7/7] oeqa/selftest/oelib: add tests for license_finder Date: Mon, 30 Nov 2026 19:49:10 -0800 Message-ID: <20261201034910.25521-8-tim.orling@konsulko.com> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261201034910.25521-1-tim.orling@konsulko.com> References: <20261201034910.25521-1-tim.orling@konsulko.com> MIME-Version: 1.0 List-Id: X-Webhook-Received: from 45-33-107-173.ip.linodeusercontent.com [45.33.107.173] by lin-tor-korg-lkml-alma10-1 with HTTPS for ; Tue, 01 Dec 2026 03:49:31 -0000 X-Groupsio-URL: https://lists.openembedded.org/g/openembedded-core/message/251663 Cover files without license text, the license files of the nearest directory, and how licensecheck results become SPDX expressions. scan_licenses() is tested with a stand-in for licensecheck, so no build is needed. AI-Generated: Claude Opus 5.5 Signed-off-by: Tim Orling --- .../selftest/cases/oelib/license_finder.py | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 meta/lib/oeqa/selftest/cases/oelib/license_finder.py diff --git a/meta/lib/oeqa/selftest/cases/oelib/license_finder.py b/meta/lib/oeqa/selftest/cases/oelib/license_finder.py new file mode 100644 index 0000000000..866ce8c785 --- /dev/null +++ b/meta/lib/oeqa/selftest/cases/oelib/license_finder.py @@ -0,0 +1,146 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +import json +import os +import stat +import sys +import tempfile +from unittest.case import TestCase + +import oe.license_finder as lf + +COMMON_LICENSE_DIR = os.path.join(os.path.dirname(__file__), "..", "..", "..", "..", "..", + "files", "common-licenses") + + +class Datastore: + """Just enough of a datastore for license_finder.""" + def __init__(self, **values): + self.values = values + + def getVar(self, name, expand=True): + return self.values.get(name) + + def expand(self, s): + return s + + +def datastore(): + return Datastore(COMMON_LICENSE_DIR=os.path.normpath(COMMON_LICENSE_DIR), LICENSE_PATH="", BBPATH="") + + +class TempDirTestCase(TestCase): + def setUp(self): + self.tmp = tempfile.TemporaryDirectory() + self.addCleanup(self.tmp.cleanup) + + def write(self, name, text): + path = os.path.join(self.tmp.name, name) + os.makedirs(os.path.dirname(path), exist_ok=True) + with open(path, "w") as f: + f.write(text) + return path + + +class TestCrunch(TempDirTestCase): + def test_no_license_text(self): + # Only a copyright line, like common-licenses/Proprietary only a title + path = self.write("COPYRIGHT", "Copyright (c) 2026 Example Corp.\nAll rights reserved.\n") + self.assertIsNone(lf._crunch_license(path)) + self.assertIsNone(lf._crunch_license(os.path.join(COMMON_LICENSE_DIR, "Proprietary"))) + self.assertIsNotNone(lf._crunch_license(os.path.join(COMMON_LICENSE_DIR, "MIT"))) + + def test_no_match_on_empty_text(self): + path = self.write("COPYRIGHT", "Copyright (c) 2026 Example Corp.\n") + self.assertNotIn(None, lf._crunch_known_licenses(datastore())) + [(node, _, _)] = lf.match_licenses([path], self.tmp.name, datastore()) + self.assertEqual(node.to_string(), "Unknown") + + +class TestFindLicenseFiles(TempDirTestCase): + def test_nearest_directory(self): + # A module with its own license and one for code taken from Go + self.write("mod/LICENSE", "MIT\n") + self.write("mod/GO_LICENSE", "BSD-3-Clause\n") + self.write("mod/pkg/file.go", "package pkg\n") + top = os.path.join(self.tmp.name, "mod") + found = lf.find_license_files(top, True, os.path.join(top, "pkg")) + self.assertEqual(sorted(os.path.basename(f) for f in found), ["GO_LICENSE", "LICENSE"]) + + def test_nearest_directory_only(self): + self.write("mod/LICENSE", "MIT\n") + self.write("mod/pkg/LICENSE", "BSD-3-Clause\n") + top = os.path.join(self.tmp.name, "mod") + found = lf.find_license_files(top, True, os.path.join(top, "pkg")) + self.assertEqual(found, [os.path.join(top, "pkg", "LICENSE")]) + + +class TestLicensecheckExpression(TestCase): + available = {"Apache-2.0", "BSD-3-Clause", "GPL-2.0-only", "GPL-2.0-or-later", "MIT", "MPL-2.0"} + + def expression(self, percent, ids, text=""): + result = {"percent": percent, + "matches": [{"id": i, "start": 0, "end": len(text)} for i in ids]} + return lf._licensecheck_expression(result, text, self.available, 80.0)[0] + + def test_choice(self): + # As in github.com/spdx/tools-golang, the choice spans two lines + text = ("may be used, at your option,\nunder either:\n* Apache\n" + "* GPL version 2, or (at your option) any later version") + self.assertEqual(self.expression(99, ["Apache-2.0", "GPL-2.0"], text), + "Apache-2.0 OR GPL-2.0-or-later") + + def test_gpl_later_is_no_choice(self): + text = "or (at your option) any later version" + self.assertEqual(self.expression(95, ["MIT", "GPL-2.0"], text), "GPL-2.0-or-later AND MIT") + + def test_gpl_only(self): + self.assertEqual(self.expression(99, ["GPL-2.0"], "version 2 of the License"), "GPL-2.0-only") + + def test_partial_coverage(self): + # A list of third-party licenses: all of them, never a choice + text = "licensed under either of the licenses below" + self.assertEqual(self.expression(74, ["MIT", "Apache-2.0", "MPL-2.0"], text), + "Apache-2.0 AND MIT AND MPL-2.0") + + def test_no_text(self): + self.assertIsNone(self.expression(95, ["Zlib"])) + self.assertIsNone(self.expression(0, [])) + + def test_urls_are_not_licenses(self): + result = {"percent": 90, "matches": [{"id": "MIT", "start": 0, "end": 10, "url": True}]} + self.assertIsNone(lf._licensecheck_expression(result, "", self.available, 80.0)[0]) + + +class TestScanLicenses(TempDirTestCase): + def licensecheck(self): + """A licensecheck that finds nothing, as for texts it does not know.""" + path = self.write("licensecheck", "#!%s\nimport json, sys\n" + "for f in sys.argv[1:]:\n" + " print(json.dumps({'file': f, 'percent': 0, 'matches': []}))\n" + % sys.executable) + os.chmod(path, os.stat(path).st_mode | stat.S_IXUSR) + return path + + def scan(self, text): + path = self.write("LICENSE", text) + node, _ = lf.scan_licenses([path], self.licensecheck(), datastore())[path] + return node.to_string() if node else None + + def test_spdx_header(self): + self.assertEqual(self.scan("SPDX-License-Identifier: Apache-2.0 OR MIT\n"), "Apache-2.0 OR MIT") + self.assertEqual(self.scan("`SPDX-License-Identifier: MPL-2.0 AND BSD-3-Clause`\n"), + "MPL-2.0 AND BSD-3-Clause") + + def test_public_domain(self): + self.assertEqual(self.scan("All of the code has been dedicated to the public domain.\n"), + "LicenseRef-PD") + self.assertEqual(self.scan("All these files have been put\ninto the public domain.\n"), + "LicenseRef-PD") + + def test_unknown(self): + self.assertIsNone(self.scan("Copyright (c) Example. See LICENSE for the full license text.\n"))