[edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
This script can be used to check some expected rules for EDK II patches. It only works on git formatted patches. It checks both the commit message and the lines that are added in the patch diff. In the commit message it verifies line lengths, signature formats, and the Contributed-under tag. In the patch, it checks that line endings are CRLF for all files that don't have a .sh extension. It verifies that no trailing whitespace is present and that tab characters are not used. Patch contributors should use this script prior to submitting their patches. Package maintainers can also use it to verify incoming patches. It can also be run by specifying a git revision list, so actual patch files are not always required. For example, to checkout this last 5 patches in your git branch you can run: python PatchCheck.py HEAD~5.. Or, a shortcut (like git log): python PatchCheck.py -5 The --oneline option works similar to git log --oneline. The --silent option enables silent operation. The script supports python 2.7 and python 3. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen Cc: Erik Bjorge Cc: Yonghong Zhu Cc: Liming Gao --- BaseTools/Scripts/PatchCheck.py | 607 1 file changed, 607 insertions(+) create mode 100644 BaseTools/Scripts/PatchCheck.py diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py new file mode 100644 index 000..340a997 --- /dev/null +++ b/BaseTools/Scripts/PatchCheck.py @@ -0,0 +1,607 @@ +## @file +# Check a patch for various format issues +# +# Copyright (c) 2015, 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 +# accompanies this distribution. The full text of the license may be +# found at http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER +# EXPRESS OR IMPLIED. +# + +from __future__ import print_function + +VersionNumber = '0.1' +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights reserved." + +import email +import argparse +import os +import re +import subprocess +import sys + +class Verbose: +SILENT, ONELINE, NORMAL = range(3) +level = NORMAL + +class CommitMessageCheck: +"""Checks the contents of a git commit message.""" + +def __init__(self, subject, message): +self.ok = True + +if subject is None and message is None: +self.error('Commit message is missing!') +return + +self.subject = subject +self.msg = message + +self.check_contributed_under() +self.check_signed_off_by() +self.check_misc_signatures() +self.check_overall_format() +self.report_message_result() + +url = 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' + +def report_message_result(self): +if Verbose.level < Verbose.NORMAL: +return +if self.ok: +# All checks passed +return_code = 0 +print('The commit message format passed all checks.') +else: +return_code = 1 +if not self.ok: +print(self.url) + +def error(self, *err): +if self.ok and Verbose.level > Verbose.ONELINE: +print('The commit message format is not valid:') +self.ok = False +if Verbose.level < Verbose.NORMAL: +return +count = 0 +for line in err: +prefix = (' *', ' ')[count > 0] +print(prefix, line) +count += 1 + +def check_contributed_under(self): +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): +if re_input: +sub_re = sig +else: +sub_re = sig.replace('-', r'[-\s]+') +re_str = (r'^(?P' + sub_re + + r')(\s*):(\s*)(?P\S.*?)(?:\s*)$') +try: +return re.compile(re_str, re.MULTILINE|re.IGNORECASE) +except Exception: +print("Tried to compile re:", re_str) +raise + +sig_block_re = \ +re.compile(r'''^ +(?: (?P[^:]+) \s* : \s* +(?P\S.*?) ) +| +(?: \[ (?P[^:]+) \s* : \s* + (?P.+?) \s* \] ) +\s* $''', + re.VERBOSE | re.MULTILINE) + +def find_signatures(self, sig): +if not sig.endswith('-by') and sig != 'Cc': +sig += '-by' +
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
On 10/08/15 04:53, Jordan Justen wrote: > This script can be used to check some expected rules for EDK II > patches. It only works on git formatted patches. > > It checks both the commit message and the lines that are added in the > patch diff. > > In the commit message it verifies line lengths, signature formats, and > the Contributed-under tag. > > In the patch, it checks that line endings are CRLF for all files that > don't have a .sh extension. It verifies that no trailing whitespace is > present and that tab characters are not used. Yay! :) Immediate RFE: can it enforce a line length of 79 characters for lines that a patch adds, to C or assembly source code (based on filename suffix)? ;) And reject non-ASCII characters in the same? Anyway, those are just ideas, and ideas are a dime a dozen. :) Thanks Laszlo > > Patch contributors should use this script prior to submitting their > patches. Package maintainers can also use it to verify incoming > patches. > > It can also be run by specifying a git revision list, so actual patch > files are not always required. > > For example, to checkout this last 5 patches in your git branch you > can run: > > python PatchCheck.py HEAD~5.. > > Or, a shortcut (like git log): > > python PatchCheck.py -5 > > The --oneline option works similar to git log --oneline. > > The --silent option enables silent operation. > > The script supports python 2.7 and python 3. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jordan Justen > Cc: Erik Bjorge > Cc: Yonghong Zhu > Cc: Liming Gao > --- > BaseTools/Scripts/PatchCheck.py | 607 > > 1 file changed, 607 insertions(+) > create mode 100644 BaseTools/Scripts/PatchCheck.py > > diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py > new file mode 100644 > index 000..340a997 > --- /dev/null > +++ b/BaseTools/Scripts/PatchCheck.py > @@ -0,0 +1,607 @@ > +## @file > +# Check a patch for various format issues > +# > +# Copyright (c) 2015, 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 > +# accompanies this distribution. The full text of the license may be > +# found at http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > +# EXPRESS OR IMPLIED. > +# > + > +from __future__ import print_function > + > +VersionNumber = '0.1' > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights reserved." > + > +import email > +import argparse > +import os > +import re > +import subprocess > +import sys > + > +class Verbose: > +SILENT, ONELINE, NORMAL = range(3) > +level = NORMAL > + > +class CommitMessageCheck: > +"""Checks the contents of a git commit message.""" > + > +def __init__(self, subject, message): > +self.ok = True > + > +if subject is None and message is None: > +self.error('Commit message is missing!') > +return > + > +self.subject = subject > +self.msg = message > + > +self.check_contributed_under() > +self.check_signed_off_by() > +self.check_misc_signatures() > +self.check_overall_format() > +self.report_message_result() > + > +url = > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > + > +def report_message_result(self): > +if Verbose.level < Verbose.NORMAL: > +return > +if self.ok: > +# All checks passed > +return_code = 0 > +print('The commit message format passed all checks.') > +else: > +return_code = 1 > +if not self.ok: > +print(self.url) > + > +def error(self, *err): > +if self.ok and Verbose.level > Verbose.ONELINE: > +print('The commit message format is not valid:') > +self.ok = False > +if Verbose.level < Verbose.NORMAL: > +return > +count = 0 > +for line in err: > +prefix = (' *', ' ')[count > 0] > +print(prefix, line) > +count += 1 > + > +def check_contributed_under(self): > +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): > +if re_input: > +sub_re = sig > +else: > +sub_re = sig.replace('-', r'[-\s]+') > +re_str = (r'^(?P' + sub_re + > + r')(\s*):(\s*)(?P\S.*?)(?:\s*)$') > +try: > +return r
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
The patch has some trailing white spaces but other than that it works fine. Reviewed-by: Erik Bjorge -Original Message- From: Justen, Jordan L Sent: Wednesday, October 7, 2015 7:53 PM To: edk2-devel@lists.01.org Cc: Justen, Jordan L ; Bjorge, Erik C ; Zhu, Yonghong ; Gao, Liming Subject: [PATCH] BaseTools/Scripts: Add PatchCheck.py script This script can be used to check some expected rules for EDK II patches. It only works on git formatted patches. It checks both the commit message and the lines that are added in the patch diff. In the commit message it verifies line lengths, signature formats, and the Contributed-under tag. In the patch, it checks that line endings are CRLF for all files that don't have a .sh extension. It verifies that no trailing whitespace is present and that tab characters are not used. Patch contributors should use this script prior to submitting their patches. Package maintainers can also use it to verify incoming patches. It can also be run by specifying a git revision list, so actual patch files are not always required. For example, to checkout this last 5 patches in your git branch you can run: python PatchCheck.py HEAD~5.. Or, a shortcut (like git log): python PatchCheck.py -5 The --oneline option works similar to git log --oneline. The --silent option enables silent operation. The script supports python 2.7 and python 3. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Jordan Justen Cc: Erik Bjorge Cc: Yonghong Zhu Cc: Liming Gao --- BaseTools/Scripts/PatchCheck.py | 607 1 file changed, 607 insertions(+) create mode 100644 BaseTools/Scripts/PatchCheck.py diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py new file mode 100644 index 000..340a997 --- /dev/null +++ b/BaseTools/Scripts/PatchCheck.py @@ -0,0 +1,607 @@ +## @file +# Check a patch for various format issues # # Copyright (c) 2015, +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 # accompanies this +distribution. The full text of the license may be # found at +http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER # +EXPRESS OR IMPLIED. +# + +from __future__ import print_function + +VersionNumber = '0.1' +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights reserved." + +import email +import argparse +import os +import re +import subprocess +import sys + +class Verbose: +SILENT, ONELINE, NORMAL = range(3) +level = NORMAL + +class CommitMessageCheck: +"""Checks the contents of a git commit message.""" + +def __init__(self, subject, message): +self.ok = True + +if subject is None and message is None: +self.error('Commit message is missing!') +return + +self.subject = subject +self.msg = message + +self.check_contributed_under() +self.check_signed_off_by() +self.check_misc_signatures() +self.check_overall_format() +self.report_message_result() + +url = 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' + +def report_message_result(self): +if Verbose.level < Verbose.NORMAL: +return +if self.ok: +# All checks passed +return_code = 0 +print('The commit message format passed all checks.') +else: +return_code = 1 +if not self.ok: +print(self.url) + +def error(self, *err): +if self.ok and Verbose.level > Verbose.ONELINE: +print('The commit message format is not valid:') +self.ok = False +if Verbose.level < Verbose.NORMAL: +return +count = 0 +for line in err: +prefix = (' *', ' ')[count > 0] +print(prefix, line) +count += 1 + +def check_contributed_under(self): +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): +if re_input: +sub_re = sig +else: +sub_re = sig.replace('-', r'[-\s]+') +re_str = (r'^(?P' + sub_re + + r')(\s*):(\s*)(?P\S.*?)(?:\s*)$') +try: +return re.compile(re_str, re.MULTILINE|re.IGNORECASE) +except Exception: +print("Tried to compile re:", re_str) +raise + +sig_block_re = \ +re.compile(r'''^ +(?: (?P[^:]+) \s* : \s* +
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
On 10/09/15 19:13, Bjorge, Erik C wrote: > The patch has some trailing white spaces Apparently, Jordan forgot to run the script on the patch that adds the script! ;) Laszlo > but other than that it works fine. > > Reviewed-by: Erik Bjorge > > -Original Message- > From: Justen, Jordan L > Sent: Wednesday, October 7, 2015 7:53 PM > To: edk2-devel@lists.01.org > Cc: Justen, Jordan L ; Bjorge, Erik C > ; Zhu, Yonghong ; Gao, > Liming > Subject: [PATCH] BaseTools/Scripts: Add PatchCheck.py script > > This script can be used to check some expected rules for EDK II patches. It > only works on git formatted patches. > > It checks both the commit message and the lines that are added in the patch > diff. > > In the commit message it verifies line lengths, signature formats, and the > Contributed-under tag. > > In the patch, it checks that line endings are CRLF for all files that don't > have a .sh extension. It verifies that no trailing whitespace is present and > that tab characters are not used. > > Patch contributors should use this script prior to submitting their patches. > Package maintainers can also use it to verify incoming patches. > > It can also be run by specifying a git revision list, so actual patch files > are not always required. > > For example, to checkout this last 5 patches in your git branch you can run: > > python PatchCheck.py HEAD~5.. > > Or, a shortcut (like git log): > > python PatchCheck.py -5 > > The --oneline option works similar to git log --oneline. > > The --silent option enables silent operation. > > The script supports python 2.7 and python 3. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jordan Justen > Cc: Erik Bjorge > Cc: Yonghong Zhu > Cc: Liming Gao > --- > BaseTools/Scripts/PatchCheck.py | 607 > > 1 file changed, 607 insertions(+) > create mode 100644 BaseTools/Scripts/PatchCheck.py > > diff --git a/BaseTools/Scripts/PatchCheck.py > b/BaseTools/Scripts/PatchCheck.py new file mode 100644 index 000..340a997 > --- /dev/null > +++ b/BaseTools/Scripts/PatchCheck.py > @@ -0,0 +1,607 @@ > +## @file > +# Check a patch for various format issues # # Copyright (c) 2015, > +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 # accompanies this > +distribution. The full text of the license may be # found at > +http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER # > +EXPRESS OR IMPLIED. > +# > + > +from __future__ import print_function > + > +VersionNumber = '0.1' > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights reserved." > + > +import email > +import argparse > +import os > +import re > +import subprocess > +import sys > + > +class Verbose: > +SILENT, ONELINE, NORMAL = range(3) > +level = NORMAL > + > +class CommitMessageCheck: > +"""Checks the contents of a git commit message.""" > + > +def __init__(self, subject, message): > +self.ok = True > + > +if subject is None and message is None: > +self.error('Commit message is missing!') > +return > + > +self.subject = subject > +self.msg = message > + > +self.check_contributed_under() > +self.check_signed_off_by() > +self.check_misc_signatures() > +self.check_overall_format() > +self.report_message_result() > + > +url = > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > + > +def report_message_result(self): > +if Verbose.level < Verbose.NORMAL: > +return > +if self.ok: > +# All checks passed > +return_code = 0 > +print('The commit message format passed all checks.') > +else: > +return_code = 1 > +if not self.ok: > +print(self.url) > + > +def error(self, *err): > +if self.ok and Verbose.level > Verbose.ONELINE: > +print('The commit message format is not valid:') > +self.ok = False > +if Verbose.level < Verbose.NORMAL: > +return > +count = 0 > +for line in err: > +prefix = (' *', ' ')[count > 0] > +print(prefix, line) > +count += 1 > + > +def check_contributed_under(self): > +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): > +if re_input: > +sub_re = sig > +
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
On 2015-10-09 10:57:40, Laszlo Ersek wrote: > On 10/09/15 19:13, Bjorge, Erik C wrote: > > The patch has some trailing white spaces > > Apparently, Jordan forgot to run the script on the patch that adds the > script! ;) I ran the script on the patch, and it didn't flag any trailing whitespace. So, if there is trailing whitespace in the patch, then there is a bug in the script. I also tried using my editor to cleanup any tailing whitespace, and it didn't seem to locate any. Can either of you point out a line with trailing whitespace in the patch? -Jordan > > but other than that it works fine. > > > > Reviewed-by: Erik Bjorge > > > > -Original Message- > > From: Justen, Jordan L > > Sent: Wednesday, October 7, 2015 7:53 PM > > To: edk2-devel@lists.01.org > > Cc: Justen, Jordan L ; Bjorge, Erik C > > ; Zhu, Yonghong ; Gao, > > Liming > > Subject: [PATCH] BaseTools/Scripts: Add PatchCheck.py script > > > > This script can be used to check some expected rules for EDK II patches. It > > only works on git formatted patches. > > > > It checks both the commit message and the lines that are added in the patch > > diff. > > > > In the commit message it verifies line lengths, signature formats, and the > > Contributed-under tag. > > > > In the patch, it checks that line endings are CRLF for all files that don't > > have a .sh extension. It verifies that no trailing whitespace is present > > and that tab characters are not used. > > > > Patch contributors should use this script prior to submitting their > > patches. Package maintainers can also use it to verify incoming patches. > > > > It can also be run by specifying a git revision list, so actual patch files > > are not always required. > > > > For example, to checkout this last 5 patches in your git branch you can run: > > > > python PatchCheck.py HEAD~5.. > > > > Or, a shortcut (like git log): > > > > python PatchCheck.py -5 > > > > The --oneline option works similar to git log --oneline. > > > > The --silent option enables silent operation. > > > > The script supports python 2.7 and python 3. > > > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Jordan Justen > > Cc: Erik Bjorge > > Cc: Yonghong Zhu > > Cc: Liming Gao > > --- > > BaseTools/Scripts/PatchCheck.py | 607 > > > > 1 file changed, 607 insertions(+) > > create mode 100644 BaseTools/Scripts/PatchCheck.py > > > > diff --git a/BaseTools/Scripts/PatchCheck.py > > b/BaseTools/Scripts/PatchCheck.py new file mode 100644 index > > 000..340a997 > > --- /dev/null > > +++ b/BaseTools/Scripts/PatchCheck.py > > @@ -0,0 +1,607 @@ > > +## @file > > +# Check a patch for various format issues # # Copyright (c) 2015, > > +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 # accompanies this > > +distribution. The full text of the license may be # found at > > +http://opensource.org/licenses/bsd-license.php > > +# > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER # > > +EXPRESS OR IMPLIED. > > +# > > + > > +from __future__ import print_function > > + > > +VersionNumber = '0.1' > > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights > > reserved." > > + > > +import email > > +import argparse > > +import os > > +import re > > +import subprocess > > +import sys > > + > > +class Verbose: > > +SILENT, ONELINE, NORMAL = range(3) > > +level = NORMAL > > + > > +class CommitMessageCheck: > > +"""Checks the contents of a git commit message.""" > > + > > +def __init__(self, subject, message): > > +self.ok = True > > + > > +if subject is None and message is None: > > +self.error('Commit message is missing!') > > +return > > + > > +self.subject = subject > > +self.msg = message > > + > > +self.check_contributed_under() > > +self.check_signed_off_by() > > +self.check_misc_signatures() > > +self.check_overall_format() > > +self.report_message_result() > > + > > +url = > > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > > + > > +def report_message_result(self): > > +if Verbose.level < Verbose.NORMAL: > > +return > > +if self.ok: > > +# All checks passed > > +return_code = 0 > > +print('The commit message format passed all checks.') > > +else: > > +return_code = 1 > > +if not self.ok: > > +print(self.url) > > + > > +def error(self, *err): > > +if self.ok and Verbose.level > Verbose.ONELINE: > > +print('The commit message format is not valid:') > > +self.ok = False > > +
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
On 2015-10-08 15:22:08, Laszlo Ersek wrote: > On 10/08/15 04:53, Jordan Justen wrote: > > This script can be used to check some expected rules for EDK II > > patches. It only works on git formatted patches. > > > > It checks both the commit message and the lines that are added in the > > patch diff. > > > > In the commit message it verifies line lengths, signature formats, and > > the Contributed-under tag. > > > > In the patch, it checks that line endings are CRLF for all files that > > don't have a .sh extension. It verifies that no trailing whitespace is > > present and that tab characters are not used. > > Yay! :) > > Immediate RFE: can it enforce a line length of 79 characters for lines > that a patch adds, to C or assembly source code (based on filename > suffix)? ;) I would also like to add this. But, I thought it might be too controversial for a first pass. (Despite the fact that it is part of the coding standard.) > And reject non-ASCII characters in the same? This one I'd like to hold off on just because I don't want to spend the time implement it just now. :) -Jordan > Anyway, those are just ideas, and ideas are a dime a dozen. :) > > Thanks > Laszlo > > > > > Patch contributors should use this script prior to submitting their > > patches. Package maintainers can also use it to verify incoming > > patches. > > > > It can also be run by specifying a git revision list, so actual patch > > files are not always required. > > > > For example, to checkout this last 5 patches in your git branch you > > can run: > > > > python PatchCheck.py HEAD~5.. > > > > Or, a shortcut (like git log): > > > > python PatchCheck.py -5 > > > > The --oneline option works similar to git log --oneline. > > > > The --silent option enables silent operation. > > > > The script supports python 2.7 and python 3. > > > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Jordan Justen > > Cc: Erik Bjorge > > Cc: Yonghong Zhu > > Cc: Liming Gao > > --- > > BaseTools/Scripts/PatchCheck.py | 607 > > > > 1 file changed, 607 insertions(+) > > create mode 100644 BaseTools/Scripts/PatchCheck.py > > > > diff --git a/BaseTools/Scripts/PatchCheck.py > > b/BaseTools/Scripts/PatchCheck.py > > new file mode 100644 > > index 000..340a997 > > --- /dev/null > > +++ b/BaseTools/Scripts/PatchCheck.py > > @@ -0,0 +1,607 @@ > > +## @file > > +# Check a patch for various format issues > > +# > > +# Copyright (c) 2015, 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 > > +# accompanies this distribution. The full text of the license may be > > +# found at http://opensource.org/licenses/bsd-license.php > > +# > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > > +# EXPRESS OR IMPLIED. > > +# > > + > > +from __future__ import print_function > > + > > +VersionNumber = '0.1' > > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights > > reserved." > > + > > +import email > > +import argparse > > +import os > > +import re > > +import subprocess > > +import sys > > + > > +class Verbose: > > +SILENT, ONELINE, NORMAL = range(3) > > +level = NORMAL > > + > > +class CommitMessageCheck: > > +"""Checks the contents of a git commit message.""" > > + > > +def __init__(self, subject, message): > > +self.ok = True > > + > > +if subject is None and message is None: > > +self.error('Commit message is missing!') > > +return > > + > > +self.subject = subject > > +self.msg = message > > + > > +self.check_contributed_under() > > +self.check_signed_off_by() > > +self.check_misc_signatures() > > +self.check_overall_format() > > +self.report_message_result() > > + > > +url = > > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > > + > > +def report_message_result(self): > > +if Verbose.level < Verbose.NORMAL: > > +return > > +if self.ok: > > +# All checks passed > > +return_code = 0 > > +print('The commit message format passed all checks.') > > +else: > > +return_code = 1 > > +if not self.ok: > > +print(self.url) > > + > > +def error(self, *err): > > +if self.ok and Verbose.level > Verbose.ONELINE: > > +print('The commit message format is not valid:') > > +self.ok = False > > +if Verbose.level < Verbose.NORMAL: > > +return > > +count = 0 > > +for line in err: > > +prefix = (' *', ' ')[count > 0] > > +print(prefix, line) > > +count += 1 > > + > > +def check_cont
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
On Wed, Oct 07, 2015 at 07:53:18PM -0700, Jordan Justen wrote: > This script can be used to check some expected rules for EDK II > patches. It only works on git formatted patches. Yay, that's a much better implementation than the one I keep failing to complete! :) > It checks both the commit message and the lines that are added in the > patch diff. > > In the commit message it verifies line lengths, signature formats, and > the Contributed-under tag. > > In the patch, it checks that line endings are CRLF for all files that > don't have a .sh extension. It verifies that no trailing whitespace is > present and that tab characters are not used. > > Patch contributors should use this script prior to submitting their > patches. Package maintainers can also use it to verify incoming > patches. > > It can also be run by specifying a git revision list, so actual patch > files are not always required. > > For example, to checkout this last 5 patches in your git branch you > can run: > > python PatchCheck.py HEAD~5.. > > Or, a shortcut (like git log): > > python PatchCheck.py -5 > > The --oneline option works similar to git log --oneline. > > The --silent option enables silent operation. > > The script supports python 2.7 and python 3. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jordan Justen > Cc: Erik Bjorge > Cc: Yonghong Zhu > Cc: Liming Gao > --- > BaseTools/Scripts/PatchCheck.py | 607 > > 1 file changed, 607 insertions(+) > create mode 100644 BaseTools/Scripts/PatchCheck.py > > diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py > new file mode 100644 Here is actually the only complaint I'm going to make, and it's a bit random: Even though scripts in edk2 don't tend to describe their interpreter (#!), they do tend to be 100755 mode, which highlights them as executables. it would be useful to do the same here. With that, if it speeds up getting this sorely missing piece of infrastructure in: Reviewed-by: Leif Lindholm / Leif > index 000..340a997 > --- /dev/null > +++ b/BaseTools/Scripts/PatchCheck.py > @@ -0,0 +1,607 @@ > +## @file > +# Check a patch for various format issues > +# > +# Copyright (c) 2015, 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 > +# accompanies this distribution. The full text of the license may be > +# found at http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > +# EXPRESS OR IMPLIED. > +# > + > +from __future__ import print_function > + > +VersionNumber = '0.1' > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights reserved." > + > +import email > +import argparse > +import os > +import re > +import subprocess > +import sys > + > +class Verbose: > +SILENT, ONELINE, NORMAL = range(3) > +level = NORMAL > + > +class CommitMessageCheck: > +"""Checks the contents of a git commit message.""" > + > +def __init__(self, subject, message): > +self.ok = True > + > +if subject is None and message is None: > +self.error('Commit message is missing!') > +return > + > +self.subject = subject > +self.msg = message > + > +self.check_contributed_under() > +self.check_signed_off_by() > +self.check_misc_signatures() > +self.check_overall_format() > +self.report_message_result() > + > +url = > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > + > +def report_message_result(self): > +if Verbose.level < Verbose.NORMAL: > +return > +if self.ok: > +# All checks passed > +return_code = 0 > +print('The commit message format passed all checks.') > +else: > +return_code = 1 > +if not self.ok: > +print(self.url) > + > +def error(self, *err): > +if self.ok and Verbose.level > Verbose.ONELINE: > +print('The commit message format is not valid:') > +self.ok = False > +if Verbose.level < Verbose.NORMAL: > +return > +count = 0 > +for line in err: > +prefix = (' *', ' ')[count > 0] > +print(prefix, line) > +count += 1 > + > +def check_contributed_under(self): > +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): > +if re_input: > +sub_
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
On 2015-10-10 04:07:22, Leif Lindholm wrote: > On Wed, Oct 07, 2015 at 07:53:18PM -0700, Jordan Justen wrote: > > This script can be used to check some expected rules for EDK II > > patches. It only works on git formatted patches. > > Yay, that's a much better implementation than the one I keep failing > to complete! :) > > > It checks both the commit message and the lines that are added in the > > patch diff. > > > > In the commit message it verifies line lengths, signature formats, and > > the Contributed-under tag. > > > > In the patch, it checks that line endings are CRLF for all files that > > don't have a .sh extension. It verifies that no trailing whitespace is > > present and that tab characters are not used. > > > > Patch contributors should use this script prior to submitting their > > patches. Package maintainers can also use it to verify incoming > > patches. > > > > It can also be run by specifying a git revision list, so actual patch > > files are not always required. > > > > For example, to checkout this last 5 patches in your git branch you > > can run: > > > > python PatchCheck.py HEAD~5.. > > > > Or, a shortcut (like git log): > > > > python PatchCheck.py -5 > > > > The --oneline option works similar to git log --oneline. > > > > The --silent option enables silent operation. > > > > The script supports python 2.7 and python 3. > > > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Jordan Justen > > Cc: Erik Bjorge > > Cc: Yonghong Zhu > > Cc: Liming Gao > > --- > > BaseTools/Scripts/PatchCheck.py | 607 > > > > 1 file changed, 607 insertions(+) > > create mode 100644 BaseTools/Scripts/PatchCheck.py > > > > diff --git a/BaseTools/Scripts/PatchCheck.py > > b/BaseTools/Scripts/PatchCheck.py > > new file mode 100644 > > Here is actually the only complaint I'm going to make, and it's a bit > random: > Even though scripts in edk2 don't tend to describe their interpreter > (#!), they do tend to be 100755 mode, which highlights them as > executables. it would be useful to do the same here. I don't think making it executable without #! will help much. And, #! can't be used in the script, since it uses CRLF line endings. My understanding is that we currently require all .py files to use CRLF. Maybe a shell script at BaseTools/Scripts/PatchCheck that runs python with the script would be helpful. (Hmm, maybe the script should not require CRLF for extensionless files.) -Jordan > With that, if it speeds up getting this sorely missing piece of > infrastructure in: > > Reviewed-by: Leif Lindholm > > / > Leif > > > index 000..340a997 > > --- /dev/null > > +++ b/BaseTools/Scripts/PatchCheck.py > > @@ -0,0 +1,607 @@ > > +## @file > > +# Check a patch for various format issues > > +# > > +# Copyright (c) 2015, 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 > > +# accompanies this distribution. The full text of the license may be > > +# found at http://opensource.org/licenses/bsd-license.php > > +# > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > > +# EXPRESS OR IMPLIED. > > +# > > + > > +from __future__ import print_function > > + > > +VersionNumber = '0.1' > > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights > > reserved." > > + > > +import email > > +import argparse > > +import os > > +import re > > +import subprocess > > +import sys > > + > > +class Verbose: > > +SILENT, ONELINE, NORMAL = range(3) > > +level = NORMAL > > + > > +class CommitMessageCheck: > > +"""Checks the contents of a git commit message.""" > > + > > +def __init__(self, subject, message): > > +self.ok = True > > + > > +if subject is None and message is None: > > +self.error('Commit message is missing!') > > +return > > + > > +self.subject = subject > > +self.msg = message > > + > > +self.check_contributed_under() > > +self.check_signed_off_by() > > +self.check_misc_signatures() > > +self.check_overall_format() > > +self.report_message_result() > > + > > +url = > > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > > + > > +def report_message_result(self): > > +if Verbose.level < Verbose.NORMAL: > > +return > > +if self.ok: > > +# All checks passed > > +return_code = 0 > > +print('The commit message format passed all checks.') > > +else: > > +return_code = 1 > > +if not self.ok: > > +print(self.url) > > + > > +def error(self, *err): > > +if self.ok and Verbose.level > Verbose.ONELINE: > > +
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
On Sat, Oct 10, 2015 at 08:45:19AM -0700, Jordan Justen wrote: > On 2015-10-10 04:07:22, Leif Lindholm wrote: > > On Wed, Oct 07, 2015 at 07:53:18PM -0700, Jordan Justen wrote: > > > This script can be used to check some expected rules for EDK II > > > patches. It only works on git formatted patches. > > > > Yay, that's a much better implementation than the one I keep failing > > to complete! :) > > > > > It checks both the commit message and the lines that are added in the > > > patch diff. > > > > > > In the commit message it verifies line lengths, signature formats, and > > > the Contributed-under tag. > > > > > > In the patch, it checks that line endings are CRLF for all files that > > > don't have a .sh extension. It verifies that no trailing whitespace is > > > present and that tab characters are not used. > > > > > > Patch contributors should use this script prior to submitting their > > > patches. Package maintainers can also use it to verify incoming > > > patches. > > > > > > It can also be run by specifying a git revision list, so actual patch > > > files are not always required. > > > > > > For example, to checkout this last 5 patches in your git branch you > > > can run: > > > > > > python PatchCheck.py HEAD~5.. > > > > > > Or, a shortcut (like git log): > > > > > > python PatchCheck.py -5 > > > > > > The --oneline option works similar to git log --oneline. > > > > > > The --silent option enables silent operation. > > > > > > The script supports python 2.7 and python 3. > > > > > > Contributed-under: TianoCore Contribution Agreement 1.0 > > > Signed-off-by: Jordan Justen > > > Cc: Erik Bjorge > > > Cc: Yonghong Zhu > > > Cc: Liming Gao > > > --- > > > BaseTools/Scripts/PatchCheck.py | 607 > > > > > > 1 file changed, 607 insertions(+) > > > create mode 100644 BaseTools/Scripts/PatchCheck.py > > > > > > diff --git a/BaseTools/Scripts/PatchCheck.py > > > b/BaseTools/Scripts/PatchCheck.py > > > new file mode 100644 > > > > Here is actually the only complaint I'm going to make, and it's a bit > > random: > > Even though scripts in edk2 don't tend to describe their interpreter > > (#!), they do tend to be 100755 mode, which highlights them as > > executables. it would be useful to do the same here. > > I don't think making it executable without #! will help much. And, #! > can't be used in the script, since it uses CRLF line endings. My > understanding is that we currently require all .py files to use CRLF. What I said was that the mode on this file in this patch is a mismatch with the mode of other .py files in the tree, including some in the same directory. > Maybe a shell script at BaseTools/Scripts/PatchCheck that runs python > with the script would be helpful. (Hmm, maybe the script should not > require CRLF for extensionless files.) Or we could rename the extensionless files, giving appropriate extensions. Short of swithing everything to LF-only, that's the only way we can make sure that a syntax checker will get it right. > -Jordan > > > With that, if it speeds up getting this sorely missing piece of > > infrastructure in: > > > > Reviewed-by: Leif Lindholm > > > > / > > Leif > > > > > index 000..340a997 > > > --- /dev/null > > > +++ b/BaseTools/Scripts/PatchCheck.py > > > @@ -0,0 +1,607 @@ > > > +## @file > > > +# Check a patch for various format issues > > > +# > > > +# Copyright (c) 2015, 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 > > > +# accompanies this distribution. The full text of the license may be > > > +# found at http://opensource.org/licenses/bsd-license.php > > > +# > > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > > > +# EXPRESS OR IMPLIED. > > > +# > > > + > > > +from __future__ import print_function > > > + > > > +VersionNumber = '0.1' > > > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights > > > reserved." > > > + > > > +import email > > > +import argparse > > > +import os > > > +import re > > > +import subprocess > > > +import sys > > > + > > > +class Verbose: > > > +SILENT, ONELINE, NORMAL = range(3) > > > +level = NORMAL > > > + > > > +class CommitMessageCheck: > > > +"""Checks the contents of a git commit message.""" > > > + > > > +def __init__(self, subject, message): > > > +self.ok = True > > > + > > > +if subject is None and message is None: > > > +self.error('Commit message is missing!') > > > +return > > > + > > > +self.subject = subject > > > +self.msg = message > > > + > > > +self.check_contributed_under() > > > +self.check_signed_off_by() > > > +self.check_misc_signatures() > > > +self.check_over
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
I think it may have been outlook messing with me when applying the patch. The whitespace notice was about some of the copyright lines. I will pull from your public repo/branch and see if I have the same issue. Thanks, -Erik -Original Message- From: Justen, Jordan L Sent: Friday, October 9, 2015 11:11 AM To: Laszlo Ersek ; Bjorge, Erik C ; edk2-devel@lists.01.org Cc: Gao, Liming Subject: Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script On 2015-10-09 10:57:40, Laszlo Ersek wrote: > On 10/09/15 19:13, Bjorge, Erik C wrote: > > The patch has some trailing white spaces > > Apparently, Jordan forgot to run the script on the patch that adds the > script! ;) I ran the script on the patch, and it didn't flag any trailing whitespace. So, if there is trailing whitespace in the patch, then there is a bug in the script. I also tried using my editor to cleanup any tailing whitespace, and it didn't seem to locate any. Can either of you point out a line with trailing whitespace in the patch? -Jordan > > but other than that it works fine. > > > > Reviewed-by: Erik Bjorge > > > > -Original Message- > > From: Justen, Jordan L > > Sent: Wednesday, October 7, 2015 7:53 PM > > To: edk2-devel@lists.01.org > > Cc: Justen, Jordan L ; Bjorge, Erik C > > ; Zhu, Yonghong ; > > Gao, Liming > > Subject: [PATCH] BaseTools/Scripts: Add PatchCheck.py script > > > > This script can be used to check some expected rules for EDK II patches. It > > only works on git formatted patches. > > > > It checks both the commit message and the lines that are added in the patch > > diff. > > > > In the commit message it verifies line lengths, signature formats, and the > > Contributed-under tag. > > > > In the patch, it checks that line endings are CRLF for all files that don't > > have a .sh extension. It verifies that no trailing whitespace is present > > and that tab characters are not used. > > > > Patch contributors should use this script prior to submitting their > > patches. Package maintainers can also use it to verify incoming patches. > > > > It can also be run by specifying a git revision list, so actual patch files > > are not always required. > > > > For example, to checkout this last 5 patches in your git branch you can run: > > > > python PatchCheck.py HEAD~5.. > > > > Or, a shortcut (like git log): > > > > python PatchCheck.py -5 > > > > The --oneline option works similar to git log --oneline. > > > > The --silent option enables silent operation. > > > > The script supports python 2.7 and python 3. > > > > Contributed-under: TianoCore Contribution Agreement 1.0 > > Signed-off-by: Jordan Justen > > Cc: Erik Bjorge > > Cc: Yonghong Zhu > > Cc: Liming Gao > > --- > > BaseTools/Scripts/PatchCheck.py | 607 > > > > 1 file changed, 607 insertions(+) > > create mode 100644 BaseTools/Scripts/PatchCheck.py > > > > diff --git a/BaseTools/Scripts/PatchCheck.py > > b/BaseTools/Scripts/PatchCheck.py new file mode 100644 index > > 000..340a997 > > --- /dev/null > > +++ b/BaseTools/Scripts/PatchCheck.py > > @@ -0,0 +1,607 @@ > > +## @file > > +# Check a patch for various format issues # # Copyright (c) 2015, > > +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 # accompanies > > +this distribution. The full text of the license may be # found at > > +http://opensource.org/licenses/bsd-license.php > > +# > > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > > +# EXPRESS OR IMPLIED. > > +# > > + > > +from __future__ import print_function > > + > > +VersionNumber = '0.1' > > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights > > reserved." > > + > > +import email > > +import argparse > > +import os > > +import re > > +import subprocess > > +import sys > > + > > +class Verbose: > > +SILENT, ONELINE, NORMAL = range(3) > > +level = NORMAL > > + > > +class CommitMessageCheck: > > +"""Checks the contents of a git commit message.""" > > + > > +def __init__(self, subject, message): > &g
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
Yonghong, Liming, I have gotten two reviews for this patch. Do either of you have concerns with me committing this change to BaseTools? -Jordan On 2015-10-07 19:53:18, Jordan Justen wrote: > This script can be used to check some expected rules for EDK II > patches. It only works on git formatted patches. > > It checks both the commit message and the lines that are added in the > patch diff. > > In the commit message it verifies line lengths, signature formats, and > the Contributed-under tag. > > In the patch, it checks that line endings are CRLF for all files that > don't have a .sh extension. It verifies that no trailing whitespace is > present and that tab characters are not used. > > Patch contributors should use this script prior to submitting their > patches. Package maintainers can also use it to verify incoming > patches. > > It can also be run by specifying a git revision list, so actual patch > files are not always required. > > For example, to checkout this last 5 patches in your git branch you > can run: > > python PatchCheck.py HEAD~5.. > > Or, a shortcut (like git log): > > python PatchCheck.py -5 > > The --oneline option works similar to git log --oneline. > > The --silent option enables silent operation. > > The script supports python 2.7 and python 3. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jordan Justen > Cc: Erik Bjorge > Cc: Yonghong Zhu > Cc: Liming Gao > --- > BaseTools/Scripts/PatchCheck.py | 607 > > 1 file changed, 607 insertions(+) > create mode 100644 BaseTools/Scripts/PatchCheck.py > > diff --git a/BaseTools/Scripts/PatchCheck.py b/BaseTools/Scripts/PatchCheck.py > new file mode 100644 > index 000..340a997 > --- /dev/null > +++ b/BaseTools/Scripts/PatchCheck.py > @@ -0,0 +1,607 @@ > +## @file > +# Check a patch for various format issues > +# > +# Copyright (c) 2015, 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 > +# accompanies this distribution. The full text of the license may be > +# found at http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER > +# EXPRESS OR IMPLIED. > +# > + > +from __future__ import print_function > + > +VersionNumber = '0.1' > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights reserved." > + > +import email > +import argparse > +import os > +import re > +import subprocess > +import sys > + > +class Verbose: > +SILENT, ONELINE, NORMAL = range(3) > +level = NORMAL > + > +class CommitMessageCheck: > +"""Checks the contents of a git commit message.""" > + > +def __init__(self, subject, message): > +self.ok = True > + > +if subject is None and message is None: > +self.error('Commit message is missing!') > +return > + > +self.subject = subject > +self.msg = message > + > +self.check_contributed_under() > +self.check_signed_off_by() > +self.check_misc_signatures() > +self.check_overall_format() > +self.report_message_result() > + > +url = > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > + > +def report_message_result(self): > +if Verbose.level < Verbose.NORMAL: > +return > +if self.ok: > +# All checks passed > +return_code = 0 > +print('The commit message format passed all checks.') > +else: > +return_code = 1 > +if not self.ok: > +print(self.url) > + > +def error(self, *err): > +if self.ok and Verbose.level > Verbose.ONELINE: > +print('The commit message format is not valid:') > +self.ok = False > +if Verbose.level < Verbose.NORMAL: > +return > +count = 0 > +for line in err: > +prefix = (' *', ' ')[count > 0] > +print(prefix, line) > +count += 1 > + > +def check_contributed_under(self): > +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): > +if re_input: > +sub_re = sig > +else: > +sub_re = sig.replace('-', r'[-\s]+') > +re_str = (r'^(?P' + sub_re + > + r')(\s*):(\s*)(?P\S.*?)(?:\s*)$') > +try: > +return re.compile(re_str, re.MULTILINE|re.IGNORECASE) > +except Exception: > +print("Tried to compile re:", re_str) > +
Re: [edk2] [PATCH] BaseTools/Scripts: Add PatchCheck.py script
Jordan: I have no other comment. Reviewed-by: Liming Gao Thanks Liming -Original Message- From: Justen, Jordan L Sent: Thursday, October 22, 2015 6:03 AM To: Zhu, Yonghong; Gao, Liming Cc: Bjorge, Erik C; edk2-devel@lists.01.org Subject: Re: [PATCH] BaseTools/Scripts: Add PatchCheck.py script Yonghong, Liming, I have gotten two reviews for this patch. Do either of you have concerns with me committing this change to BaseTools? -Jordan On 2015-10-07 19:53:18, Jordan Justen wrote: > This script can be used to check some expected rules for EDK II > patches. It only works on git formatted patches. > > It checks both the commit message and the lines that are added in the > patch diff. > > In the commit message it verifies line lengths, signature formats, and > the Contributed-under tag. > > In the patch, it checks that line endings are CRLF for all files that > don't have a .sh extension. It verifies that no trailing whitespace is > present and that tab characters are not used. > > Patch contributors should use this script prior to submitting their > patches. Package maintainers can also use it to verify incoming > patches. > > It can also be run by specifying a git revision list, so actual patch > files are not always required. > > For example, to checkout this last 5 patches in your git branch you > can run: > > python PatchCheck.py HEAD~5.. > > Or, a shortcut (like git log): > > python PatchCheck.py -5 > > The --oneline option works similar to git log --oneline. > > The --silent option enables silent operation. > > The script supports python 2.7 and python 3. > > Contributed-under: TianoCore Contribution Agreement 1.0 > Signed-off-by: Jordan Justen > Cc: Erik Bjorge > Cc: Yonghong Zhu > Cc: Liming Gao > --- > BaseTools/Scripts/PatchCheck.py | 607 > > 1 file changed, 607 insertions(+) > create mode 100644 BaseTools/Scripts/PatchCheck.py > > diff --git a/BaseTools/Scripts/PatchCheck.py > b/BaseTools/Scripts/PatchCheck.py new file mode 100644 index > 000..340a997 > --- /dev/null > +++ b/BaseTools/Scripts/PatchCheck.py > @@ -0,0 +1,607 @@ > +## @file > +# Check a patch for various format issues # # Copyright (c) 2015, > +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 # accompanies this > +distribution. The full text of the license may be # found at > +http://opensource.org/licenses/bsd-license.php > +# > +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" > +# BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER # > +EXPRESS OR IMPLIED. > +# > + > +from __future__ import print_function > + > +VersionNumber = '0.1' > +__copyright__ = "Copyright (c) 2015, Intel Corporation All rights reserved." > + > +import email > +import argparse > +import os > +import re > +import subprocess > +import sys > + > +class Verbose: > +SILENT, ONELINE, NORMAL = range(3) > +level = NORMAL > + > +class CommitMessageCheck: > +"""Checks the contents of a git commit message.""" > + > +def __init__(self, subject, message): > +self.ok = True > + > +if subject is None and message is None: > +self.error('Commit message is missing!') > +return > + > +self.subject = subject > +self.msg = message > + > +self.check_contributed_under() > +self.check_signed_off_by() > +self.check_misc_signatures() > +self.check_overall_format() > +self.report_message_result() > + > +url = > 'https://github.com/tianocore/tianocore.github.io/wiki/Commit-Message-Format' > + > +def report_message_result(self): > +if Verbose.level < Verbose.NORMAL: > +return > +if self.ok: > +# All checks passed > +return_code = 0 > +print('The commit message format passed all checks.') > +else: > +return_code = 1 > +if not self.ok: > +print(self.url) > + > +def error(self, *err): > +if self.ok and Verbose.level > Verbose.ONELINE: > +print('The commit message format is not valid:') > +self.ok = False > +if Verbose.level < Verbose.NORMAL: > +return > +count = 0 > +for line in err: > +prefix = (' *', ' ')[count > 0] > +print(prefix, line) > +count += 1 > + > +def check_contributed_under(self): > +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): > +if re_input: > +sub_re = sig > +else: