public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck
@ 2020-06-05  9:21 Zhang, Shenglei
  2020-06-07  6:49 ` Liming Gao
  2020-06-08  0:20 ` [edk2-devel] " Yuwei Chen
  0 siblings, 2 replies; 3+ messages in thread
From: Zhang, Shenglei @ 2020-06-05  9:21 UTC (permalink / raw)
  To: devel; +Cc: Bob Feng, Liming Gao

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 <bob.c.feng@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
---
v2: Update handling methods for different licenses.

v3: Change the position of LicenseCheck(). No functional
    update.

v4: Extend the scope of file types to scan.

 BaseTools/Scripts/PatchCheck.py | 50 +++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py
index 13da6967785d..106b434c750d 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:
+            warning_format = 'Warning: License accepted but not BSD plus patent license in'
+            print(warning_format, line)
+            count += 1
+
     def report_message_result(self):
         if Verbose.level < Verbose.NORMAL:
             return
@@ -491,6 +528,19 @@ 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", "yml", ".asm", \
+                          ".asm16", ".asl", ".vfr", ".s", ".S", ".aslc", ".nasm", ".nasmb", ".idf", ".Vfr", ".H"]
+
 class CheckOnePatch:
     """Checks the contents of a git email formatted patch.
 
-- 
2.18.0.windows.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck
  2020-06-05  9:21 [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck Zhang, Shenglei
@ 2020-06-07  6:49 ` Liming Gao
  2020-06-08  0:20 ` [edk2-devel] " Yuwei Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Liming Gao @ 2020-06-07  6:49 UTC (permalink / raw)
  To: Zhang, Shenglei, devel@edk2.groups.io; +Cc: Feng, Bob C

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Zhang, Shenglei <shenglei.zhang@intel.com>
> Sent: Friday, June 5, 2020 5:22 PM
> To: devel@edk2.groups.io
> Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck
> 
> 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 <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
> v2: Update handling methods for different licenses.
> 
> v3: Change the position of LicenseCheck(). No functional
>     update.
> 
> v4: Extend the scope of file types to scan.
> 
>  BaseTools/Scripts/PatchCheck.py | 50 +++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py
> index 13da6967785d..106b434c750d 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:
> +            warning_format = 'Warning: License accepted but not BSD plus patent license in'
> +            print(warning_format, line)
> +            count += 1
> +
>      def report_message_result(self):
>          if Verbose.level < Verbose.NORMAL:
>              return
> @@ -491,6 +528,19 @@ 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", "yml", ".asm", \
> +                          ".asm16", ".asl", ".vfr", ".s", ".S", ".aslc", ".nasm", ".nasmb", ".idf", ".Vfr", ".H"]
> +
>  class CheckOnePatch:
>      """Checks the contents of a git email formatted patch.
> 
> --
> 2.18.0.windows.1


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [edk2-devel] [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck
  2020-06-05  9:21 [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck Zhang, Shenglei
  2020-06-07  6:49 ` Liming Gao
@ 2020-06-08  0:20 ` Yuwei Chen
  1 sibling, 0 replies; 3+ messages in thread
From: Yuwei Chen @ 2020-06-08  0:20 UTC (permalink / raw)
  To: devel@edk2.groups.io, Zhang, Shenglei; +Cc: Feng, Bob C, Gao, Liming

Reviewed-by: Yuwei Chen <yuwei.chen@intel.com>

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Zhang,
> Shenglei
> Sent: Friday, June 5, 2020 5:22 PM
> To: devel@edk2.groups.io
> Cc: Feng, Bob C <bob.c.feng@intel.com>; Gao, Liming <liming.gao@intel.com>
> Subject: [edk2-devel] [PATCH v4] BaseTools/PatchCheck.py: Add
> LicenseCheck
> 
> 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 <bob.c.feng@intel.com>
> Cc: Liming Gao <liming.gao@intel.com>
> Signed-off-by: Shenglei Zhang <shenglei.zhang@intel.com>
> ---
> v2: Update handling methods for different licenses.
> 
> v3: Change the position of LicenseCheck(). No functional
>     update.
> 
> v4: Extend the scope of file types to scan.
> 
>  BaseTools/Scripts/PatchCheck.py | 50
> +++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/BaseTools/Scripts/PatchCheck.py
> b/BaseTools/Scripts/PatchCheck.py index 13da6967785d..106b434c750d
> 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:
> +            warning_format = 'Warning: License accepted but not BSD plus patent
> license in'
> +            print(warning_format, line)
> +            count += 1
> +
>      def report_message_result(self):
>          if Verbose.level < Verbose.NORMAL:
>              return
> @@ -491,6 +528,19 @@ 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", "yml", ".asm", \
> +                          ".asm16", ".asl", ".vfr", ".s", ".S",
> + ".aslc", ".nasm", ".nasmb", ".idf", ".Vfr", ".H"]
> +
>  class CheckOnePatch:
>      """Checks the contents of a git email formatted patch.
> 
> --
> 2.18.0.windows.1
> 
> 
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-06-08  0:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-05  9:21 [PATCH v4] BaseTools/PatchCheck.py: Add LicenseCheck Zhang, Shenglei
2020-06-07  6:49 ` Liming Gao
2020-06-08  0:20 ` [edk2-devel] " Yuwei Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox