]> git.proxmox.com Git - mirror_edk2.git/commitdiff
BaseTools/PatchCheck.py: Add LicenseCheck
authorShenglei Zhang <shenglei.zhang@intel.com>
Tue, 21 Apr 2020 06:45:02 +0000 (14:45 +0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 12 Jun 2020 06:26:13 +0000 (06:26 +0000)
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>
Reviewed-by: Yuwei Chen <yuwei.chen@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
BaseTools/Scripts/PatchCheck.py

index 13da6967785d45e0ab5186054f14d53682000379..106b434c750d71d8aa1658109f146dc066633c2c 100755 (executable)
@@ -304,12 +304,49 @@ class GitDiffCheck:
         self.line_num = 0\r
         self.state = START\r
         self.new_bin = []\r
+        self.LicenseCheck(self.lines, self.count)\r
         while self.line_num < self.count and self.format_ok:\r
             line_num = self.line_num\r
             self.run()\r
             assert(self.line_num > line_num)\r
         self.report_message_result()\r
 \r
+    def LicenseCheck(self, lines, count):\r
+        self.ok = True\r
+        self.startcheck = False\r
+        self.license = True\r
+        line_index = 0\r
+        for line in lines:\r
+            if line.startswith('--- /dev/null'):\r
+                nextline = lines[line_index + 1]\r
+                added_file = self.Readdedfileformat.search(nextline).group(1)\r
+                added_file_extension = os.path.splitext(added_file)[1]\r
+                if added_file_extension in self.file_extension_list:\r
+                    self.startcheck = True\r
+                    self.license = False\r
+            if self.startcheck and self.license_format_preflix in line:\r
+                if self.bsd2_patent in line or self.bsd3_patent in line:\r
+                    self.license = True\r
+                else:\r
+                    for optional_license in self.license_optional_list:\r
+                        if optional_license in line:\r
+                            self.license = True\r
+                            self.warning(added_file)\r
+            if line_index + 1 == count or lines[line_index + 1].startswith('diff --') and self.startcheck:\r
+                if not self.license:\r
+                    error_message = "Invalid License in: " + added_file\r
+                    self.error(error_message)\r
+                self.startcheck = False\r
+                self.license = True\r
+            line_index = line_index + 1\r
+\r
+    def warning(self, *err):\r
+        count = 0\r
+        for line in err:\r
+            warning_format = 'Warning: License accepted but not BSD plus patent license in'\r
+            print(warning_format, line)\r
+            count += 1\r
+\r
     def report_message_result(self):\r
         if Verbose.level < Verbose.NORMAL:\r
             return\r
@@ -491,6 +528,19 @@ class GitDiffCheck:
             print(prefix, line)\r
             count += 1\r
 \r
+    license_format_preflix = 'SPDX-License-Identifier'\r
+\r
+    bsd2_patent = 'BSD-2-Clause-Patent'\r
+\r
+    bsd3_patent = 'BSD-3-Clause-Patent'\r
+\r
+    license_optional_list = ['BSD-2-Clause', 'BSD-3-Clause', 'MIT', 'Python-2.0', 'Zlib']\r
+\r
+    Readdedfileformat = re.compile(r'\+\+\+ b\/(.*)\n')\r
+\r
+    file_extension_list = [".c", ".h", ".inf", ".dsc", ".dec", ".py", ".bat", ".sh", ".uni", ".yaml", ".fdf", ".inc", "yml", ".asm", \\r
+                          ".asm16", ".asl", ".vfr", ".s", ".S", ".aslc", ".nasm", ".nasmb", ".idf", ".Vfr", ".H"]\r
+\r
 class CheckOnePatch:\r
     """Checks the contents of a git email formatted patch.\r
 \r