From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.9233.1591172845821564055 for ; Wed, 03 Jun 2020 01:27:25 -0700 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: shenglei.zhang@intel.com) IronPort-SDR: yLxGp5HTrPOP6rANIOrTei3z119oysiFG5S8+a+m/++gxK3nlw7SrFyRJ2i6++PWFAu+Lseq/y XCGIRVgj1Bxg== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Jun 2020 01:27:24 -0700 IronPort-SDR: 0HCclXctXoUFS/Cc7DwrOqXjUy4oruEL/7uIbWIVPKZng0m1hg6gR5PfPHYkT7TBaIBcO3bnx3 2MOedhiq6wvg== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,467,1583222400"; d="scan'208";a="470969382" Received: from shenglei-dev.ccr.corp.intel.com ([10.239.158.52]) by fmsmga006.fm.intel.com with ESMTP; 03 Jun 2020 01:27:23 -0700 From: "Zhang, Shenglei" To: devel@edk2.groups.io Cc: Bob Feng , Liming Gao Subject: [PATCH v3] BaseTools/PatchCheck.py: Add LicenseCheck Date: Wed, 3 Jun 2020 16:27:21 +0800 Message-Id: <20200603082721.26752-1-shenglei.zhang@intel.com> X-Mailer: git-send-email 2.18.0.windows.1 REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2691 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 --- v2: Update handling methods for different licenses. v3: Change the position of LicenseCheck(). No functional update. BaseTools/Scripts/PatchCheck.py | 49 +++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py index 13da6967785d..764e66ab7a89 100755 --- a/BaseTools/Scripts/PatchCheck.py +++ b/BaseTools/Scripts/PatchCheck.py @@ -304,12 +304,49 @@ class GitDiffCheck: self.line_num = 0 self.state = START self.new_bin = [] + self.LicenseCheck(self.lines, self.count) while self.line_num < self.count and self.format_ok: line_num = self.line_num self.run() assert(self.line_num > line_num) self.report_message_result() + def LicenseCheck(self, lines, count): + self.ok = True + self.startcheck = False + self.license = True + line_index = 0 + for line in lines: + if line.startswith('--- /dev/null'): + nextline = lines[line_index + 1] + added_file = self.Readdedfileformat.search(nextline).group(1) + added_file_extension = os.path.splitext(added_file)[1] + if added_file_extension in self.file_extension_list: + self.startcheck = True + self.license = 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 = True + else: + for optional_license in self.license_optional_list: + if optional_license in line: + self.license = True + self.warning(added_file) + if line_index + 1 == count or lines[line_index + 1].startswith('diff --') and self.startcheck: + if not self.license: + error_message = "Invalid License in: " + added_file + self.error(error_message) + self.startcheck = False + self.license = True + line_index = line_index + 1 + + def warning(self, *err): + count = 0 + for line in err: + error_format = 'Warning: License accepted but not BSD plus patent license in' + print(error_format, line) + count += 1 + def report_message_result(self): if Verbose.level < Verbose.NORMAL: return @@ -491,6 +528,18 @@ class GitDiffCheck: print(prefix, line) count += 1 + license_format_preflix = 'SPDX-License-Identifier' + + bsd2_patent = 'BSD-2-Clause-Patent' + + bsd3_patent = 'BSD-3-Clause-Patent' + + license_optional_list = ['BSD-2-Clause', 'BSD-3-Clause', 'MIT', 'Python-2.0', 'Zlib'] + + Readdedfileformat = re.compile(r'\+\+\+ b\/(.*)\n') + + file_extension_list = [".c", ".h", ".inf", ".dsc", ".dec", ".py", ".bat", ".sh", ".uni", ".yaml", ".fdf", ".inc"] + class CheckOnePatch: """Checks the contents of a git email formatted patch. -- 2.18.0.windows.1