From nobody Thu May 9 02:08:58 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+59272+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+59272+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1589285169; cv=none; d=zohomail.com; s=zohoarc; b=ZH9cK/xWjzR84e5iUNXx1pCRPhg2CEwg2s4QAnLl8czDotmCP7DtpbUp1SFKSRk7npnqK/hvDymlO84QO7F9nvz1sM1XznTDw8GDpNjnxO/H/YTeDc4axYqRTWaCnbrNi2Z4A/eV/jj5r5UPvzVknCsIcuwkNNAYjo6rw6v4M1I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589285169; h=Cc:Date:From:List-Id:List-Unsubscribe:Message-ID:Reply-To:Sender:Subject:To; bh=+mBnFjsaO65mZtVCyWnLPMLxTGcAX9JbCjV8pvOEIvE=; b=bwheghMJahyEF8wx2clbjmkAFujsK4uIYp5oNxn4xPY0VLQXzG/9eNFBvOpiy0BQBYC62zMS7ogjfcZX+GZN7ixJqQCFjBXsdex+VV/f+HgpPGGgiZjD1uL8/Ta0M68/zL1U6B6kTL7rfr8if3Zf/50/zjyrEO92xJDUFR7HCG8= 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+59272+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 1589285169179887.1423696452739; Tue, 12 May 2020 05:06:09 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id gZfAYY1788612xJIQIuIIQK7; Tue, 12 May 2020 05:06:08 -0700 X-Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by mx.groups.io with SMTP id smtpd.web12.4285.1589285168358538463 for ; Tue, 12 May 2020 05:06:08 -0700 IronPort-SDR: CnU5pA9KdEuZ0uD67FPFkQiubLTpsI9lKrCYjovnA19saChUfqIbwmsfsC8qKzkQqP7Q8lK5U+ ZuImuAxRtTwQ== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 May 2020 05:06:07 -0700 IronPort-SDR: uEH9sCDmTMbinAP9bObpZPzTggBbei5cAxp262v2OYosu6K++jtkbReRt4u02D0S6YStnzX70h kAv1NChweiQg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,383,1583222400"; d="scan'208";a="251445584" X-Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by fmsmga007.fm.intel.com with ESMTP; 12 May 2020 05:06:06 -0700 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao Subject: [edk2-devel] [PATCH v2] BaseTools/PatchCheck.py: Add LicenseCheck Date: Tue, 12 May 2020 20:06:04 +0800 Message-Id: <20200512120604.18244-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: JRqvChAPnSf3oq65ZkYUf216x1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1589285168; bh=4bh5bT6/keG3fVGt0el5XU/acjvDSFWjSLePBmumSnw=; h=Cc:Date:From:Reply-To:Subject:To; b=tRagJT2OOOdc6NLBKAXv3hclfzD68qFgjTDL1Dk4uHFi7tzz2sTShXGDH/+WCN/eQ3A 9edLQY12bP9nTl6m5Oc0ahf3b0BfuZxDnItpVBXvwIHYKmrGJ9/09lQSGtxV1WA5Trk7B OXziLyD7rSbXzSfhHKLJgEM4n8dDgx7c4PA= 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 out. Otherwise, it should be error. Cc: Bob Feng Cc: Liming Gao Signed-off-by: Shenglei Zhang --- v2: Update handling methods for different licenses. BaseTools/Scripts/PatchCheck.py | 71 ++++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck= .py index 13da6967785d..c96009034aa7 100755 --- a/BaseTools/Scripts/PatchCheck.py +++ b/BaseTools/Scripts/PatchCheck.py @@ -491,6 +491,72 @@ class GitDiffCheck: print(prefix, line) count +=3D 1 =20 +class LicenseCheck(): + + def __init__(self, diff): + self.ok =3D True + self.startcheck =3D False + self.license =3D True + lines =3D diff.splitlines(True) + count =3D len(lines) + 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) = =20 + if line_index + 1 =3D=3D count or lines[line_index + 1].starts= with('diff --') and self.startcheck: + if not self.license: + self.error(added_file) + 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: + prefix =3D (' *', ' ')[count > 0] + error_format =3D 'Warning: License accepted but not BSD plus p= atent license in' + print(prefix, error_format, line) + count +=3D 1 + + def error(self, *err): + if self.ok and Verbose.level > Verbose.ONELINE: + print('License error!') + self.ok =3D False + if Verbose.level < Verbose.NORMAL: + return + count =3D 0 + for line in err: + prefix =3D (' *', ' ')[count > 0] + error_format =3D 'No accepted license in:' + print(prefix, error_format, line) + count +=3D 1 + + 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"] + + class CheckOnePatch: """Checks the contents of a git email formatted patch. =20 @@ -508,12 +574,15 @@ class CheckOnePatch: msg_check =3D CommitMessageCheck(self.commit_subject, self.commit_= msg) msg_ok =3D msg_check.ok =20 + license_check =3D LicenseCheck(self.diff) + license_ok =3D license_check.ok + diff_ok =3D True if self.diff is not None: diff_check =3D GitDiffCheck(self.diff) diff_ok =3D diff_check.ok =20 - self.ok =3D email_ok and msg_ok and diff_ok + self.ok =3D email_ok and msg_ok and diff_ok and license_ok =20 if Verbose.level =3D=3D Verbose.ONELINE: if self.ok: --=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 (#59272): https://edk2.groups.io/g/devel/message/59272 Mute This Topic: https://groups.io/mt/74156794/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-