From nobody Mon Feb 9 19:08:15 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+63448+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+63448+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1596025699; cv=none; d=zohomail.com; s=zohoarc; b=ay69kvFsfTwsvBExuEqX6/heCl5x2Ts0PWWc8oZHnbrR6uGNxums04k1z5G3nRe6QvLKel2VYfUoMEdvFaambI08yWCzvtpIghdn8+vc68+/pniTHyRDy8XC0TxX2r/BOpo3ghP1c1QsHbbn5bYeDd5y5prcVahTIjhMFiq0nJg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1596025699; h=Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:Message-ID:Reply-To:References:Sender:Subject:To; bh=PlfPduIC7mu3pugw5cxlBRoWQ0XIHB81mvv0AEiJXA8=; b=EJSMitbckw1vyhSnGozoyypjx7eOedbwkptD1m3pclFwFcBTfEwrDFHT3srr7BaX7iiC5LSZkhUh2kGPznxn1J1IBNY+P3oDJ2o0K87XLPY7kNT3AngUsFddz/gunuK2SqrxmQIg32BXECwWNoxaFipnXJsgUO+paPYXPiP4anc= 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+63448+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 1596025698954220.4611931163205; Wed, 29 Jul 2020 05:28:18 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id 4v09YY1788612xyq6QqcxWAL; Wed, 29 Jul 2020 05:28:18 -0700 X-Received: from mga14.intel.com (mga14.intel.com []) by mx.groups.io with SMTP id smtpd.web12.4741.1596025694698132285 for ; Wed, 29 Jul 2020 05:28:17 -0700 IronPort-SDR: 1AUGW+HzWOQtSTiqLBVTQHdXv8I14Q5XlhWXkGPVM3L/7g1HyxTXFeSmyPLLAenDjoERRvkEjM 9hQ4xeRDwhKA== X-IronPort-AV: E=McAfee;i="6000,8403,9696"; a="150571076" X-IronPort-AV: E=Sophos;i="5.75,410,1589266800"; d="scan'208";a="150571076" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 29 Jul 2020 05:28:17 -0700 IronPort-SDR: cS8MGMm9RUY2sdsLU/7TTAf9N5WsEnFiMQyvwW5iznB6tmgClqAFvV2XLnHpxT08tCJiuO5s3L pRrXiXe5rHpw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,410,1589266800"; d="scan'208";a="273872533" X-Received: from shenglei-dev.ccr.corp.intel.com ([10.239.154.36]) by fmsmga008.fm.intel.com with ESMTP; 29 Jul 2020 05:28:15 -0700 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Michael D Kinney , Liming Gao Subject: [edk2-devel] [PATCH v2 01/15] .pytool/Plugin: Add a plugin LicenseCheck Date: Wed, 29 Jul 2020 20:28:06 +0800 Message-Id: <20200729122806.21304-2-shenglei.zhang@intel.com> In-Reply-To: <20200729122806.21304-1-shenglei.zhang@intel.com> References: <20200729122806.21304-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: qfNq6hZgB6dC8fD2UJvSn4pvx1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1596025698; bh=i/O6ieNl+s7gABqvkEcxbdOnfX/dI9jSoi20Vn1/X9Q=; h=Cc:Date:From:Reply-To:Subject:To; b=T6ecyiZFVYR1xD6zLhMcpCCLlw3TmBmQiH+IkAZlsjuIW5LJvTemiO2fUIybXPfB39Y KbV54XWkfiPRXfI6+jRfF9cPqidBc29PygIWIpguao/Ixmu9kz/BcvPOiJETmhtFvrgqR C4n/jheQEu97/vTRar3ivHvt0qlCbvxfJwI= 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. Cc: Sean Brogan Cc: Bret Barkelew Cc: Michael D Kinney Cc: Liming Gao Signed-off-by: Shenglei Zhang --- .pytool/Plugin/LicenseCheck/LicenseCheck.py | 115 ++++++++++++++++++ .../LicenseCheck/LicenseCheck_plug_in.yaml | 11 ++ .pytool/Plugin/LicenseCheck/Readme.md | 17 +++ 3 files changed, 143 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..5733f7bf4ec0 --- /dev/null +++ b/.pytool/Plugin/LicenseCheck/LicenseCheck.py @@ -0,0 +1,115 @@ +# @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' + + 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: + 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 is 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..2fdb0aa72359 --- /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) 2020, Intel Corporation. All rights reserved. +# 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..b0e1bbea9e21 --- /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. + +## 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 (#63448): https://edk2.groups.io/g/devel/message/63448 Mute This Topic: https://groups.io/mt/75863476/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-