Skip to content

Commit 290b79c

Browse files
committed
Clean up tidy scripts, coverage, performance
This restructures tidy.py to walk the tree itself, and improves performance considerably by not loading entire files into buffers for licenseck. Splits build rules into 'tidy', 'tidy-basic', 'tidy-binaries', 'tidy-errors', 'tidy-features'.
1 parent 0e16ad8 commit 290b79c

File tree

28 files changed

+196
-106
lines changed

28 files changed

+196
-106
lines changed

mk/tests.mk

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -235,30 +235,10 @@ cleantestlibs:
235235
######################################################################
236236

237237
ifdef CFG_NOTIDY
238+
.PHONY: tidy
238239
tidy:
239240
else
240241

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-
262242
# Run the tidy script in multiple parts to avoid huge 'echo' commands
263243
.PHONY: tidy
264244
tidy: tidy-basic tidy-binaries tidy-errors tidy-features
@@ -268,30 +248,7 @@ endif
268248
.PHONY: tidy-basic
269249
tidy-basic:
270250
@$(call E, check: formatting)
271-
$(Q)find $(S)src -name '*.r[sc]' \
272-
-and -not -regex '^$(S)src/jemalloc.*' \
273-
-and -not -regex '^$(S)src/libuv.*' \
274-
-and -not -regex '^$(S)src/llvm.*' \
275-
-and -not -regex '^$(S)src/gyp.*' \
276-
-and -not -regex '^$(S)src/libbacktrace.*' \
277-
-print0 \
278-
| xargs -0 -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
279-
$(Q)find $(S)src/etc -name '*.py' \
280-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
281-
$(Q)find $(S)src/doc -name '*.js' \
282-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
283-
$(Q)find $(S)src/etc -name '*.sh' \
284-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
285-
$(Q)find $(S)src/etc -name '*.pl' \
286-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
287-
$(Q)find $(S)src/etc -name '*.c' \
288-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
289-
$(Q)find $(S)src/etc -name '*.h' \
290-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
291-
$(Q)echo $(ALL_CS) \
292-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
293-
$(Q)echo $(ALL_HS) \
294-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
251+
$(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
295252

296253
.PHONY: tidy-binaries
297254
tidy-binaries:

src/etc/errorck.py

Lines changed: 4 additions & 0 deletions
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)")

src/etc/featureck.py

Lines changed: 4 additions & 0 deletions
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

src/etc/licenseck.py

Lines changed: 0 additions & 5 deletions
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

Lines changed: 155 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -51,78 +51,184 @@ 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_rs = 0
68+
count_py = 0
69+
count_js = 0
70+
count_sh = 0
71+
count_pl = 0
72+
count_c = 0
73+
count_h = 0
74+
count_other = 0
75+
76+
count_lines = 0
77+
count_non_blank_lines = 0
78+
79+
def update_counts(current_name):
80+
global count_rs
81+
global count_py
82+
global count_js
83+
global count_sh
84+
global count_pl
85+
global count_c
86+
global count_h
87+
global count_other
88+
89+
if current_name.endswith(".rs"):
90+
count_rs += 1
91+
if current_name.endswith(".py"):
92+
count_py += 1
93+
if current_name.endswith(".js"):
94+
count_js += 1
95+
if current_name.endswith(".sh"):
96+
count_sh += 1
97+
if current_name.endswith(".pl"):
98+
count_pl += 1
99+
if current_name.endswith(".c"):
100+
count_c += 1
101+
if current_name.endswith(".h"):
102+
count_h += 1
103+
104+
all_paths = set()
105+
106+
for (dirpath, dirnames, filenames) in os.walk(src_dir):
107+
108+
# Skip some third-party directories
109+
if "src/jemalloc" in dirpath: continue
110+
if "src/llvm" in dirpath: continue
111+
if "src/gyp" in dirpath: continue
112+
if "src/libbacktrace" in dirpath: continue
113+
if "src/compiler-rt" in dirpath: continue
114+
if "src/rt/hoedown" in dirpath: continue
115+
if "src/rustllvm" in dirpath: continue
116+
if "src/rt/valgrind" in dirpath: continue
117+
if "src/rt/msvc" in dirpath: continue
118+
if "src/rust-installer" in dirpath: continue
119+
120+
def interesting_file(f):
121+
if "miniz.c" in f \
122+
or "jquery" in f \
123+
or "rust_android_dummy" in f:
124+
return False
125+
126+
if f.endswith(".rs") \
127+
or f.endswith(".py") \
128+
or f.endswith(".js") \
129+
or f.endswith(".sh") \
130+
or f.endswith(".pl") \
131+
or f.endswith(".c") \
132+
or f.endswith(".h") :
133+
return True
134+
else:
135+
return False
136+
137+
file_names = [os.path.join(dirpath, f) for f in filenames
138+
if interesting_file(f)
139+
and not f.endswith("_gen.rs")
140+
and not ".#" is f]
141+
142+
if not file_names:
143+
continue
144+
145+
for line in fileinput.input(file_names,
67146
openhook=fileinput.hook_encoded("utf-8")):
68147

69-
if "tidy.py" not in fileinput.filename():
148+
filename = fileinput.filename()
149+
150+
if "tidy.py" not in filename:
151+
if "TODO" in line:
152+
report_err("TODO is deprecated; use FIXME")
153+
match = re.match(r'^.*/(\*|/!?)\s*XXX', line)
154+
if match:
155+
report_err("XXX is no longer necessary, use FIXME")
156+
match = re.match(r'^.*//\s*(NOTE.*)$', line)
157+
if match and "TRAVIS" not in os.environ:
158+
m = match.group(1)
159+
if "snap" in m.lower():
160+
report_warn(match.group(1))
161+
match = re.match(r'^.*//\s*SNAP\s+(\w+)', line)
162+
if match:
163+
hsh = match.group(1)
164+
date, rev = snapshot.curr_snapshot_rev()
165+
if not hsh.startswith(rev):
166+
report_err("snapshot out of date (" + date
167+
+ "): " + line)
168+
else:
169+
if "SNAP" in line:
170+
report_warn("unmatched SNAP line: " + line)
171+
70172
if cr_flag in line:
71173
check_cr = False
72174
if tab_flag in line:
73175
check_tab = False
74176
if linelength_flag in line:
75177
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
118178

119-
current_contents += line
179+
if check_tab and ('\t' in line and
180+
"Makefile" not in filename):
181+
report_err("tab character")
182+
if check_cr and not autocrlf and '\r' in line:
183+
report_err("CR character")
184+
if line.endswith(" \n") or line.endswith("\t\n"):
185+
report_err("trailing whitespace")
186+
line_len = len(line)-2 if autocrlf else len(line)-1
187+
188+
if check_linelength and line_len > cols:
189+
report_err("line longer than %d chars" % cols)
190+
191+
if fileinput.isfirstline():
192+
# This happens at the end of each file except the last.
193+
if current_name != "":
194+
update_counts(current_name)
195+
assert len(current_contents) > 0
196+
do_license_check(current_name, current_contents)
197+
198+
current_name = filename
199+
current_contents = ""
200+
check_cr = True
201+
check_tab = True
202+
check_linelength = True
203+
204+
# Put a reasonable limit on the amount of header data we use for
205+
# the licenseck
206+
if len(current_contents) < 1000:
207+
current_contents += line
208+
209+
count_lines += 1
210+
if line.strip():
211+
count_non_blank_lines += 1
120212

121213
if current_name != "":
214+
update_counts(current_name)
215+
assert len(current_contents) > 0
122216
do_license_check(current_name, current_contents)
123217

124218
except UnicodeDecodeError as e:
125219
report_err("UTF-8 decoding error " + str(e))
126220

221+
print
222+
print "* linted .rs files: " + str(count_rs)
223+
print "* linted .py files: " + str(count_py)
224+
print "* linted .js files: " + str(count_js)
225+
print "* linted .sh files: " + str(count_sh)
226+
print "* linted .pl files: " + str(count_pl)
227+
print "* linted .c files: " + str(count_c)
228+
print "* linted .h files: " + str(count_h)
229+
print "* other linted files: " + str(count_other)
230+
print "* total lines of code: " + str(count_lines)
231+
print "* total non-blank lines of code: " + str(count_non_blank_lines)
232+
print
127233

128234
sys.exit(err)

src/grammar/check.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/sh
22

3+
# ignore-license
4+
35
# Run the reference lexer against libsyntax and compare the tokens and spans.
46
# If "// ignore-lexer-test" is present in the file, it will be ignored.
57

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// ignore-license
12
int foo() { return 0; }
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
// ignore-license
12
int foo() { return 0; }

src/test/run-make/c-link-to-rust-dylib/bar.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-license
12
void foo();
23

34
int main() {

src/test/run-make/c-link-to-rust-staticlib/bar.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// ignore-license
12
void foo();
23

34
int main() {

0 commit comments

Comments
 (0)