about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-30 20:49:44 +0200
committerGitHub <noreply@github.com>2025-06-30 20:49:44 +0200
commit8156725d2e659bbbf13e4d6d842224b250703186 (patch)
treedd4628a3ec75f67a70815c842e20540972245ab5
parentf2231d5324235bb077d0a8158e8f8914faf3813b (diff)
parente664e7e1166d4b15e7631c9e5014f107449e8d06 (diff)
downloadrust-8156725d2e659bbbf13e4d6d842224b250703186.tar.gz
rust-8156725d2e659bbbf13e4d6d842224b250703186.zip
Rollup merge of #143229 - jieyouxu:compiletest-maintenance-1, r=Kobzol
[COMPILETEST-UNTANGLE 1/N] Move some some early config checks to the lib and move the compiletest binary

This is part of a patch series to untangle `compiletest` to hopefully nudge it towards being more maintainable.

This PR:

- Moves some early config checks (some warnings) to the compiletest library.
- Moves `src/main.rs` to `src/bin/main.rs` to make the separation (as in, compiletest's library component vs the tool binary component) more obvious.

r? ``@Kobzol`` (or reroll)
-rw-r--r--src/tools/compiletest/Cargo.toml4
-rw-r--r--src/tools/compiletest/src/bin/main.rs24
-rw-r--r--src/tools/compiletest/src/lib.rs28
-rw-r--r--src/tools/compiletest/src/main.rs36
4 files changed, 50 insertions, 42 deletions
diff --git a/src/tools/compiletest/Cargo.toml b/src/tools/compiletest/Cargo.toml
index 3b544d8b828..cdada5a2230 100644
--- a/src/tools/compiletest/Cargo.toml
+++ b/src/tools/compiletest/Cargo.toml
@@ -6,6 +6,10 @@ edition = "2024"
 [lib]
 doctest = false
 
+[[bin]]
+name = "compiletest"
+path = "src/bin/main.rs"
+
 [dependencies]
 # tidy-alphabetical-start
 anstyle-svg = "0.1.3"
diff --git a/src/tools/compiletest/src/bin/main.rs b/src/tools/compiletest/src/bin/main.rs
new file mode 100644
index 00000000000..1f777e71cf9
--- /dev/null
+++ b/src/tools/compiletest/src/bin/main.rs
@@ -0,0 +1,24 @@
+use std::env;
+use std::io::IsTerminal;
+use std::sync::Arc;
+
+use compiletest::{early_config_check, log_config, parse_config, run_tests};
+
+fn main() {
+    tracing_subscriber::fmt::init();
+
+    // colored checks stdout by default, but for some reason only stderr is a terminal.
+    // compiletest *does* print many things to stdout, but it doesn't really matter.
+    if std::io::stderr().is_terminal()
+        && matches!(std::env::var("NO_COLOR").as_deref(), Err(_) | Ok("0"))
+    {
+        colored::control::set_override(true);
+    }
+
+    let config = Arc::new(parse_config(env::args().collect()));
+
+    early_config_check(&config);
+
+    log_config(&config);
+    run_tests(config);
+}
diff --git a/src/tools/compiletest/src/lib.rs b/src/tools/compiletest/src/lib.rs
index 0db4d3f6a41..23a4dd73796 100644
--- a/src/tools/compiletest/src/lib.rs
+++ b/src/tools/compiletest/src/lib.rs
@@ -51,12 +51,6 @@ use crate::util::logv;
 /// some code here that inspects environment variables or even runs executables
 /// (e.g. when discovering debugger versions).
 pub fn parse_config(args: Vec<String>) -> Config {
-    if env::var("RUST_TEST_NOCAPTURE").is_ok() {
-        eprintln!(
-            "WARNING: RUST_TEST_NOCAPTURE is not supported. Use the `--no-capture` flag instead."
-        );
-    }
-
     let mut opts = Options::new();
     opts.reqopt("", "compile-lib-path", "path to host shared libraries", "PATH")
         .reqopt("", "run-lib-path", "path to target shared libraries", "PATH")
@@ -1111,3 +1105,25 @@ fn check_for_overlapping_test_paths(found_path_stems: &HashSet<Utf8PathBuf>) {
         );
     }
 }
+
+pub fn early_config_check(config: &Config) {
+    if !config.has_html_tidy && config.mode == Mode::Rustdoc {
+        eprintln!("warning: `tidy` (html-tidy.org) is not installed; diffs will not be generated");
+    }
+
+    if !config.profiler_runtime && config.mode == Mode::CoverageRun {
+        let actioned = if config.bless { "blessed" } else { "checked" };
+        eprintln!(
+            r#"
+WARNING: profiler runtime is not available, so `.coverage` files won't be {actioned}
+help: try setting `profiler = true` in the `[build]` section of `bootstrap.toml`"#
+        );
+    }
+
+    // `RUST_TEST_NOCAPTURE` is a libtest env var, but we don't callout to libtest.
+    if env::var("RUST_TEST_NOCAPTURE").is_ok() {
+        eprintln!(
+            "WARNING: RUST_TEST_NOCAPTURE is not supported. Use the `--no-capture` flag instead."
+        );
+    }
+}
diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs
deleted file mode 100644
index b9ae583581e..00000000000
--- a/src/tools/compiletest/src/main.rs
+++ /dev/null
@@ -1,36 +0,0 @@
-use std::env;
-use std::io::IsTerminal;
-use std::sync::Arc;
-
-use compiletest::common::Mode;
-use compiletest::{log_config, parse_config, run_tests};
-
-fn main() {
-    tracing_subscriber::fmt::init();
-
-    // colored checks stdout by default, but for some reason only stderr is a terminal.
-    // compiletest *does* print many things to stdout, but it doesn't really matter.
-    if std::io::stderr().is_terminal()
-        && matches!(std::env::var("NO_COLOR").as_deref(), Err(_) | Ok("0"))
-    {
-        colored::control::set_override(true);
-    }
-
-    let config = Arc::new(parse_config(env::args().collect()));
-
-    if !config.has_html_tidy && config.mode == Mode::Rustdoc {
-        eprintln!("warning: `tidy` (html-tidy.org) is not installed; diffs will not be generated");
-    }
-
-    if !config.profiler_runtime && config.mode == Mode::CoverageRun {
-        let actioned = if config.bless { "blessed" } else { "checked" };
-        eprintln!(
-            r#"
-WARNING: profiler runtime is not available, so `.coverage` files won't be {actioned}
-help: try setting `profiler = true` in the `[build]` section of `bootstrap.toml`"#
-        );
-    }
-
-    log_config(&config);
-    run_tests(config);
-}