From nobody Sun May 5 23:21:23 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+60752+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60752+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1591348907; cv=none; d=zohomail.com; s=zohoarc; b=fOmtEPTlG1NG1BsmpBIBYfbvEZF6WlpEjF0k3jvbUVZWe30Kn3q+/P0HNTXy7m8btSICJRzhjnHb8eiHSC2SCxoQYXSXyhVYbZXr3nN73IWqI4FAHxAvDdRrQ4AlICOAnpDuH3IUa0zZdeyhj1J4DyA43fZfvQ0rm0VCMJbTUpI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1591348907; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=fi3Z4AYMQYidbCHIt19M8tJHTv/Q38Y5uFJ1syQzAOg=; b=i6FsfyBSzPMnanCfV5jN57b2PAd/JPsLCGZHBvAuawj+Q66JOZUn/HcmFav16W1SN3S3eRRQap775pb9BuwDbdGaz4GsiClHcBrjvt2G3gFi5fVLf5JQPZOp/VwUI1YAE5bRGYZn9eOkfY9Ygsr2JY9ri+RJWyzZnnccK4EdHvA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+60752+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 159134890746837.350254778334374; Fri, 5 Jun 2020 02:21:47 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 2EXMYY1788612xxeMh0krNFC; Fri, 05 Jun 2020 02:21:47 -0700 X-Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by mx.groups.io with SMTP id smtpd.web10.7124.1591348906650058096 for ; Fri, 05 Jun 2020 02:21:46 -0700 IronPort-SDR: PsYkp/ZTZxWRFGoc6jajaxPFlCqP6WzKidUSBUG1uzsjusLZ3yQ4bTstcFIHKdgjjDQPJ1M7e4 mh2DeIRVDl/Q== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 05 Jun 2020 02:21:45 -0700 IronPort-SDR: PfKrel77TFCC7wKYuObklNYfFo2mJm+ak00tF+8kQle53NoThT9LzyAeijGI+RFCvl5W3jj55s tBocBT19uHFA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,475,1583222400"; d="scan'208";a="471849758" X-Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by fmsmga005.fm.intel.com with ESMTP; 05 Jun 2020 02:21:44 -0700 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao Subject: [edk2-devel] [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck Date: Fri, 5 Jun 2020 17:21:38 +0800 Message-Id: <20200605092138.32660-1-shenglei.zhang@intel.com> Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,shenglei.zhang@intel.com X-Gm-Message-State: JyJlzEHPOWHroDsFXXgdWh8rx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1591348907; bh=bOutmlfK18FUe5UQk9hH5PA3xIsyt0fikRUPnCQdeSU=; h=Cc:Date:From:Reply-To:Subject:To; b=BBiwvLeDQ7pJ/+Tx+Q1oFY9FramFnaqAQ/9gfs1fiC31+y8kEPgp8fZ946hc6rHaL8v jTQxhgDJ0N76bBC7WKS2dm8vw+SG9WhMvWNIaK2hoshDhffOhTM1TDaCl79uIeDsciA/M M9RShf5uZHDu7XzG9vBqQxM7l+UnC58XPvE= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2691 For files to be added to the tree, this feature will check whether it has BSD plus patent license. If not, licenses listed in Readme are also accepted but warning will be reported. Otherwise, it should be error. Cc: Bob Feng Cc: Liming Gao Signed-off-by: Shenglei Zhang Reviewed-by: Liming Gao Reviewed-by: Yuwei Chen --- v2: Update handling methods for different licenses. v3: Change the position of LicenseCheck(). No functional update. v4: Extend the scope of file types to scan. BaseTools/Scripts/PatchCheck.py | 50 +++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck= .py index 13da6967785d..106b434c750d 100755 --- a/BaseTools/Scripts/PatchCheck.py +++ b/BaseTools/Scripts/PatchCheck.py @@ -304,12 +304,49 @@ class GitDiffCheck: self.line_num =3D 0 self.state =3D START self.new_bin =3D [] + self.LicenseCheck(self.lines, self.count) while self.line_num < self.count and self.format_ok: line_num =3D self.line_num self.run() assert(self.line_num > line_num) self.report_message_result() =20 + def LicenseCheck(self, lines, count): + self.ok =3D True + self.startcheck =3D False + self.license =3D True + line_index =3D 0 + for line in lines: + if line.startswith('--- /dev/null'): + nextline =3D lines[line_index + 1] + added_file =3D self.Readdedfileformat.search(nextline).gro= up(1) + added_file_extension =3D os.path.splitext(added_file)[1] + if added_file_extension in self.file_extension_list: + self.startcheck =3D True + self.license =3D False + if self.startcheck and self.license_format_preflix in line: + if self.bsd2_patent in line or self.bsd3_patent in line: + self.license =3D True + else: + for optional_license in self.license_optional_list: + if optional_license in line: + self.license =3D True + self.warning(added_file) + if line_index + 1 =3D=3D count or lines[line_index + 1].starts= with('diff --') and self.startcheck: + if not self.license: + error_message =3D "Invalid License in: " + added_file + self.error(error_message) + self.startcheck =3D False + self.license =3D True + line_index =3D line_index + 1 + + def warning(self, *err): + count =3D 0 + for line in err: + warning_format =3D 'Warning: License accepted but not BSD plus= patent license in' + print(warning_format, line) + count +=3D 1 + def report_message_result(self): if Verbose.level < Verbose.NORMAL: return @@ -491,6 +528,19 @@ class GitDiffCheck: print(prefix, line) count +=3D 1 =20 + license_format_preflix =3D 'SPDX-License-Identifier' + + bsd2_patent =3D 'BSD-2-Clause-Patent' + + bsd3_patent =3D 'BSD-3-Clause-Patent' + + license_optional_list =3D ['BSD-2-Clause', 'BSD-3-Clause', 'MIT', 'Pyt= hon-2.0', 'Zlib'] + + Readdedfileformat =3D re.compile(r'\+\+\+ b\/(.*)\n') + + file_extension_list =3D [".c", ".h", ".inf", ".dsc", ".dec", ".py", ".= bat", ".sh", ".uni", ".yaml", ".fdf", ".inc", "yml", ".asm", \ + ".asm16", ".asl", ".vfr", ".s", ".S", ".aslc", "= .nasm", ".nasmb", ".idf", ".Vfr", ".H"] + class CheckOnePatch: """Checks the contents of a git email formatted patch. =20 --=20 2.18.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#60752): https://edk2.groups.io/g/devel/message/60752 Mute This Topic: https://groups.io/mt/74689246/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-