Skip to content

Commit 706be5b

Browse files
committedFeb 5, 2015
Auto merge of #21619 - brson:featureck-tidy, r=alexcrichton
Builds on my [feature staging PR](#21248) to clean up the tidy scripts a bit, and make them much faster (6s vs ~40s). Adds make rules 'tidy-basic', 'tidy-binaries', 'tidy-errors' and 'tidy-features'. This is the output of `make tidy` here: ``` cfg: version 1.0.0-dev (a8c878d 2015-01-25 01:49:14 -0800) cfg: build triple x86_64-unknown-linux-gnu cfg: host triples x86_64-unknown-linux-gnu cfg: target triples x86_64-unknown-linux-gnu cfg: host for x86_64-unknown-linux-gnu is x86_64 cfg: os for x86_64-unknown-linux-gnu is unknown-linux-gnu cfg: good valgrind for x86_64-unknown-linux-gnu is 1 cfg: using CC=gcc (CFG_CC) cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS) cfg: valgrind-rpass command set to "/usr/bin/valgrind" --error-exitcode=100 --soname-synonyms=somalloc=NONE --quiet --suppressions=/home/brian/dev/rust3/src/etc/x86.supp --tool=memcheck --leak-check=full cfg: no lualatex found, deferring to xelatex cfg: no xelatex found, deferring to pdflatex cfg: no pdflatex found, disabling LaTeX docs cfg: no pandoc found, omitting PDF and EPUB docs cfg: including test rules cfg: javac not available, skipping lexer test... check: formatting * linted .rs files: 4948 * linted .py files: 27 * linted .js files: 2 * linted .sh files: 5 * linted .pl files: 0 * linted .c files: 28 * linted .h files: 3 * other linted files: 0 * total lines of code: 481217 * total non-blank lines of code: 423682 check: binaries check: extended errors * 249 error codes * highest error code: E0315 check: feature sanity * advanced_slice_patterns lang unstable None * alloc lib unstable None * asm lang unstable None * associated_types lang stable 1.0.0 * box_syntax lang unstable None * collections lib unstable None * concat_idents lang unstable None * core lib unstable None * default_type_params lang stable 1.0.0 * globs lang stable 1.0.0 * hash lib unstable None * if_let lang stable 1.0.0 * import_shadowing lang unstable None * int_uint lang unstable None * intrinsics lang unstable None * io lib unstable None * issue_5723_bootstrap lang stable 1.0.0 * lang_items lang unstable None * link_args lang unstable None * link_llvm_intrinsics lang unstable None * linkage lang unstable None * log_syntax lang unstable None * macro_rules lang stable 1.0.0 * main lang unstable None * managed_boxes lang unstable None * non_ascii_idents lang unstable None * old_impl_check lang unstable None * old_orphan_check lang unstable None * on_unimplemented lang unstable None * opt_out_copy lang unstable None * optin_builtin_traits lang unstable None * os lib unstable None * path lib unstable None * phase lang unstable None * plugin lang unstable None * plugin_registrar lang unstable None * quad_precision_float lang unstable None * quote lang unstable None * rand lib unstable None * rust1 lib stable 1.0.0 * rustc_diagnostic_macros lang unstable None * rustc_private lib unstable None * rustdoc lib unstable None * simd lang unstable None * simd_ffi lang unstable None * slicing_syntax lang unstable None * staged_api lang unstable None * start lang unstable None * std_misc lib unstable None * struct_inherit lang unstable None * struct_variant lang stable 1.0.0 * test lib unstable None * test_accepted_feature lang stable 1.0.0 * test_removed_feature lang unstable None * thread_local lang unstable None * trace_macros lang unstable None * tuple_indexing lang stable 1.0.0 * unboxed_closures lang unstable None * unicode lib unstable None * unsafe_destructor lang unstable None * visible_private_types lang unstable None * while_let lang stable 1.0.0 ``` There's a lot of informational output now, which comes after things like 'NOTE's.
2 parents 99f6206 + d0e82a6 commit 706be5b

File tree

32 files changed

+205
-120
lines changed

32 files changed

+205
-120
lines changed
 

‎Makefile.in

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@
5959
# * check-stage$(stage)-$(crate) - Test a crate in a specific stage
6060
# * check-stage$(stage)-{rpass,rfail,cfail,rmake,...} - Run tests in src/test/
6161
# * check-stage1-T-$(target)-H-$(host) - Run cross-compiled-tests
62+
# * tidy-basic - show file / line stats
63+
# * tidy-errors - show the highest rustc error code
64+
# * tidy-features - show the status of language and lib features
6265
#
6366
# Then mix in some of these environment variables to harness the
6467
# ultimate power of The Rust Build System.

‎mk/main.mk

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ endif
7272
# numbers and dots here
7373
CFG_VERSION_WIN = $(CFG_RELEASE_NUM)
7474

75+
CFG_INFO := $(info cfg: version $(CFG_VERSION))
7576

7677
######################################################################
7778
# More configuration
@@ -179,6 +180,7 @@ endif
179180

180181
ifndef CFG_DISABLE_VALGRIND_RPASS
181182
$(info cfg: enabling valgrind run-pass tests (CFG_ENABLE_VALGRIND_RPASS))
183+
$(info cfg: valgrind-rpass command set to $(CFG_VALGRIND))
182184
CFG_VALGRIND_RPASS :=$(CFG_VALGRIND)
183185
else
184186
CFG_VALGRIND_RPASS :=

‎mk/tests.mk

+23-51
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,8 @@ $(foreach file,$(wildcard $(S)src/doc/trpl/*.md), \
162162
######################################################################
163163

164164
# The main testing target. Tests lots of stuff.
165-
check: cleantmptestlogs cleantestlibs check-notidy tidy
165+
check: cleantmptestlogs cleantestlibs all check-stage2 tidy
166+
$(Q)$(CFG_PYTHON) $(S)src/etc/check-summary.py tmp/*.log
166167

167168
# As above but don't bother running tidy.
168169
check-notidy: cleantmptestlogs cleantestlibs all check-stage2
@@ -235,57 +236,24 @@ cleantestlibs:
235236
######################################################################
236237

237238
ifdef CFG_NOTIDY
239+
.PHONY: tidy
238240
tidy:
239241
else
240242

241-
ALL_CS := $(wildcard $(S)src/rt/*.cpp \
242-
$(S)src/rt/*/*.cpp \
243-
$(S)src/rt/*/*/*.cpp \
244-
$(S)src/rustllvm/*.cpp)
245-
ALL_CS := $(filter-out $(S)src/rt/miniz.cpp \
246-
$(wildcard $(S)src/rt/hoedown/src/*.c) \
247-
$(wildcard $(S)src/rt/hoedown/bin/*.c) \
248-
,$(ALL_CS))
249-
ALL_HS := $(wildcard $(S)src/rt/*.h \
250-
$(S)src/rt/*/*.h \
251-
$(S)src/rt/*/*/*.h \
252-
$(S)src/rustllvm/*.h)
253-
ALL_HS := $(filter-out $(S)src/rt/valgrind/valgrind.h \
254-
$(S)src/rt/valgrind/memcheck.h \
255-
$(S)src/rt/msvc/typeof.h \
256-
$(S)src/rt/msvc/stdint.h \
257-
$(S)src/rt/msvc/inttypes.h \
258-
$(wildcard $(S)src/rt/hoedown/src/*.h) \
259-
$(wildcard $(S)src/rt/hoedown/bin/*.h) \
260-
,$(ALL_HS))
261-
262243
# Run the tidy script in multiple parts to avoid huge 'echo' commands
263-
tidy:
244+
.PHONY: tidy
245+
tidy: tidy-basic tidy-binaries tidy-errors tidy-features
246+
247+
endif
248+
249+
.PHONY: tidy-basic
250+
tidy-basic:
264251
@$(call E, check: formatting)
265-
$(Q)find $(S)src -name '*.r[sc]' \
266-
-and -not -regex '^$(S)src/jemalloc.*' \
267-
-and -not -regex '^$(S)src/libuv.*' \
268-
-and -not -regex '^$(S)src/llvm.*' \
269-
-and -not -regex '^$(S)src/gyp.*' \
270-
-and -not -regex '^$(S)src/libbacktrace.*' \
271-
-print0 \
272-
| xargs -0 -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
273-
$(Q)find $(S)src/etc -name '*.py' \
274-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
275-
$(Q)find $(S)src/doc -name '*.js' \
276-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
277-
$(Q)find $(S)src/etc -name '*.sh' \
278-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
279-
$(Q)find $(S)src/etc -name '*.pl' \
280-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
281-
$(Q)find $(S)src/etc -name '*.c' \
282-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
283-
$(Q)find $(S)src/etc -name '*.h' \
284-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
285-
$(Q)echo $(ALL_CS) \
286-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
287-
$(Q)echo $(ALL_HS) \
288-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
252+
$(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
253+
254+
.PHONY: tidy-binaries
255+
tidy-binaries:
256+
@$(call E, check: binaries)
289257
$(Q)find $(S)src -type f -perm +a+x \
290258
-not -name '*.rs' -and -not -name '*.py' \
291259
-and -not -name '*.sh' \
@@ -300,11 +268,16 @@ tidy:
300268
| grep '^$(S)src/libbacktrace' -v \
301269
| grep '^$(S)src/rust-installer' -v \
302270
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
303-
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
304-
$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
305271

272+
.PHONY: tidy-errors
273+
tidy-errors:
274+
@$(call E, check: extended errors)
275+
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
306276

307-
endif
277+
.PHONY: tidy-features
278+
tidy-features:
279+
@$(call E, check: feature sanity)
280+
$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
308281

309282

310283
######################################################################
@@ -639,7 +612,6 @@ CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) := \
639612

640613
ifdef CFG_VALGRIND_RPASS
641614
ifdef GOOD_VALGRIND_$(2)
642-
$(info cfg: valgrind-path set to $(CFG_VALGRIND_RPASS))
643615
CTEST_COMMON_ARGS$(1)-T-$(2)-H-$(3) += --valgrind-path "$(CFG_VALGRIND_RPASS)"
644616
endif
645617
endif

‎src/etc/errorck.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
import os
1616
import re
1717

18+
if len(sys.argv) < 2:
19+
print "usage: errorck.py <src-dir>"
20+
sys.exit(1)
21+
1822
src_dir = sys.argv[1]
1923
errcode_map = {}
2024
error_re = re.compile("(E\d\d\d\d)")
@@ -54,8 +58,10 @@
5458
print("{1}: {2}\n{3}".format(*entry))
5559
errors = True
5660

57-
print("{0} error codes".format(len(errcode_map)))
58-
print("highest error code: " + max(all_errors))
61+
print
62+
print("* {0} error codes".format(len(errcode_map)))
63+
print("* highest error code: " + max(all_errors))
64+
print
5965

6066
if errors:
6167
sys.exit(1)

‎src/etc/featureck.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020

2121
import sys, os, re
2222

23+
if len(sys.argv) < 2:
24+
print "usage: featurkck.py <src-dir>"
25+
sys.exit(1)
26+
2327
src_dir = sys.argv[1]
2428

2529
# Features that are allowed to exist in both the language and the library
@@ -234,10 +238,8 @@
234238

235239
lines.sort()
236240

237-
print
238-
print "Rust feature summary:"
239241
print
240242
for line in lines:
241-
print line
243+
print "* " + line
242244
print
243245

‎src/etc/licenseck.py

-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
\\1 except according to those terms.""")
2323

2424
exceptions = [
25-
"rt/rust_android_dummy.cpp", # BSD, chromium
26-
"rt/rust_android_dummy.h", # BSD, chromium
27-
"rt/isaac/randport.cpp", # public domain
28-
"rt/isaac/rand.h", # public domain
29-
"rt/isaac/standard.h", # public domain
3025
"libstd/sync/mpsc/mpsc_queue.rs", # BSD
3126
"libstd/sync/mpsc/spsc_queue.rs", # BSD
3227
"test/bench/shootout-binarytrees.rs", # BSD

‎src/etc/tidy.py

+127-50
Original file line numberDiff line numberDiff line change
@@ -51,78 +51,155 @@ def do_license_check(name, contents):
5151
if not check_license(name, contents):
5252
report_error_name_no(name, 1, "incorrect license")
5353

54-
55-
file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
56-
and (not ".#" in s)]
57-
5854
current_name = ""
5955
current_contents = ""
6056
check_tab = True
6157
check_cr = True
6258
check_linelength = True
6359

60+
if len(sys.argv) < 2:
61+
print "usage: tidy.py <src-dir>"
62+
sys.exit(1)
63+
64+
src_dir = sys.argv[1]
6465

6566
try:
66-
for line in fileinput.input(file_names,
67+
count_lines = 0
68+
count_non_blank_lines = 0
69+
70+
interesting_files = ['.rs', '.py', '.js', '.sh', '.c', '.h']
71+
72+
file_counts = {ext: 0 for ext in interesting_files}
73+
file_counts['other'] = 0
74+
75+
def update_counts(current_name):
76+
global file_counts
77+
_, ext = os.path.splitext(current_name)
78+
79+
if ext in file_counts:
80+
file_counts[ext] += 1
81+
else:
82+
file_counts['other'] += 1
83+
84+
all_paths = set()
85+
86+
for (dirpath, dirnames, filenames) in os.walk(src_dir):
87+
88+
# Skip some third-party directories
89+
skippable_dirs = {
90+
'src/jemalloc',
91+
'src/llvm',
92+
'src/gyp',
93+
'src/libbacktrace',
94+
'src/libuv',
95+
'src/compiler-rt',
96+
'src/rt/hoedown',
97+
'src/rustllvm',
98+
'src/rt/valgrind',
99+
'src/rt/msvc',
100+
'src/rust-installer'
101+
}
102+
103+
if any(d in dirpath for d in skippable_dirs):
104+
continue
105+
106+
def interesting_file(f):
107+
if "miniz.c" in f \
108+
or "jquery" in f \
109+
or "rust_android_dummy" in f:
110+
return False
111+
112+
return any(os.path.splitext(f)[1] == ext for ext in interesting_files)
113+
114+
file_names = [os.path.join(dirpath, f) for f in filenames
115+
if interesting_file(f)
116+
and not f.endswith("_gen.rs")
117+
and not ".#" is f]
118+
119+
if not file_names:
120+
continue
121+
122+
for line in fileinput.input(file_names,
67123
openhook=fileinput.hook_encoded("utf-8")):
68124

69-
if "tidy.py" not in fileinput.filename():
125+
filename = fileinput.filename()
126+
127+
if "tidy.py" not in filename:
128+
if "TODO" in line:
129+
report_err("TODO is deprecated; use FIXME")
130+
match = re.match(r'^.*/(\*|/!?)\s*XXX', line)
131+
if match:
132+
report_err("XXX is no longer necessary, use FIXME")
133+
match = re.match(r'^.*//\s*(NOTE.*)$', line)
134+
if match and "TRAVIS" not in os.environ:
135+
m = match.group(1)
136+
if "snap" in m.lower():
137+
report_warn(match.group(1))
138+
match = re.match(r'^.*//\s*SNAP\s+(\w+)', line)
139+
if match:
140+
hsh = match.group(1)
141+
date, rev = snapshot.curr_snapshot_rev()
142+
if not hsh.startswith(rev):
143+
report_err("snapshot out of date (" + date
144+
+ "): " + line)
145+
else:
146+
if "SNAP" in line:
147+
report_warn("unmatched SNAP line: " + line)
148+
70149
if cr_flag in line:
71150
check_cr = False
72151
if tab_flag in line:
73152
check_tab = False
74153
if linelength_flag in line:
75154
check_linelength = False
76-
if "TODO" in line:
77-
report_err("TODO is deprecated; use FIXME")
78-
match = re.match(r'^.*/(\*|/!?)\s*XXX', line)
79-
if match:
80-
report_err("XXX is no longer necessary, use FIXME")
81-
match = re.match(r'^.*//\s*(NOTE.*)$', line)
82-
if match and "TRAVIS" not in os.environ:
83-
m = match.group(1)
84-
if "snap" in m.lower():
85-
report_warn(match.group(1))
86-
match = re.match(r'^.*//\s*SNAP\s+(\w+)', line)
87-
if match:
88-
hsh = match.group(1)
89-
date, rev = snapshot.curr_snapshot_rev()
90-
if not hsh.startswith(rev):
91-
report_err("snapshot out of date (" + date
92-
+ "): " + line)
93-
else:
94-
if "SNAP" in line:
95-
report_warn("unmatched SNAP line: " + line)
96-
97-
if check_tab and ('\t' in line and
98-
"Makefile" not in fileinput.filename()):
99-
report_err("tab character")
100-
if check_cr and not autocrlf and '\r' in line:
101-
report_err("CR character")
102-
if line.endswith(" \n") or line.endswith("\t\n"):
103-
report_err("trailing whitespace")
104-
line_len = len(line)-2 if autocrlf else len(line)-1
105-
106-
if check_linelength and line_len > cols:
107-
report_err("line longer than %d chars" % cols)
108-
109-
if fileinput.isfirstline() and current_name != "":
110-
do_license_check(current_name, current_contents)
111-
112-
if fileinput.isfirstline():
113-
current_name = fileinput.filename()
114-
current_contents = ""
115-
check_cr = True
116-
check_tab = True
117-
check_linelength = True
118-
119-
current_contents += line
155+
156+
if check_tab and ('\t' in line and
157+
"Makefile" not in filename):
158+
report_err("tab character")
159+
if check_cr and not autocrlf and '\r' in line:
160+
report_err("CR character")
161+
if line.endswith(" \n") or line.endswith("\t\n"):
162+
report_err("trailing whitespace")
163+
line_len = len(line)-2 if autocrlf else len(line)-1
164+
165+
if check_linelength and line_len > cols:
166+
report_err("line longer than %d chars" % cols)
167+
168+
if fileinput.isfirstline():
169+
# This happens at the end of each file except the last.
170+
if current_name != "":
171+
update_counts(current_name)
172+
assert len(current_contents) > 0
173+
do_license_check(current_name, current_contents)
174+
175+
current_name = filename
176+
current_contents = ""
177+
check_cr = True
178+
check_tab = True
179+
check_linelength = True
180+
181+
# Put a reasonable limit on the amount of header data we use for
182+
# the licenseck
183+
if len(current_contents) < 1000:
184+
current_contents += line
185+
186+
count_lines += 1
187+
if line.strip():
188+
count_non_blank_lines += 1
120189

121190
if current_name != "":
191+
update_counts(current_name)
192+
assert len(current_contents) > 0
122193
do_license_check(current_name, current_contents)
123194

124195
except UnicodeDecodeError as e:
125196
report_err("UTF-8 decoding error " + str(e))
126197

198+
print
199+
for ext in file_counts:
200+
print "* linted " + str(file_counts[ext]) + " " + ext + " files"
201+
print "* total lines of code: " + str(count_lines)
202+
print "* total non-blank lines of code: " + str(count_non_blank_lines)
203+
print
127204

128205
sys.exit(err)

0 commit comments

Comments
 (0)
Please sign in to comment.