summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJerry Jelinek <jerry.jelinek@joyent.com>2018-05-07 11:44:41 +0000
committerJerry Jelinek <jerry.jelinek@joyent.com>2018-05-07 11:44:41 +0000
commit591b9c242301892c6a1c6fa87d9d5a9100561efe (patch)
tree2951bfe62b5c856cc132ea9d306d3183c516b6f8
parent734000027845005c8c88895da60e3be5798296e2 (diff)
parent4ff15898b7da74f6c007b0fef82a27cb866afade (diff)
downloadillumos-joyent-591b9c242301892c6a1c6fa87d9d5a9100561efe.tar.gz
[illumos-gate merge]
commit 4ff15898b7da74f6c007b0fef82a27cb866afade 9473 Want git nits to check for white space nits
-rw-r--r--usr/src/pkg/manifests/developer-build-onbld.mf5
-rw-r--r--usr/src/tools/onbld/Checks/Makefile3
-rw-r--r--usr/src/tools/onbld/Checks/WsCheck.py46
-rw-r--r--usr/src/tools/onbld/Checks/__init__.py3
-rw-r--r--usr/src/tools/scripts/Makefile5
-rw-r--r--usr/src/tools/scripts/git-pbchk.py18
-rw-r--r--usr/src/tools/scripts/wscheck.py54
7 files changed, 126 insertions, 8 deletions
diff --git a/usr/src/pkg/manifests/developer-build-onbld.mf b/usr/src/pkg/manifests/developer-build-onbld.mf
index 51c3a1aa98..47ffd7808e 100644
--- a/usr/src/pkg/manifests/developer-build-onbld.mf
+++ b/usr/src/pkg/manifests/developer-build-onbld.mf
@@ -121,6 +121,7 @@ file path=opt/onbld/bin/wdiff mode=0555
file path=opt/onbld/bin/webrev mode=0555
file path=opt/onbld/bin/which_scm mode=0555
file path=opt/onbld/bin/ws mode=0555
+file path=opt/onbld/bin/wscheck mode=0555
file path=opt/onbld/bin/wsdiff mode=0555
file path=opt/onbld/bin/xref mode=0555
file path=opt/onbld/bin/xref.mk
@@ -186,6 +187,10 @@ file path=opt/onbld/lib/python$(PYTHON_VERSION)/onbld/Checks/SpellCheck.py \
mode=0444
file path=opt/onbld/lib/python$(PYTHON_VERSION)/onbld/Checks/SpellCheck.pyc \
mode=0444
+file path=opt/onbld/lib/python$(PYTHON_VERSION)/onbld/Checks/WsCheck.py \
+ mode=0444
+file path=opt/onbld/lib/python$(PYTHON_VERSION)/onbld/Checks/WsCheck.pyc \
+ mode=0444
file path=opt/onbld/lib/python$(PYTHON_VERSION)/onbld/Checks/__init__.py \
mode=0444
file path=opt/onbld/lib/python$(PYTHON_VERSION)/onbld/Checks/__init__.pyc \
diff --git a/usr/src/tools/onbld/Checks/Makefile b/usr/src/tools/onbld/Checks/Makefile
index 02f13b8351..bca61be9ee 100644
--- a/usr/src/tools/onbld/Checks/Makefile
+++ b/usr/src/tools/onbld/Checks/Makefile
@@ -44,11 +44,12 @@ PYSRCS = \
Mapfile.py \
ProcessCheck.py \
SpellCheck.py \
+ WsCheck.py \
__init__.py
PYOBJS = $(PYSRCS:%.py=%.pyc)
PYTOPDIR = $(ROOTONBLDLIB)
-PYMODDIR = onbld/Checks
+PYMODDIR = onbld/Checks
include ../../Makefile.python
diff --git a/usr/src/tools/onbld/Checks/WsCheck.py b/usr/src/tools/onbld/Checks/WsCheck.py
new file mode 100644
index 0000000000..b05402e68c
--- /dev/null
+++ b/usr/src/tools/onbld/Checks/WsCheck.py
@@ -0,0 +1,46 @@
+#! /usr/bin/python
+#
+# This file and its contents are supplied under the terms of the
+# Common Development and Distribution License ("CDDL"), version 1.0.
+# You may only use this file in accordance with the terms of version
+# 1.0 of the CDDL.
+#
+# A full copy of the text of the CDDL should have accompanied this
+# source. A copy of the CDDL is also available via the Internet at
+# http://www.illumos.org/license/CDDL.
+#
+
+#
+# Copyright 2018 Gordon Ross <gordon.w.ross@gmail.com>
+#
+
+#
+# Check file for whitespace issues
+# (space tab, trailing space)
+#
+
+
+import time, re, sys
+
+stMsg = 'space tab sequences'
+twsMsg = 'has trailing spaces'
+
+def err(stream, fname, lineno, msg):
+ stream.write("%s:%d: %s\n" % (fname, lineno, msg))
+
+def wscheck(fh, output=sys.stderr):
+ lineno = 1
+ ret = 0
+
+ fname = fh.name
+
+ for line in fh:
+ if re.search(r' \t', line):
+ err(output, fname, lineno, stMsg);
+ ret = 1
+ if re.search(r'[ \t]$', line):
+ err(output, fname, lineno, twsMsg);
+ ret = 1
+ lineno += 1
+
+ return ret
diff --git a/usr/src/tools/onbld/Checks/__init__.py b/usr/src/tools/onbld/Checks/__init__.py
index c088df4ead..a8bca05d55 100644
--- a/usr/src/tools/onbld/Checks/__init__.py
+++ b/usr/src/tools/onbld/Checks/__init__.py
@@ -42,4 +42,5 @@ __all__ = [
'Keywords',
'ManLint',
'Mapfile',
- 'SpellCheck']
+ 'SpellCheck',
+ 'WsCheck']
diff --git a/usr/src/tools/scripts/Makefile b/usr/src/tools/scripts/Makefile
index e797213bcd..be65637a17 100644
--- a/usr/src/tools/scripts/Makefile
+++ b/usr/src/tools/scripts/Makefile
@@ -68,6 +68,7 @@ PYFILES= \
hdrchk \
mapfilechk \
validate_pkg \
+ wscheck \
wsdiff
SCRIPTLINKS= \
@@ -158,7 +159,7 @@ bldenv: bldenv.sh stdenv.sh
shlintout="$$( /usr/bin/ksh93 -n "$@" 2>&1 )" ; \
[[ "$${shlintout}" != "" ]] && \
{ print -r -- "$${shlintout}" ; false ; } || true
- $(CHMOD) +x "$@"
+ $(CHMOD) +x "$@"
bldenv.1onbld: bldenv
$(RM) "$@"
@@ -170,7 +171,7 @@ bldenv.1onbld: bldenv
nightly: nightly.sh stdenv.sh
$(RM) "$@"
sed -e '/# STDENV_START/ r stdenv.sh' nightly.sh > nightly
- $(CHMOD) +x "$@"
+ $(CHMOD) +x "$@"
include ../Makefile.targ
diff --git a/usr/src/tools/scripts/git-pbchk.py b/usr/src/tools/scripts/git-pbchk.py
index d8a3e19bf3..4a3533156d 100644
--- a/usr/src/tools/scripts/git-pbchk.py
+++ b/usr/src/tools/scripts/git-pbchk.py
@@ -48,7 +48,7 @@ sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
sys.path.insert(2, os.path.join(os.path.dirname(__file__), ".."))
from onbld.Scm import Ignore
-from onbld.Checks import Comments, Copyright, CStyle, HdrChk
+from onbld.Checks import Comments, Copyright, CStyle, HdrChk, WsCheck
from onbld.Checks import JStyle, Keywords, ManLint, Mapfile, SpellCheck
@@ -122,7 +122,7 @@ def git_parent_branch(branch):
if not branch:
return None
- p = git(["for-each-ref", "--format=%(refname:short) %(upstream:short)",
+ p = git(["for-each-ref", "--format=%(refname:short) %(upstream:short)",
"refs/heads/"])
if not p:
@@ -310,6 +310,14 @@ def keywords(root, parent, flist, output):
fh.close()
return ret
+def wscheck(root, parent, flist, output):
+ ret = 0
+ output.write("white space nits:\n")
+ for f in flist():
+ fh = open(f, 'r')
+ ret |= WsCheck.wscheck(fh, output=output)
+ fh.close()
+ return ret
def run_checks(root, parent, cmds, paths='', opts={}):
"""Run the checks given in 'cmds', expected to have well-known signatures,
@@ -343,7 +351,8 @@ def nits(root, parent, paths):
jstyle,
keywords,
manlint,
- mapfilechk]
+ mapfilechk,
+ wscheck]
run_checks(root, parent, cmds, paths)
@@ -355,7 +364,8 @@ def pbchk(root, parent, paths):
jstyle,
keywords,
manlint,
- mapfilechk]
+ mapfilechk,
+ wscheck]
run_checks(root, parent, cmds)
diff --git a/usr/src/tools/scripts/wscheck.py b/usr/src/tools/scripts/wscheck.py
new file mode 100644
index 0000000000..ce85b8971f
--- /dev/null
+++ b/usr/src/tools/scripts/wscheck.py
@@ -0,0 +1,54 @@
+#!@PYTHON@
+#
+# CDDL HEADER START
+#
+# The contents of this file are subject to the terms of the
+# Common Development and Distribution License (the "License").
+# You may not use this file except in compliance with the License.
+#
+# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+# or http://www.opensolaris.org/os/licensing.
+# See the License for the specific language governing permissions
+# and limitations under the License.
+#
+# When distributing Covered Code, include this CDDL HEADER in each
+# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+# If applicable, add the following below this CDDL HEADER, with the
+# fields enclosed by brackets "[]" replaced with your own identifying
+# information: Portions Copyright [yyyy] [name of copyright owner]
+#
+# CDDL HEADER END
+#
+
+#
+# Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+#
+
+#
+# Check file for whitespace issues
+# (space tab, trailing space)
+#
+
+import sys, os
+
+sys.path.insert(1, os.path.join(os.path.dirname(__file__), "..", "lib",
+ "python%d.%d" % sys.version_info[:2]))
+
+# Allow running from the source tree, using the modules in the source tree
+sys.path.insert(2, os.path.join(os.path.dirname(__file__), '..'))
+
+from onbld.Checks.WsCheck import wscheck
+
+ret = 0
+for filename in sys.argv[1:]:
+ try:
+ fh = open(filename, 'r')
+ except IOError, e:
+ sys.stderr.write("failed to open '%s': %s\n" %
+ (e.filename, e.strerror))
+ continue
+
+ ret |= wscheck(fh, output=sys.stderr)
+ fh.close()
+
+sys.exit(ret)