diff options
| author | jyn <github@jyn.dev> | 2023-07-09 21:59:27 -0500 |
|---|---|---|
| committer | jyn <github@jyn.dev> | 2023-07-14 17:27:20 -0500 |
| commit | 26cdf7566cba986045b856d26c253df1150bff93 (patch) | |
| tree | 830f6adf01ca897a5fa0c58ddb0280e6831cf22b | |
| parent | fff8223584d5c55bfc974772db1856db90e878d8 (diff) | |
| download | rust-26cdf7566cba986045b856d26c253df1150bff93.tar.gz rust-26cdf7566cba986045b856d26c253df1150bff93.zip | |
Add must_use to `msg_` functions
This caught several places which weren't waiting until the command finished to drop the Group. I also took the liberty of calling `msg_sysroot_tool` from `run_cargo_test` to reduce code duplication and make errors like this less likely in the future.
| -rw-r--r-- | src/bootstrap/doc.rs | 8 | ||||
| -rw-r--r-- | src/bootstrap/lib.rs | 6 | ||||
| -rw-r--r-- | src/bootstrap/test.rs | 98 |
3 files changed, 67 insertions, 45 deletions
diff --git a/src/bootstrap/doc.rs b/src/bootstrap/doc.rs index d20bfab4131..8ceaadbefac 100644 --- a/src/bootstrap/doc.rs +++ b/src/bootstrap/doc.rs @@ -221,7 +221,7 @@ impl Step for TheBook { let shared_assets = builder.ensure(SharedAssets { target }); // build the redirect pages - builder.msg_doc(compiler, "book redirect pages", target); + let _guard = builder.msg_doc(compiler, "book redirect pages", target); for file in t!(fs::read_dir(builder.src.join(&relative_path).join("redirects"))) { let file = t!(file); let path = file.path(); @@ -305,7 +305,7 @@ impl Step for Standalone { fn run(self, builder: &Builder<'_>) { let target = self.target; let compiler = self.compiler; - builder.msg_doc(compiler, "standalone", target); + let _guard = builder.msg_doc(compiler, "standalone", target); let out = builder.doc_out(target); t!(fs::create_dir_all(&out)); @@ -799,8 +799,6 @@ macro_rules! tool_doc { SourceType::Submodule }; - builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target); - // Symlink compiler docs to the output directory of rustdoc documentation. let out_dirs = [ builder.stage_out(compiler, Mode::ToolRustc).join(target.triple).join("doc"), @@ -839,6 +837,8 @@ macro_rules! tool_doc { cargo.rustdocflag("--show-type-layout"); cargo.rustdocflag("--generate-link-to-definition"); cargo.rustdocflag("-Zunstable-options"); + + let _guard = builder.msg_doc(compiler, stringify!($tool).to_lowercase(), target); builder.run(&mut cargo.into()); } } diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index f5ad4f336a7..7ffd1e1f9c5 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -999,6 +999,7 @@ impl Build { } } + #[must_use = "Groups should not be dropped until the Step finishes running"] fn msg_check( &self, what: impl Display, @@ -1007,6 +1008,7 @@ impl Build { self.msg(Kind::Check, self.config.stage, what, self.config.build, target) } + #[must_use = "Groups should not be dropped until the Step finishes running"] fn msg_doc( &self, compiler: Compiler, @@ -1016,6 +1018,7 @@ impl Build { self.msg(Kind::Doc, compiler.stage, what, compiler.host, target.into()) } + #[must_use = "Groups should not be dropped until the Step finishes running"] fn msg_build( &self, compiler: Compiler, @@ -1028,6 +1031,7 @@ impl Build { /// Return a `Group` guard for a [`Step`] that is built for each `--stage`. /// /// [`Step`]: crate::builder::Step + #[must_use = "Groups should not be dropped until the Step finishes running"] fn msg( &self, action: impl Into<Kind>, @@ -1054,6 +1058,7 @@ impl Build { /// Return a `Group` guard for a [`Step`] that is only built once and isn't affected by `--stage`. /// /// [`Step`]: crate::builder::Step + #[must_use = "Groups should not be dropped until the Step finishes running"] fn msg_unstaged( &self, action: impl Into<Kind>, @@ -1065,6 +1070,7 @@ impl Build { self.group(&msg) } + #[must_use = "Groups should not be dropped until the Step finishes running"] fn msg_sysroot_tool( &self, action: impl Into<Kind>, diff --git a/src/bootstrap/test.rs b/src/bootstrap/test.rs index da0c3767c5c..c8ec9f1a8ff 100644 --- a/src/bootstrap/test.rs +++ b/src/bootstrap/test.rs @@ -117,9 +117,8 @@ impl Step for CrateBootstrap { SourceType::InTree, &[], ); - let _group = builder.msg(Kind::Test, compiler.stage, path, compiler.host, bootstrap_host); let crate_name = path.rsplit_once('/').unwrap().1; - run_cargo_test(cargo, &[], &[], crate_name, compiler, bootstrap_host, builder); + run_cargo_test(cargo, &[], &[], crate_name, crate_name, compiler, bootstrap_host, builder); } } @@ -159,14 +158,6 @@ You can skip linkcheck with --exclude src/tools/linkchecker" let bootstrap_host = builder.config.build; let compiler = builder.compiler(0, bootstrap_host); - let self_test_group = builder.msg( - Kind::Test, - compiler.stage, - "linkchecker self tests", - bootstrap_host, - bootstrap_host, - ); - let cargo = tool::prepare_tool_cargo( builder, compiler, @@ -177,8 +168,16 @@ You can skip linkcheck with --exclude src/tools/linkchecker" SourceType::InTree, &[], ); - run_cargo_test(cargo, &[], &[], "linkchecker", compiler, bootstrap_host, builder); - drop(self_test_group); + run_cargo_test( + cargo, + &[], + &[], + "linkchecker", + "linkchecker self tests", + compiler, + bootstrap_host, + builder, + ); if builder.doc_tests == DocTests::No { return; @@ -413,8 +412,7 @@ impl Step for RustAnalyzer { cargo.env("SKIP_SLOW_TESTS", "1"); cargo.add_rustc_lib_path(builder, compiler); - builder.msg_sysroot_tool(Kind::Test, compiler.stage, "rust-analyzer", host, host); - run_cargo_test(cargo, &[], &[], "rust-analyzer", compiler, host, builder); + run_cargo_test(cargo, &[], &[], "rust-analyzer", "rust-analyzer", compiler, host, builder); } } @@ -463,8 +461,7 @@ impl Step for Rustfmt { cargo.add_rustc_lib_path(builder, compiler); - builder.msg_sysroot_tool(Kind::Test, compiler.stage, "rustfmt", host, host); - run_cargo_test(cargo, &[], &[], "rustfmt", compiler, host, builder); + run_cargo_test(cargo, &[], &[], "rustfmt", "rustfmt", compiler, host, builder); } } @@ -512,7 +509,16 @@ impl Step for RustDemangler { cargo.env("RUST_DEMANGLER_DRIVER_PATH", rust_demangler); cargo.add_rustc_lib_path(builder, compiler); - run_cargo_test(cargo, &[], &[], "rust-demangler", compiler, host, builder); + run_cargo_test( + cargo, + &[], + &[], + "rust-demangler", + "rust-demangler", + compiler, + host, + builder, + ); } } @@ -754,7 +760,16 @@ impl Step for CompiletestTest { &[], ); cargo.allow_features("test"); - run_cargo_test(cargo, &[], &[], "compiletest", compiler, host, builder); + run_cargo_test( + cargo, + &[], + &[], + "compiletest", + "compiletest self test", + compiler, + host, + builder, + ); } } @@ -810,7 +825,7 @@ impl Step for Clippy { cargo.env("BLESS", "Gesundheit"); } - builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host); + let _guard = builder.msg_sysroot_tool(Kind::Test, compiler.stage, "clippy", host, host); if builder.try_run(&mut cargo).is_ok() { // The tests succeeded; nothing to do. @@ -2201,11 +2216,12 @@ impl Step for CrateLibrustc { /// Given a `cargo test` subcommand, add the appropriate flags and run it. /// /// Returns whether the test succeeded. -fn run_cargo_test( +fn run_cargo_test<'a>( cargo: impl Into<Command>, libtest_args: &[&str], crates: &[Interned<String>], primary_crate: &str, + description: impl Into<Option<&'a str>>, compiler: Compiler, target: TargetSelection, builder: &Builder<'_>, @@ -2213,6 +2229,9 @@ fn run_cargo_test( let mut cargo = prepare_cargo_test(cargo, libtest_args, crates, primary_crate, compiler, target, builder); let _time = util::timeit(&builder); + let _group = description.into().and_then(|what| { + builder.msg_sysroot_tool(Kind::Test, compiler.stage, what, compiler.host, target) + }); #[cfg(feature = "build-metrics")] builder.metrics.begin_test_suite( @@ -2378,14 +2397,16 @@ impl Step for Crate { _ => panic!("can only test libraries"), }; - let _guard = builder.msg( - builder.kind, - compiler.stage, - crate_description(&self.crates), - compiler.host, + run_cargo_test( + cargo, + &[], + &self.crates, + &self.crates[0], + &*crate_description(&self.crates), + compiler, target, + builder, ); - run_cargo_test(cargo, &[], &self.crates, &self.crates[0], compiler, target, builder); } } @@ -2478,18 +2499,12 @@ impl Step for CrateRustdoc { dylib_path.insert(0, PathBuf::from(&*libdir)); cargo.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap()); - let _guard = builder.msg_sysroot_tool( - builder.kind, - compiler.stage, - "rustdoc", - compiler.host, - target, - ); run_cargo_test( cargo, &[], &[INTERNER.intern_str("rustdoc:0.0.0")], "rustdoc", + "rustdoc", compiler, target, builder, @@ -2545,13 +2560,12 @@ impl Step for CrateRustdocJsonTypes { &[] }; - let _guard = - builder.msg(builder.kind, compiler.stage, "rustdoc-json-types", compiler.host, target); run_cargo_test( cargo, libtest_args, &[INTERNER.intern_str("rustdoc-json-types")], "rustdoc-json-types", + "rustdoc-json-types", compiler, target, builder, @@ -2722,7 +2736,7 @@ impl Step for Bootstrap { } // rustbuild tests are racy on directory creation so just run them one at a time. // Since there's not many this shouldn't be a problem. - run_cargo_test(cmd, &["--test-threads=1"], &[], "bootstrap", compiler, host, builder); + run_cargo_test(cmd, &["--test-threads=1"], &[], "bootstrap", None, compiler, host, builder); } fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> { @@ -2840,14 +2854,16 @@ impl Step for RustInstaller { &[], ); - let _guard = builder.msg( - Kind::Test, - compiler.stage, + run_cargo_test( + cargo, + &[], + &[], + "installer", "rust-installer", + compiler, bootstrap_host, - bootstrap_host, + builder, ); - run_cargo_test(cargo, &[], &[], "installer", compiler, bootstrap_host, builder); // We currently don't support running the test.sh script outside linux(?) environments. // Eventually this should likely migrate to #[test]s in rust-installer proper rather than a |
