Skip to content

Commit 603d72c

Browse files
committed
Add supporting infrastructure for run-make V2 tests
1 parent 1d447a9 commit 603d72c

File tree

12 files changed

+507
-32
lines changed

12 files changed

+507
-32
lines changed

Cargo.lock

+13
Original file line numberDiff line numberDiff line change
@@ -3313,6 +3313,13 @@ dependencies = [
33133313
"serde_json",
33143314
]
33153315

3316+
[[package]]
3317+
name = "run_make_support"
3318+
version = "0.0.0"
3319+
dependencies = [
3320+
"shell-words",
3321+
]
3322+
33163323
[[package]]
33173324
name = "rust-demangler"
33183325
version = "0.0.1"
@@ -5025,6 +5032,12 @@ version = "0.1.5"
50255032
source = "registry+https://github.com/rust-lang/crates.io-index"
50265033
checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"
50275034

5035+
[[package]]
5036+
name = "shell-words"
5037+
version = "1.1.0"
5038+
source = "registry+https://github.com/rust-lang/crates.io-index"
5039+
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
5040+
50285041
[[package]]
50295042
name = "shlex"
50305043
version = "1.3.0"

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ members = [
1010
"src/tools/clippy",
1111
"src/tools/clippy/clippy_dev",
1212
"src/tools/compiletest",
13+
"src/tools/run-make-support",
1314
"src/tools/error_index_generator",
1415
"src/tools/linkchecker",
1516
"src/tools/lint-docs",

src/bootstrap/src/core/build_steps/test.rs

+82-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::core::config::flags::get_completion;
2727
use crate::core::config::flags::Subcommand;
2828
use crate::core::config::TargetSelection;
2929
use crate::utils::cache::{Interned, INTERNER};
30+
use crate::utils::dylib::shared_lib_name;
3031
use crate::utils::exec::BootstrapCommand;
3132
use crate::utils::helpers::{
3233
self, add_link_lib_path, add_rustdoc_cargo_linker_args, dylib_path, dylib_path_var,
@@ -1327,6 +1328,53 @@ macro_rules! coverage_test_alias {
13271328
};
13281329
}
13291330

1331+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
1332+
pub struct RunMakeSupport {
1333+
pub compiler: Compiler,
1334+
pub target: TargetSelection,
1335+
}
1336+
1337+
impl Step for RunMakeSupport {
1338+
type Output = PathBuf;
1339+
const DEFAULT: bool = true;
1340+
1341+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1342+
run.never()
1343+
}
1344+
1345+
fn make_run(run: RunConfig<'_>) {
1346+
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1347+
run.builder.ensure(RunMakeSupport { compiler, target: run.build_triple() });
1348+
}
1349+
1350+
fn run(self, builder: &Builder<'_>) -> PathBuf {
1351+
builder.ensure(compile::Std::new(self.compiler, self.target));
1352+
1353+
let cargo = tool::prepare_tool_cargo(
1354+
builder,
1355+
self.compiler,
1356+
Mode::ToolStd,
1357+
self.target,
1358+
"build",
1359+
"src/tools/run-make-support",
1360+
SourceType::InTree,
1361+
&[],
1362+
);
1363+
1364+
let mut cargo = Command::from(cargo);
1365+
cargo.env("RUSTFLAGS", "-C prefer-dynamic");
1366+
builder.run(&mut cargo);
1367+
1368+
let lib_name = shared_lib_name("run_make_support", &self.target.to_string());
1369+
let lib = builder.tools_dir(self.compiler).join(&lib_name);
1370+
1371+
let cargo_out =
1372+
builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(&lib_name);
1373+
builder.copy(&cargo_out, &lib);
1374+
lib
1375+
}
1376+
}
1377+
13301378
default_test!(Ui { path: "tests/ui", mode: "ui", suite: "ui" });
13311379

13321380
default_test!(RunPassValgrind {
@@ -1361,7 +1409,40 @@ host_test!(RustdocJson { path: "tests/rustdoc-json", mode: "rustdoc-json", suite
13611409

13621410
host_test!(Pretty { path: "tests/pretty", mode: "pretty", suite: "pretty" });
13631411

1364-
default_test!(RunMake { path: "tests/run-make", mode: "run-make", suite: "run-make" });
1412+
// Special-handling is needed for `run-make`, so don't use `default_test` for defining `RunMake`
1413+
// tests.
1414+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1415+
pub struct RunMake {
1416+
pub compiler: Compiler,
1417+
pub target: TargetSelection,
1418+
}
1419+
1420+
impl Step for RunMake {
1421+
type Output = ();
1422+
const DEFAULT: bool = true;
1423+
const ONLY_HOSTS: bool = false;
1424+
1425+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1426+
run.suite_path("tests/run-make")
1427+
}
1428+
1429+
fn make_run(run: RunConfig<'_>) {
1430+
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1431+
run.builder.ensure(RunMakeSupport { compiler, target: run.build_triple() });
1432+
run.builder.ensure(RunMake { compiler, target: run.target });
1433+
}
1434+
1435+
fn run(self, builder: &Builder<'_>) {
1436+
builder.ensure(Compiletest {
1437+
compiler: self.compiler,
1438+
target: self.target,
1439+
mode: "run-make",
1440+
suite: "run-make",
1441+
path: "tests/run-make",
1442+
compare_mode: None,
1443+
});
1444+
}
1445+
}
13651446

13661447
host_test!(RunMakeFullDeps {
13671448
path: "tests/run-make-fulldeps",

src/bootstrap/src/utils/dylib.rs

+13
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,16 @@ pub fn exe(name: &str, target: &str) -> String {
3838
name.to_string()
3939
}
4040
}
41+
42+
/// Given a shared library called `name`, return the filename for the
43+
/// shared library for a particular target.
44+
#[allow(dead_code)]
45+
pub fn shared_lib_name(name: &str, target: &str) -> String {
46+
if target.contains("windows") {
47+
format!("{name}.dll")
48+
} else if target.contains("apple") {
49+
format!("lib{name}.dylib")
50+
} else {
51+
format!("lib{name}.so")
52+
}
53+
}

src/tools/compiletest/src/lib.rs

+26-9
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,21 @@ fn collect_tests_from_dir(
655655
return Ok(());
656656
}
657657

658-
if config.mode == Mode::RunMake && dir.join("Makefile").exists() {
659-
let paths = TestPaths {
660-
file: dir.to_path_buf(),
661-
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
662-
};
663-
tests.extend(make_test(config, cache, &paths, inputs, poisoned));
664-
return Ok(());
658+
if config.mode == Mode::RunMake {
659+
if dir.join("Makefile").exists() && dir.join("rmake.rs").exists() {
660+
return Err(io::Error::other(
661+
"run-make tests cannot have both `Makefile` and `rmake.rs`",
662+
));
663+
}
664+
665+
if dir.join("Makefile").exists() || dir.join("rmake.rs").exists() {
666+
let paths = TestPaths {
667+
file: dir.to_path_buf(),
668+
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
669+
};
670+
tests.extend(make_test(config, cache, &paths, inputs, poisoned));
671+
return Ok(());
672+
}
665673
}
666674

667675
// If we find a test foo/bar.rs, we have to build the
@@ -733,8 +741,17 @@ fn make_test(
733741
poisoned: &mut bool,
734742
) -> Vec<test::TestDescAndFn> {
735743
let test_path = if config.mode == Mode::RunMake {
736-
// Parse directives in the Makefile
737-
testpaths.file.join("Makefile")
744+
if testpaths.file.join("rmake.rs").exists() && testpaths.file.join("Makefile").exists() {
745+
panic!("run-make tests cannot have both `rmake.rs` and `Makefile`");
746+
}
747+
748+
if testpaths.file.join("rmake.rs").exists() {
749+
// Parse directives in rmake.rs.
750+
testpaths.file.join("rmake.rs")
751+
} else {
752+
// Parse directives in the Makefile.
753+
testpaths.file.join("Makefile")
754+
}
738755
} else {
739756
PathBuf::from(&testpaths.file)
740757
};

0 commit comments

Comments
 (0)