]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Scripts/PatchCheck.py
BaseTools: Use absolute import in Scripts
[mirror_edk2.git] / BaseTools / Scripts / PatchCheck.py
index 7c3008233c24f07d540e37326f48f79ae8050540..7b7fba8b70445177aa1100b9ffb74b54cd2c0c9f 100755 (executable)
@@ -1,7 +1,7 @@
 ## @file\r
 #  Check a patch for various format issues\r
 #\r
-#  Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>\r
+#  Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.<BR>\r
 #\r
 #  This program and the accompanying materials are licensed and made\r
 #  available under the terms and conditions of the BSD License which\r
@@ -75,10 +75,13 @@ class CommitMessageCheck:
             count += 1\r
 \r
     def check_contributed_under(self):\r
-        cu_msg='Contributed-under: TianoCore Contribution Agreement 1.0'\r
+        cu_msg='Contributed-under: TianoCore Contribution Agreement 1.1'\r
         if self.msg.find(cu_msg) < 0:\r
-            self.error('Missing Contributed-under! (Note: this must be ' +\r
-                       'added by the code contributor!)')\r
+            # Allow 1.0 for now while EDK II community transitions to 1.1\r
+            cu_msg='Contributed-under: TianoCore Contribution Agreement 1.0'\r
+            if self.msg.find(cu_msg) < 0:\r
+                self.error('Missing Contributed-under! (Note: this must be ' +\r
+                           'added by the code contributor!)')\r
 \r
     @staticmethod\r
     def make_signature_re(sig, re_input=False):\r
@@ -243,6 +246,7 @@ class GitDiffCheck:
         self.count = len(self.lines)\r
         self.line_num = 0\r
         self.state = START\r
+        self.new_bin = []\r
         while self.line_num < self.count and self.format_ok:\r
             line_num = self.line_num\r
             self.run()\r
@@ -254,6 +258,11 @@ class GitDiffCheck:
             return\r
         if self.ok:\r
             print('The code passed all checks.')\r
+        if self.new_bin:\r
+            print('\nWARNING - The following binary files will be added ' +\r
+                  'into the repository:')\r
+            for binary in self.new_bin:\r
+                print('  ' + binary)\r
 \r
     def run(self):\r
         line = self.lines[self.line_num]\r
@@ -265,7 +274,7 @@ class GitDiffCheck:
             if line.startswith('@@ '):\r
                 self.state = PRE_PATCH\r
             elif len(line) >= 1 and line[0] not in ' -+' and \\r
-                 not line.startswith(r'\ No newline '):\r
+                 not line.startswith(r'\ No newline ') and not self.binary:\r
                 for line in self.lines[self.line_num + 1:]:\r
                     if line.startswith('diff --git'):\r
                         self.format_error('diff found after end of patch')\r
@@ -276,21 +285,25 @@ class GitDiffCheck:
         if self.state == START:\r
             if line.startswith('diff --git'):\r
                 self.state = PRE_PATCH\r
-                self.set_filename(None)\r
+                self.filename = line[13:].split(' ', 1)[0]\r
+                self.is_newfile = False\r
+                self.force_crlf = not self.filename.endswith('.sh')\r
             elif len(line.rstrip()) != 0:\r
                 self.format_error("didn't find diff command")\r
             self.line_num += 1\r
         elif self.state == PRE_PATCH:\r
-            if line.startswith('+++ b/'):\r
-                self.set_filename(line[6:].rstrip())\r
             if line.startswith('@@ '):\r
                 self.state = PATCH\r
                 self.binary = False\r
-            elif line.startswith('GIT binary patch'):\r
+            elif line.startswith('GIT binary patch') or \\r
+                 line.startswith('Binary files'):\r
                 self.state = PATCH\r
                 self.binary = True\r
+                if self.is_newfile:\r
+                    self.new_bin.append(self.filename)\r
             else:\r
                 ok = False\r
+                self.is_newfile = self.newfile_prefix_re.match(line)\r
                 for pfx in self.pre_patch_prefixes:\r
                     if line.startswith(pfx):\r
                         ok = True\r
@@ -300,7 +313,7 @@ class GitDiffCheck:
         elif self.state == PATCH:\r
             if self.binary:\r
                 pass\r
-            if line.startswith('-'):\r
+            elif line.startswith('-'):\r
                 pass\r
             elif line.startswith('+'):\r
                 self.check_added_line(line[1:])\r
@@ -320,22 +333,20 @@ class GitDiffCheck:
         'new mode ',\r
         'similarity index ',\r
         'rename ',\r
-        'Binary files ',\r
         )\r
 \r
     line_endings = ('\r\n', '\n\r', '\n', '\r')\r
 \r
-    def set_filename(self, filename):\r
-        self.hunk_filename = filename\r
-        if filename:\r
-            self.force_crlf = not filename.endswith('.sh')\r
-        else:\r
-            self.force_crlf = True\r
+    newfile_prefix_re = \\r
+        re.compile(r'''^\r
+                       index\ 0+\.\.\r
+                   ''',\r
+                   re.VERBOSE)\r
 \r
     def added_line_error(self, msg, line):\r
         lines = [ msg ]\r
-        if self.hunk_filename is not None:\r
-            lines.append('File: ' + self.hunk_filename)\r
+        if self.filename is not None:\r
+            lines.append('File: ' + self.filename)\r
         lines.append('Line: ' + line)\r
 \r
         self.error(*lines)\r