Skip to content

Commit 516495e

Browse files
committed
Port tests/run-make/sysroot-crates-are-unstable to rmake
1 parent 6a207f4 commit 516495e

File tree

7 files changed

+123
-79
lines changed

7 files changed

+123
-79
lines changed

src/tools/compiletest/src/runtest.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3588,6 +3588,7 @@ impl<'test> TestCx<'test> {
35883588
.env("TARGET", &self.config.target)
35893589
.env("PYTHON", &self.config.python)
35903590
.env("SOURCE_ROOT", &src_root)
3591+
.env("SYSROOT_BASE", &self.config.sysroot_base)
35913592
.env("RUST_BUILD_STAGE", &self.config.stage_id)
35923593
.env("RUSTC", cwd.join(&self.config.rustc_path))
35933594
.env("HOST_RPATH_DIR", cwd.join(&self.config.compile_lib_path))

src/tools/run-make-support/src/command.rs

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ impl Command {
4848
output
4949
}
5050

51+
#[track_caller]
52+
pub fn run_unchecked(&mut self) -> CompletedProcess {
53+
self.command_output()
54+
}
55+
5156
#[track_caller]
5257
pub(crate) fn command_output(&mut self) -> CompletedProcess {
5358
// let's make sure we piped all the input and outputs

src/tools/run-make-support/src/lib.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ pub fn recursive_diff(dir1: impl AsRef<Path>, dir2: impl AsRef<Path>) {
278278
});
279279
}
280280

281-
pub fn read_dir<F: Fn(&Path)>(dir: impl AsRef<Path>, callback: F) {
281+
pub fn read_dir(dir: impl AsRef<Path>, mut callback: impl FnMut(&Path)) {
282282
for entry in fs::read_dir(dir).unwrap() {
283283
callback(&entry.unwrap().path());
284284
}
@@ -414,6 +414,17 @@ macro_rules! impl_common_helpers {
414414
self.cmd.run_fail()
415415
}
416416

417+
/// Run the constructed command, but don't check its result status.
418+
/// The caller is responsible for performing any necessary checks.
419+
///
420+
/// Prefer to call [`run`](Self::run) or [`run_fail`](Self::run_fail)
421+
/// if possible.
422+
#[must_use]
423+
#[track_caller]
424+
pub fn run_unchecked(&mut self) -> crate::command::CompletedProcess {
425+
self.cmd.run_unchecked()
426+
}
427+
417428
/// Set the path where the command will be run.
418429
pub fn current_dir<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
419430
self.cmd.current_dir(path);

src/tools/tidy/src/allowed_run_make_makefiles.txt

-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ run-make/symbols-include-type-name/Makefile
234234
run-make/symlinked-extern/Makefile
235235
run-make/symlinked-libraries/Makefile
236236
run-make/symlinked-rlib/Makefile
237-
run-make/sysroot-crates-are-unstable/Makefile
238237
run-make/target-cpu-native/Makefile
239238
run-make/target-specs/Makefile
240239
run-make/target-without-atomic-cas/Makefile

tests/run-make/sysroot-crates-are-unstable/Makefile

-2
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
//! Checks that all unstable library crates in the sysroot are actually treated
2+
//! as unstable.
3+
#![deny(warnings)]
4+
5+
use run_make_support::{env_var, read_dir, rustc};
6+
use std::path::{Path, PathBuf};
7+
use std::str;
8+
9+
#[derive(Debug)]
10+
struct Lib {
11+
name: String,
12+
path: PathBuf,
13+
}
14+
15+
fn check_lib(lib: &Lib) -> Result<(), ()> {
16+
let Lib { name, path } = lib;
17+
18+
println!("verifying that sysroot crate '{name}' is an unstable crate");
19+
20+
let output = rustc()
21+
.input("-")
22+
.crate_type("rlib")
23+
.target(&env_var("TARGET"))
24+
.extern_(name, path)
25+
.stdin(format!("extern crate {name};"))
26+
.run_unchecked();
27+
28+
if !output.status().success()
29+
&& output.stderr_utf8().contains("use of unstable library feature")
30+
{
31+
return Ok(());
32+
}
33+
34+
eprintln!();
35+
eprintln!("CRATE IS NOT UNSTABLE: `{name}` at {path:?}");
36+
eprintln!("output status: `{}`", output.status());
37+
eprintln!("=== STDOUT ===");
38+
eprint!("{}", output.stdout_utf8());
39+
eprintln!("==============");
40+
eprintln!("=== STDERR ===");
41+
eprint!("{}", output.stderr_utf8());
42+
eprintln!("==============");
43+
44+
Err(())
45+
}
46+
47+
fn get_all_libs(libs_dir: &Path) -> Vec<Lib> {
48+
let mut libs = vec![];
49+
read_dir(libs_dir, |file| {
50+
if !file.is_file() {
51+
return;
52+
};
53+
54+
// Treat a file as a library if it begins with `lib` and ends with `.rlib`.
55+
// The library name is the part before the first hyphen (if any).
56+
// FIXME: Use a `try` block once they're stable.
57+
let Some(lib_name) = Some(file).and_then(|file| {
58+
file.file_name()?
59+
.to_str()?
60+
.strip_prefix("lib")?
61+
.strip_suffix(".rlib")?
62+
.split('-')
63+
.next()
64+
}) else {
65+
return;
66+
};
67+
68+
libs.push(Lib { name: lib_name.to_owned(), path: file.to_owned() });
69+
});
70+
libs
71+
}
72+
73+
fn is_stable_crate(name: &str) -> bool {
74+
matches!(name, "std" | "alloc" | "core" | "proc_macro")
75+
}
76+
77+
fn main() {
78+
// Generate a list of all library crates in the sysroot.
79+
let sysroot_libs_dir = PathBuf::from(env_var("SYSROOT_BASE"))
80+
.join("lib/rustlib")
81+
.join(env_var("TARGET"))
82+
.join("lib");
83+
let sysroot_libs = get_all_libs(&sysroot_libs_dir);
84+
85+
// Self-check: If we didn't find `core`, we probably checked the wrong directory.
86+
assert!(
87+
sysroot_libs.iter().any(|lib| lib.name == "core"),
88+
"couldn't find `core` in {sysroot_libs_dir:?}:\n{sysroot_libs:#?}"
89+
);
90+
91+
let unstable_sysroot_libs =
92+
sysroot_libs.iter().filter(|lib| !is_stable_crate(&lib.name)).collect::<Vec<_>>();
93+
// Self-check: There should be at least one unstable lib in the directory.
94+
assert!(
95+
!unstable_sysroot_libs.is_empty(),
96+
"couldn't find any unstable libs in {sysroot_libs_dir:?}:\n{sysroot_libs:#?}"
97+
);
98+
99+
// Check all of the crates before actually failing, so that we report all
100+
// errors instead of just the first one.
101+
let results = unstable_sysroot_libs.iter().map(|lib| check_lib(lib)).collect::<Vec<_>>();
102+
if results.iter().any(|r| r.is_err()) {
103+
std::process::exit(1);
104+
}
105+
}

tests/run-make/sysroot-crates-are-unstable/test.py

-75
This file was deleted.

0 commit comments

Comments
 (0)