From: "Zhang, Shenglei" <shenglei.zhang@intel.com>
To: devel@edk2.groups.io
Cc: Bob Feng <bob.c.feng@intel.com>, Liming Gao <liming.gao@intel.com>
Subject: [PATCH] BaseTools/PatchCheck.py: Add LicenseCheck
Date: Wed, 22 Apr 2020 14:56:55 +0800 [thread overview]
Message-ID: <20200422065655.75392-1-shenglei.zhang@intel.com> (raw)
For files to be added to the tree, this feature will check
whether it has BSD license.
Cc: Bob Feng <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
BaseTools/Scripts/PatchCheck.py | 52 ++++++++++++++++++++++++++++++++-
1 file changed, 51 insertions(+), 1 deletion(-)
diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py
index 13da6967785d..15663d02a3c0 100755
--- a/BaseTools/Scripts/PatchCheck.py
+++ b/BaseTools/Scripts/PatchCheck.py
@@ -491,6 +491,53 @@ class GitDiffCheck:
print(prefix, line)
count += 1
+class LicenseCheck():
+
+ def __init__(self, diff):
+ self.ok = True
+ self.startcheck = False
+ self.license = True
+ lines = diff.splitlines(True)
+ count = len(lines)
+ 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_name in line:
+ self.license = True
+ if line_index + 1 == count or lines[line_index + 1].startswith('diff --') and self.startcheck:
+ if not self.license:
+ self.error(added_file)
+ self.startcheck = False
+ self.license = True
+ line_index = line_index + 1
+
+ def error(self, *err):
+ if self.ok and Verbose.level > Verbose.ONELINE:
+ print('License is missing!')
+ self.ok = False
+ if Verbose.level < Verbose.NORMAL:
+ return
+ count = 0
+ for line in err:
+ prefix = (' *', ' ')[count > 0]
+ error_format = 'Missing license in:'
+ print(prefix, error_format, line)
+ count += 1
+
+
+ license_name = 'BSD-2-Clause-Patent'
+
+ 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.
@@ -508,12 +555,15 @@ class CheckOnePatch:
msg_check = CommitMessageCheck(self.commit_subject, self.commit_msg)
msg_ok = msg_check.ok
+ license_check = LicenseCheck(self.diff)
+ license_ok = license_check.ok
+
diff_ok = True
if self.diff is not None:
diff_check = GitDiffCheck(self.diff)
diff_ok = diff_check.ok
- self.ok = email_ok and msg_ok and diff_ok
+ self.ok = email_ok and msg_ok and diff_ok and license_ok
if Verbose.level == Verbose.ONELINE:
if self.ok:
--
2.18.0.windows.1
next reply other threads:[~2020-04-22 6:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-04-22 6:56 Zhang, Shenglei [this message]
2020-04-22 7:01 ` [PATCH] BaseTools/PatchCheck.py: Add LicenseCheck Liming Gao
2020-04-22 15:41 ` [edk2-devel] " Michael D Kinney
2020-04-22 16:01 ` Liming Gao
2020-04-24 16:13 ` Laszlo Ersek
2020-04-24 16:25 ` Leif Lindholm
[not found] ` <dcfe88b6-f4cf-cea0-ca93-3d5b15548c4f@redhat.com>
2020-04-28 15:01 ` Leif Lindholm
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200422065655.75392-1-shenglei.zhang@intel.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox