Skip to content

Commit 9dd3c54

Browse files
committed
rustbuild: Migrate tidy checks to Rust
This commit rewrites all of the tidy checks we have, namely: * featureck * errorck * tidy * binaries into Rust under a new `tidy` tool inside of the `src/tools` directory. This at the same time deletes all the corresponding Python tidy checks so we can be sure to only have one source of truth for all the tidy checks. cc rust-lang#31590
1 parent bed32d8 commit 9dd3c54

File tree

24 files changed

+547
-742
lines changed

24 files changed

+547
-742
lines changed

mk/tests.mk

Lines changed: 9 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -240,52 +240,16 @@ cleantestlibs:
240240
# Tidy
241241
######################################################################
242242

243-
ifdef CFG_NOTIDY
244243
.PHONY: tidy
245-
tidy:
246-
else
247-
248-
# Run the tidy script in multiple parts to avoid huge 'echo' commands
249-
.PHONY: tidy
250-
tidy: tidy-basic tidy-binaries tidy-errors tidy-features
251-
252-
endif
253-
254-
.PHONY: tidy-basic
255-
tidy-basic:
256-
@$(call E, check: formatting)
257-
$(Q) $(CFG_PYTHON) $(S)src/etc/tidy.py $(S)src/
258-
259-
.PHONY: tidy-binaries
260-
tidy-binaries:
261-
@$(call E, check: binaries)
262-
$(Q)find $(S)src -type f \
263-
\( -perm -u+x -or -perm -g+x -or -perm -o+x \) \
264-
-not -name '*.rs' -and -not -name '*.py' \
265-
-and -not -name '*.sh' -and -not -name '*.pp' \
266-
| grep '^$(S)src/jemalloc' -v \
267-
| grep '^$(S)src/libuv' -v \
268-
| grep '^$(S)src/llvm' -v \
269-
| grep '^$(S)src/rt/hoedown' -v \
270-
| grep '^$(S)src/gyp' -v \
271-
| grep '^$(S)src/etc' -v \
272-
| grep '^$(S)src/doc' -v \
273-
| grep '^$(S)src/compiler-rt' -v \
274-
| grep '^$(S)src/libbacktrace' -v \
275-
| grep '^$(S)src/rust-installer' -v \
276-
| grep '^$(S)src/liblibc' -v \
277-
| xargs $(CFG_PYTHON) $(S)src/etc/check-binaries.py
278-
279-
.PHONY: tidy-errors
280-
tidy-errors:
281-
@$(call E, check: extended errors)
282-
$(Q) $(CFG_PYTHON) $(S)src/etc/errorck.py $(S)src/
283-
284-
.PHONY: tidy-features
285-
tidy-features:
286-
@$(call E, check: feature sanity)
287-
$(Q) $(CFG_PYTHON) $(S)src/etc/featureck.py $(S)src/
288-
244+
tidy: $(HBIN0_H_$(CFG_BUILD))/tidy$(X_$(CFG_BUILD))
245+
$< $(S)src
246+
247+
$(HBIN0_H_$(CFG_BUILD))/tidy$(X_$(CFG_BUILD)): \
248+
$(TSREQ0_T_$(CFG_BUILD)_H_$(CFG_BUILD)) \
249+
$(TLIB0_T_$(CFG_BUILD)_H_$(CFG_BUILD))/stamp.std \
250+
$(call rwildcard,$(S)src/tools/tidy/src,*.rs)
251+
$(STAGE0_T_$(CFG_BUILD)_H_$(CFG_BUILD)) src/tools/tidy/src/main.rs \
252+
--out-dir $(@D) --crate-name tidy
289253

290254
######################################################################
291255
# Sets of tests

src/bootstrap/build/check.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ pub fn cargotest(build: &Build, stage: u32, host: &str) {
3333
.env("PATH", newpath)
3434
.arg(&build.cargo));
3535
}
36+
37+
pub fn tidy(build: &Build, stage: u32, host: &str) {
38+
println!("tidy check stage{} ({})", stage, host);
39+
let compiler = Compiler::new(stage, host);
40+
build.run(build.tool_cmd(&compiler, "tidy")
41+
.arg(build.src.join("src")));
42+
}

src/bootstrap/build/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ impl Build {
197197
ToolCargoTest { stage } => {
198198
compile::tool(self, stage, target.target, "cargotest");
199199
}
200+
ToolTidy { stage } => {
201+
compile::tool(self, stage, target.target, "tidy");
202+
}
200203
DocBook { stage } => {
201204
doc::rustbook(self, stage, target.target, "book", &doc_out);
202205
}
@@ -230,6 +233,9 @@ impl Build {
230233
CheckCargoTest { stage } => {
231234
check::cargotest(self, stage, target.target);
232235
}
236+
CheckTidy { stage } => {
237+
check::tidy(self, stage, target.target);
238+
}
233239

234240
DistDocs { stage } => dist::docs(self, stage, target.target),
235241
DistMingw { _dummy } => dist::mingw(self, target.target),

src/bootstrap/build/step.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ macro_rules! targets {
5151
(tool_rustbook, ToolRustbook { stage: u32 }),
5252
(tool_error_index, ToolErrorIndex { stage: u32 }),
5353
(tool_cargotest, ToolCargoTest { stage: u32 }),
54+
(tool_tidy, ToolTidy { stage: u32 }),
5455

5556
// Steps for long-running native builds. Ideally these wouldn't
5657
// actually exist and would be part of build scripts, but for now
@@ -79,6 +80,7 @@ macro_rules! targets {
7980
(check, Check { stage: u32, compiler: Compiler<'a> }),
8081
(check_linkcheck, CheckLinkcheck { stage: u32 }),
8182
(check_cargotest, CheckCargoTest { stage: u32 }),
83+
(check_tidy, CheckTidy { stage: u32 }),
8284

8385
// Distribution targets, creating tarballs
8486
(dist, Dist { stage: u32 }),
@@ -316,8 +318,13 @@ impl<'a> Step<'a> {
316318
Source::CheckCargoTest { stage } => {
317319
vec![self.tool_cargotest(stage)]
318320
}
321+
Source::CheckTidy { stage } => {
322+
vec![self.tool_tidy(stage)]
323+
}
319324

320-
Source::ToolLinkchecker { stage } => {
325+
Source::ToolLinkchecker { stage } |
326+
Source::ToolTidy { stage } |
327+
Source::ToolCargoTest { stage } => {
321328
vec![self.libstd(self.compiler(stage))]
322329
}
323330
Source::ToolErrorIndex { stage } |

src/bootstrap/mk/Makefile.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,7 @@ check-cargotest:
4242
$(Q)$(BOOTSTRAP) --step check-cargotest
4343
dist:
4444
$(Q)$(BOOTSTRAP) --step dist
45+
tidy:
46+
$(Q)$(BOOTSTRAP) --step check-tidy --stage 0
4547

4648
.PHONY: dist

src/etc/check-binaries.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/etc/errorck.py

Lines changed: 0 additions & 136 deletions
This file was deleted.

0 commit comments

Comments
 (0)