X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=BaseTools%2FScripts%2FPatchCheck.py;h=7b7fba8b70445177aa1100b9ffb74b54cd2c0c9f;hp=05f8f6e4078183d1ab5992ade0d03fa48f83930c;hb=2add3cffb075de8a705c9d887dd25624c89d2349;hpb=e709bbb1ce386c7ac4240fae929cacfcc2bfa5a9
diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py
index 05f8f6e407..7b7fba8b70 100755
--- a/BaseTools/Scripts/PatchCheck.py
+++ b/BaseTools/Scripts/PatchCheck.py
@@ -1,7 +1,7 @@
## @file
# Check a patch for various format issues
#
-# Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.
+# Copyright (c) 2015 - 2017, Intel Corporation. All rights reserved.
#
# This program and the accompanying materials are licensed and made
# available under the terms and conditions of the BSD License which
@@ -75,10 +75,13 @@ class CommitMessageCheck:
count += 1
def check_contributed_under(self):
- cu_msg='Contributed-under: TianoCore Contribution Agreement 1.0'
+ cu_msg='Contributed-under: TianoCore Contribution Agreement 1.1'
if self.msg.find(cu_msg) < 0:
- self.error('Missing Contributed-under! (Note: this must be ' +
- 'added by the code contributor!)')
+ # Allow 1.0 for now while EDK II community transitions to 1.1
+ cu_msg='Contributed-under: TianoCore Contribution Agreement 1.0'
+ if self.msg.find(cu_msg) < 0:
+ self.error('Missing Contributed-under! (Note: this must be ' +
+ 'added by the code contributor!)')
@staticmethod
def make_signature_re(sig, re_input=False):
@@ -243,6 +246,7 @@ class GitDiffCheck:
self.count = len(self.lines)
self.line_num = 0
self.state = START
+ self.new_bin = []
while self.line_num < self.count and self.format_ok:
line_num = self.line_num
self.run()
@@ -254,6 +258,11 @@ class GitDiffCheck:
return
if self.ok:
print('The code passed all checks.')
+ if self.new_bin:
+ print('\nWARNING - The following binary files will be added ' +
+ 'into the repository:')
+ for binary in self.new_bin:
+ print(' ' + binary)
def run(self):
line = self.lines[self.line_num]
@@ -265,7 +274,7 @@ class GitDiffCheck:
if line.startswith('@@ '):
self.state = PRE_PATCH
elif len(line) >= 1 and line[0] not in ' -+' and \
- not line.startswith(r'\ No newline '):
+ not line.startswith(r'\ No newline ') and not self.binary:
for line in self.lines[self.line_num + 1:]:
if line.startswith('diff --git'):
self.format_error('diff found after end of patch')
@@ -276,21 +285,25 @@ class GitDiffCheck:
if self.state == START:
if line.startswith('diff --git'):
self.state = PRE_PATCH
- self.set_filename(None)
+ self.filename = line[13:].split(' ', 1)[0]
+ self.is_newfile = False
+ self.force_crlf = not self.filename.endswith('.sh')
elif len(line.rstrip()) != 0:
self.format_error("didn't find diff command")
self.line_num += 1
elif self.state == PRE_PATCH:
- if line.startswith('+++ b/'):
- self.set_filename(line[6:].rstrip())
if line.startswith('@@ '):
self.state = PATCH
self.binary = False
- elif line.startswith('GIT binary patch'):
+ elif line.startswith('GIT binary patch') or \
+ line.startswith('Binary files'):
self.state = PATCH
self.binary = True
+ if self.is_newfile:
+ self.new_bin.append(self.filename)
else:
ok = False
+ self.is_newfile = self.newfile_prefix_re.match(line)
for pfx in self.pre_patch_prefixes:
if line.startswith(pfx):
ok = True
@@ -300,7 +313,7 @@ class GitDiffCheck:
elif self.state == PATCH:
if self.binary:
pass
- if line.startswith('-'):
+ elif line.startswith('-'):
pass
elif line.startswith('+'):
self.check_added_line(line[1:])
@@ -320,26 +333,32 @@ class GitDiffCheck:
'new mode ',
'similarity index ',
'rename ',
- 'Binary files ',
)
line_endings = ('\r\n', '\n\r', '\n', '\r')
- def set_filename(self, filename):
- self.hunk_filename = filename
- if filename:
- self.force_crlf = not filename.endswith('.sh')
- else:
- self.force_crlf = True
+ newfile_prefix_re = \
+ re.compile(r'''^
+ index\ 0+\.\.
+ ''',
+ re.VERBOSE)
def added_line_error(self, msg, line):
lines = [ msg ]
- if self.hunk_filename is not None:
- lines.append('File: ' + self.hunk_filename)
+ if self.filename is not None:
+ lines.append('File: ' + self.filename)
lines.append('Line: ' + line)
self.error(*lines)
+ old_debug_re = \
+ re.compile(r'''
+ DEBUG \s* \( \s* \( \s*
+ (?: DEBUG_[A-Z_]+ \s* \| \s*)*
+ EFI_D_ ([A-Z_]+)
+ ''',
+ re.VERBOSE)
+
def check_added_line(self, line):
eol = ''
for an_eol in self.line_endings:
@@ -357,6 +376,12 @@ class GitDiffCheck:
if len(stripped) < len(line):
self.added_line_error('Trailing whitespace found', line)
+ mo = self.old_debug_re.search(line)
+ if mo is not None:
+ self.added_line_error('EFI_D_' + mo.group(1) + ' was used, '
+ 'but DEBUG_' + mo.group(1) +
+ ' is now recommended', line)
+
split_diff_re = re.compile(r'''
(?P
^ diff \s+ --git \s+ a/.+ \s+ b/.+ $