summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorvries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2017-05-29 07:31:02 +0000
committervries <vries@138bc75d-0d04-0410-961f-82ee72b054a4>2017-05-29 07:31:02 +0000
commit5d952fcda470b80e5b1ee71ee06fd7593b1aee22 (patch)
treec01f020ebfc7f2853ae2895bca929f360c8b5748 /contrib
parent80885f4fc0c15dd2c2739e9537fa4ff9409b3068 (diff)
downloadgcc-5d952fcda470b80e5b1ee71ee06fd7593b1aee22.tar.gz
check_GNU_style.py: Read stdin if file argument is '-'
2017-05-29 Tom de Vries <tom@codesourcery.com> * check_GNU_style_lib.py (check_GNU_style_file): Treat file argument as file handle. Add and handle file_encoding argument. * check_GNU_style.py (main): Handle '-' file argument. Call check_GNU_style_file with file handle as argument. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@248555 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'contrib')
-rw-r--r--contrib/ChangeLog7
-rwxr-xr-xcontrib/check_GNU_style.py10
-rwxr-xr-xcontrib/check_GNU_style_lib.py5
3 files changed, 18 insertions, 4 deletions
diff --git a/contrib/ChangeLog b/contrib/ChangeLog
index 582850857a8..d5b390c8c86 100644
--- a/contrib/ChangeLog
+++ b/contrib/ChangeLog
@@ -1,5 +1,12 @@
2017-05-29 Tom de Vries <tom@codesourcery.com>
+ * check_GNU_style_lib.py (check_GNU_style_file): Treat file argument as
+ file handle. Add and handle file_encoding argument.
+ * check_GNU_style.py (main): Handle '-' file argument. Call
+ check_GNU_style_file with file handle as argument.
+
+2017-05-29 Tom de Vries <tom@codesourcery.com>
+
* check_GNU_style_lib.py: Use import_pip3 to import pip3 packages.
(import_pip3): New function.
diff --git a/contrib/check_GNU_style.py b/contrib/check_GNU_style.py
index 6970ddfe1f4..61faa290fa1 100755
--- a/contrib/check_GNU_style.py
+++ b/contrib/check_GNU_style.py
@@ -21,6 +21,7 @@
# <http://www.gnu.org/licenses/>. */
import argparse
+import sys
from check_GNU_style_lib import check_GNU_style_file
def main():
@@ -30,6 +31,13 @@ def main():
help = 'Display format',
choices = ['stdio', 'quickfix'])
args = parser.parse_args()
- check_GNU_style_file(args.file, args.format)
+ filename = args.file
+ format = args.format
+
+ if filename == '-':
+ check_GNU_style_file(sys.stdin, None, format)
+ else:
+ with open(filename, 'rb') as diff_file:
+ check_GNU_style_file(diff_file, 'utf-8', format)
main()
diff --git a/contrib/check_GNU_style_lib.py b/contrib/check_GNU_style_lib.py
index d924e68ecbc..e1031dfcd92 100755
--- a/contrib/check_GNU_style_lib.py
+++ b/contrib/check_GNU_style_lib.py
@@ -223,7 +223,7 @@ class LineLengthTest(unittest.TestCase):
self.assertEqual(r.console_error,
self.check.limit * 'a' + error_string(' = 123;'))
-def check_GNU_style_file(file, format):
+def check_GNU_style_file(file, file_encoding, format):
checks = [LineLengthCheck(), SpacesCheck(), TrailingWhitespaceCheck(),
SentenceSeparatorCheck(), SentenceEndOfCommentCheck(),
SentenceDotEndCheck(), FunctionParenthesisCheck(),
@@ -231,8 +231,7 @@ def check_GNU_style_file(file, format):
BracesOnSeparateLineCheck(), TrailinigOperatorCheck()]
errors = []
- with open(file, 'rb') as diff_file:
- patch = PatchSet(diff_file, encoding = 'utf-8')
+ patch = PatchSet(file, encoding=file_encoding)
for pfile in patch.added_files + patch.modified_files:
t = pfile.target_file.lstrip('b/')