From nobody Mon Feb 9 04:03:39 2026 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+62807+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+62807+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1595234240; cv=none; d=zohomail.com; s=zohoarc; b=eEzvU5BShPAtIITuY07sJgAn5xMa/NufnEN30qFtBxXg/yQacBXyH08mYlmH0njrPlbO6ahR4kJNkdng74bUpYV3NZMOZ8yxP07X2Vgn20i0DKt0blbCF6RrAGSS4HMGODlINTM5egynZB/FalIyMfSdHk2yvdJOw/otEKqCSEM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1595234240; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=GnHt3EgZhl87Z9XrJd3iAWCZtp1RPkxHiLfSnnzZhNk=; b=GXLEoMWpI3YCgrvI6CKScsJYowv/D3tyY7OHzVKWQWNhGFgd5TO0oIAuHRq7H5C2e1dcl8yIG02vrDfamrDAvof2AZtmUwaKX8ZWDwsOBBltAI3x7GbBJZa7r1dwbLozelSYcrrI4pdehwqUJpIBw/cB7+2qpn6PWxFuFCabexU= 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+62807+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 1595234240809761.3994477814107; Mon, 20 Jul 2020 01:37:20 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id iP0eYY1788612xWGWb5cBYYT; Mon, 20 Jul 2020 01:37:20 -0700 X-Received: from mga14.intel.com (mga14.intel.com []) by mx.groups.io with SMTP id smtpd.web11.33610.1595234237313655791 for ; Mon, 20 Jul 2020 01:37:20 -0700 IronPort-SDR: tTotHDbvdQ0hKJiUjxOsp5aYEtCAT2h98r4KvOWMD+r7Tt2LOXd4CMDMsyACLqn+t34Zna9X6U 6kXPjHsRTi1A== X-IronPort-AV: E=McAfee;i="6000,8403,9687"; a="149029425" X-IronPort-AV: E=Sophos;i="5.75,374,1589266800"; d="scan'208";a="149029425" 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 fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Jul 2020 01:37:19 -0700 IronPort-SDR: 9EwL3TLtNUYa4ICC6m4h/pNAoCq/CLSPwUf0XLe0IWocP6V4l9lPCsAeCPLim3NadwSYAnvhok H44+Wy7+0itA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,374,1589266800"; d="scan'208";a="487651345" X-Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by fmsmga005.fm.intel.com with ESMTP; 20 Jul 2020 01:37:18 -0700 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Michael D Kinney , Liming Gao Subject: [edk2-devel] [PATCH 01/15] .pytool/Plugin: Add a plugin LicenseCheck Date: Mon, 20 Jul 2020 16:36:55 +0800 Message-Id: <20200720083709.17264-2-shenglei.zhang@intel.com> In-Reply-To: <20200720083709.17264-1-shenglei.zhang@intel.com> References: <20200720083709.17264-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: atDF1bnToC7F2ZCSXzDdouCax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1595234240; bh=GYplXzBpR6ejC0y3Qk0QimvSAEa/qwhsnXPE6FQRsco=; h=Cc:Date:From:Reply-To:Subject:To; b=Vs/n4FAtgoEKODqt3/xbPsdD/BVNO9ZvUb+lhMsOgQ+aj3QiPQ+oLw8eOSzfpWsls8J Dae1L/tz7/KSAQaeAh2BQVhdxegFIb8saTw+E9cqc1+Sr/MPbAPHo7qlggMhGLFw6lasy BGNIHA/B68f4Xj0jsw8bluDa5KH2sgZxUuo= 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 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2833 Add a plugin to check license conflict for new added files in a patch. It will report out errors when meeting files which are now contributed under BSD-2-Clause-Patent or BSD-3-Clause-Patent. Cc: Sean Brogan Cc: Bret Barkelew Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Shenglei Zhang --- .pytool/Plugin/LicenseCheck/LicenseCheck.py | 118 ++++++++++++++++++ .../LicenseCheck/LicenseCheck_plug_in.yaml | 11 ++ .pytool/Plugin/LicenseCheck/Readme.md | 17 +++ 3 files changed, 146 insertions(+) create mode 100644 .pytool/Plugin/LicenseCheck/LicenseCheck.py create mode 100644 .pytool/Plugin/LicenseCheck/LicenseCheck_plug_in.yaml create mode 100644 .pytool/Plugin/LicenseCheck/Readme.md diff --git a/.pytool/Plugin/LicenseCheck/LicenseCheck.py b/.pytool/Plugin/L= icenseCheck/LicenseCheck.py new file mode 100644 index 000000000000..98941ddda758 --- /dev/null +++ b/.pytool/Plugin/LicenseCheck/LicenseCheck.py @@ -0,0 +1,118 @@ +# @file LicenseCheck.py +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +import os +import logging +import re +from io import StringIO +from typing import List, Tuple +from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPl= ugin +from edk2toolext.environment.var_dict import VarDict +from edk2toollib.utility_functions import RunCmd + + +class LicenseCheck(ICiBuildPlugin): + + """ + A CiBuildPlugin to check the license for new added files. + + Configuration options: + "LicenseCheck": { + "IgnoreFiles": [] + }, + """ + + license_format_preflix =3D 'SPDX-License-Identifier' + + bsd2_patent =3D 'BSD-2-Clause-Patent' + + bsd3_patent =3D 'BSD-3-Clause-Patent' + + Readdedfileformat =3D re.compile(r'\+\+\+ b\/(.*)') + + 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"] + + def GetTestName(self, packagename: str, environment: VarDict) -> tuple: + """ Provide the testcase name and classname for use in reporting + testclassname: a descriptive string for the testcase can inclu= de whitespace + classname: should be patterned .. + + Args: + packagename: string containing name of package to build + environment: The VarDict for the test to run in + Returns: + a tuple containing the testcase name and the classname + (testcasename, classname) + """ + return ("Check for license for " + packagename, packagename + ".Li= censeCheck") + + ## + # External function of plugin. This function is used to perform the t= ask of the ci_build_plugin Plugin + # + # - package is the edk2 path to package. This means workspace/packa= gepath relative. + # - edk2path object configured with workspace and packages path + # - PkgConfig Object (dict) for the pkg + # - EnvConfig Object + # - Plugin Manager Instance + # - Plugin Helper Obj Instance + # - Junit Logger + # - output_stream the StringIO output stream from this plugin via lo= gging + def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environm= ent, PLM, PLMHelper, tc, output_stream=3DNone): + return_buffer =3D StringIO() + params =3D "diff --unified=3D0 origin/master HEAD" + RunCmd("git", params, outstream=3Dreturn_buffer) + p =3D return_buffer.getvalue().strip() + patch =3D p.split("\n") + return_buffer.close() + + ignore_files =3D [] + if "IgnoreFiles" in pkgconfig: + ignore_files =3D pkgconfig["IgnoreFiles"] + + self.ok =3D True + self.startcheck =3D False + self.license =3D True + self.all_file_pass =3D True + count =3D len(patch) + line_index =3D 0 + for line in patch: + if line.startswith('--- /dev/null'): + nextline =3D patch[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 and pa= ckagename in added_file: + if (self.IsIgnoreFile(added_file, ignore_files)): + line_index =3D line_index + 1 + continue + 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 + if line_index + 1 =3D=3D count or patch[line_index + 1].starts= with('diff --') and self.startcheck: + if not self.license: + self.all_file_pass =3D False + error_message =3D "Invalid license in: " + added_file = + " Hint: Only BSD-2-Clause-Patent and" + \ + " BSD-3-Clause-Patent are accepted." + logging.error(error_message) + self.startcheck =3D False + self.license =3D True + line_index =3D line_index + 1 + + if self.all_file_pass: + tc.SetSuccess() + return 0 + else: + tc.SetFailed("License Check {0} Failed. ".format(packagename),= "LICENSE_CHECK_FAILED") + return 1 + + def IsIgnoreFile(self, file: str, ignore_files: List[str]) -> bool: + for f in ignore_files: + if f in file: + return True + return False diff --git a/.pytool/Plugin/LicenseCheck/LicenseCheck_plug_in.yaml b/.pytoo= l/Plugin/LicenseCheck/LicenseCheck_plug_in.yaml new file mode 100644 index 000000000000..1d02f6da5a69 --- /dev/null +++ b/.pytool/Plugin/LicenseCheck/LicenseCheck_plug_in.yaml @@ -0,0 +1,11 @@ +## @file +# CiBuildPlugin used to check license issues for new added files +# +# Copyright (c) Microsoft Corporation. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## +{ + "scope": "cibuild", + "name": "License Check Test", + "module": "LicenseCheck" +} diff --git a/.pytool/Plugin/LicenseCheck/Readme.md b/.pytool/Plugin/License= Check/Readme.md new file mode 100644 index 000000000000..57d9db6769fa --- /dev/null +++ b/.pytool/Plugin/LicenseCheck/Readme.md @@ -0,0 +1,17 @@ +# License Check Plugin + +This CiBuildPlugin scans all new added files in a package to make sure code +is contributed under BSD-2-Clause-Patent or BSD-3-Clause-Patent. + +## Configuration + +The plugin can be configured to ignore certain files. + +``` yaml +"LicenseCheck": { + "IgnoreFiles": [] +} +``` +### IgnoreFiles + +OPTIONAL List of file to ignore. --=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 (#62807): https://edk2.groups.io/g/devel/message/62807 Mute This Topic: https://groups.io/mt/75678209/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-