Skip to content

Commit f8344f0

Browse files
committed
tidy.py: move the file matching logic to python
Performance: 30% faster (5.1s instead of 7.2s)
1 parent e07e49e commit f8344f0

2 files changed

Lines changed: 27 additions & 40 deletions

File tree

‎mk/tests.mk‎

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -212,44 +212,9 @@ ifdef CFG_NOTIDY
212212
tidy:
213213
else
214214

215-
ALL_CS := $(wildcard $(S)src/rt/*.cpp \
216-
$(S)src/rt/*/*.cpp \
217-
$(S)src/rt/*/*/*.cpp \
218-
$(S)srcrustllvm/*.cpp)
219-
ALL_CS := $(filter-out $(S)src/rt/bigint/bigint_ext.cpp \
220-
$(S)src/rt/bigint/bigint_int.cpp \
221-
$(S)src/rt/miniz.cpp \
222-
$(S)src/rt/linenoise/linenoise.c \
223-
$(S)src/rt/linenoise/utf8.c \
224-
,$(ALL_CS))
225-
ALL_HS := $(wildcard $(S)src/rt/*.h \
226-
$(S)src/rt/*/*.h \
227-
$(S)src/rt/*/*/*.h \
228-
$(S)srcrustllvm/*.h)
229-
ALL_HS := $(filter-out $(S)src/rt/vg/valgrind.h \
230-
$(S)src/rt/vg/memcheck.h \
231-
$(S)src/rt/uthash/uthash.h \
232-
$(S)src/rt/uthash/utlist.h \
233-
$(S)src/rt/msvc/typeof.h \
234-
$(S)src/rt/msvc/stdint.h \
235-
$(S)src/rt/msvc/inttypes.h \
236-
$(S)src/rt/bigint/bigint.h \
237-
$(S)src/rt/linenoise/linenoise.h \
238-
$(S)src/rt/linenoise/utf8.h \
239-
,$(ALL_HS))
240-
241-
# Run the tidy script in multiple parts to avoid huge 'echo' commands
242215
tidy:
243216
@$(call E, check: formatting)
244-
$(Q)find $(S)src -name '*.r[sc]' \
245-
| grep '^$(S)src/test' -v \
246-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
247-
$(Q)find $(S)src/etc -name '*.py' \
248-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
249-
$(Q)echo $(ALL_CS) \
250-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
251-
$(Q)echo $(ALL_HS) \
252-
| xargs -n 10 $(CFG_PYTHON) $(S)src/etc/tidy.py
217+
$(CFG_PYTHON) src/etc/tidy.py --srcdir $(S)
253218

254219
endif
255220

‎src/etc/tidy.py‎

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env python
22
# xfail-license
33

4-
import sys, fileinput, subprocess, re
4+
import sys, fileinput, subprocess, re, argparse, os
55
from licenseck import *
66

77
err=0
@@ -32,9 +32,31 @@ def do_license_check(name, contents):
3232
if not check_license(name, contents):
3333
report_error_name_no(name, 1, "incorrect license")
3434

35-
36-
file_names = [s for s in sys.argv[1:] if (not s.endswith("_gen.rs"))
37-
and (not ".#" in s)]
35+
parser = argparse.ArgumentParser(description='Tidy source files.')
36+
parser.add_argument('--srcdir')
37+
args = parser.parse_args()
38+
39+
file_names = []
40+
for (dirpath, dirnames, filenames) in os.walk(os.path.join(args.srcdir, 'src')):
41+
for name in filenames:
42+
if name.endswith("_gen.rs") or ".#" in name:
43+
continue
44+
def in_dir(d):
45+
return dirpath.startswith(os.path.join(args.srcdir, d))
46+
def add():
47+
file_names.append(os.path.join(dirpath, name))
48+
ext = os.path.splitext(name)[1]
49+
if ext in ['.rs', '.rc'] and not in_dir('src/test'):
50+
add()
51+
elif ext in ['.py'] and in_dir('src/etc'):
52+
add()
53+
elif ext in ['.c', '.cpp', '.h']:
54+
if in_dir('src/rt/jemalloc') or in_dir('src/rt/linenoise') \
55+
or in_dir('src/rt/vg') or in_dir('src/rt/msvc'):
56+
continue
57+
if in_dir('src/rt') or in_dir('src/rustllvm'):
58+
if name != 'miniz.cpp':
59+
add()
3860

3961
current_name = ""
4062
current_contents = ""

0 commit comments

Comments
 (0)