Skip to content

Commit 8148053

Browse files
committed
Add supporting infrastructure for run-make V2 tests
1 parent 11f32b7 commit 8148053

File tree

12 files changed

+504
-32
lines changed

12 files changed

+504
-32
lines changed

Cargo.lock

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3258,6 +3258,13 @@ dependencies = [
32583258
"serde_json",
32593259
]
32603260

3261+
[[package]]
3262+
name = "run_make_support"
3263+
version = "0.0.0"
3264+
dependencies = [
3265+
"shell-words",
3266+
]
3267+
32613268
[[package]]
32623269
name = "rust-demangler"
32633270
version = "0.0.1"
@@ -4968,6 +4975,12 @@ version = "0.1.5"
49684975
source = "registry+https://github.com/rust-lang/crates.io-index"
49694976
checksum = "45bb67a18fa91266cc7807181f62f9178a6873bfad7dc788c42e6430db40184f"
49704977

4978+
[[package]]
4979+
name = "shell-words"
4980+
version = "1.1.0"
4981+
source = "registry+https://github.com/rust-lang/crates.io-index"
4982+
checksum = "24188a676b6ae68c3b2cb3a01be17fbf7240ce009799bb56d5b1409051e78fde"
4983+
49714984
[[package]]
49724985
name = "shlex"
49734986
version = "1.1.0"

Cargo.toml

Lines changed: 1 addition & 0 deletions
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

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ use crate::core::config::flags::Subcommand;
2727
use crate::core::config::TargetSelection;
2828
use crate::utils;
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,
@@ -1344,6 +1345,53 @@ macro_rules! coverage_test_alias {
13441345
};
13451346
}
13461347

1348+
#[derive(Debug, Copy, Clone, Hash, PartialEq, Eq, Ord, PartialOrd)]
1349+
pub struct RunMakeSupport {
1350+
pub compiler: Compiler,
1351+
pub target: TargetSelection,
1352+
}
1353+
1354+
impl Step for RunMakeSupport {
1355+
type Output = PathBuf;
1356+
const DEFAULT: bool = true;
1357+
1358+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1359+
run.never()
1360+
}
1361+
1362+
fn make_run(run: RunConfig<'_>) {
1363+
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1364+
run.builder.ensure(RunMakeSupport { compiler, target: run.target });
1365+
}
1366+
1367+
fn run(self, builder: &Builder<'_>) -> PathBuf {
1368+
builder.ensure(compile::Std::new(self.compiler, self.target));
1369+
1370+
let cargo = tool::prepare_tool_cargo(
1371+
builder,
1372+
self.compiler,
1373+
Mode::ToolStd,
1374+
self.target,
1375+
"build",
1376+
"src/tools/run-make-support",
1377+
SourceType::InTree,
1378+
&[],
1379+
);
1380+
1381+
let mut cargo = Command::from(cargo);
1382+
cargo.env("RUSTFLAGS", "-C prefer-dynamic");
1383+
builder.run(&mut cargo);
1384+
1385+
let lib_name = shared_lib_name("run_make_support", &self.target.to_string());
1386+
let lib = builder.tools_dir(self.compiler).join(&lib_name);
1387+
1388+
let cargo_out =
1389+
builder.cargo_out(self.compiler, Mode::ToolStd, self.target).join(&lib_name);
1390+
builder.copy(&cargo_out, &lib);
1391+
lib
1392+
}
1393+
}
1394+
13471395
default_test!(Ui { path: "tests/ui", mode: "ui", suite: "ui" });
13481396

13491397
default_test!(RunPassValgrind {
@@ -1378,7 +1426,40 @@ host_test!(RustdocJson { path: "tests/rustdoc-json", mode: "rustdoc-json", suite
13781426

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

1381-
default_test!(RunMake { path: "tests/run-make", mode: "run-make", suite: "run-make" });
1429+
// Special-handling is needed for `run-make`, so don't use `default_test` for defining `RunMake`
1430+
// tests.
1431+
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
1432+
pub struct RunMake {
1433+
pub compiler: Compiler,
1434+
pub target: TargetSelection,
1435+
}
1436+
1437+
impl Step for RunMake {
1438+
type Output = ();
1439+
const DEFAULT: bool = true;
1440+
const ONLY_HOSTS: bool = false;
1441+
1442+
fn should_run(run: ShouldRun<'_>) -> ShouldRun<'_> {
1443+
run.suite_path("tests/run-make")
1444+
}
1445+
1446+
fn make_run(run: RunConfig<'_>) {
1447+
let compiler = run.builder.compiler(run.builder.top_stage, run.build_triple());
1448+
run.builder.ensure(RunMakeSupport { compiler, target: run.target });
1449+
run.builder.ensure(RunMake { compiler, target: run.target });
1450+
}
1451+
1452+
fn run(self, builder: &Builder<'_>) {
1453+
builder.ensure(Compiletest {
1454+
compiler: self.compiler,
1455+
target: self.target,
1456+
mode: "run-make",
1457+
suite: "run-make",
1458+
path: "tests/run-make",
1459+
compare_mode: None,
1460+
});
1461+
}
1462+
}
13821463

13831464
host_test!(RunMakeFullDeps {
13841465
path: "tests/run-make-fulldeps",

src/bootstrap/src/utils/dylib.rs

Lines changed: 13 additions & 0 deletions
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!("lib{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

Lines changed: 26 additions & 9 deletions
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
@@ -731,8 +739,17 @@ fn make_test(
731739
poisoned: &mut bool,
732740
) -> Vec<test::TestDescAndFn> {
733741
let test_path = if config.mode == Mode::RunMake {
734-
// Parse directives in the Makefile
735-
testpaths.file.join("Makefile")
742+
if testpaths.file.join("rmake.rs").exists() && testpaths.file.join("Makefile").exists() {
743+
panic!("run-make tests cannot have both `rmake.rs` and `Makefile`");
744+
}
745+
746+
if testpaths.file.join("rmake.rs").exists() {
747+
// Parse directives in rmake.rs.
748+
testpaths.file.join("rmake.rs")
749+
} else {
750+
// Parse directives in the Makefile.
751+
testpaths.file.join("Makefile")
752+
}
736753
} else {
737754
PathBuf::from(&testpaths.file)
738755
};

0 commit comments

Comments
 (0)