Skip to content

Commit 17edace

Browse files
committed
Auto merge of rust-lang#113026 - jieyouxu:run-make-v2, r=bjorn3
Introduce `run-make` V2 infrastructure, a `run_make_support` library and port over 2 tests as example ## Preface See [issue rust-lang#40713: Switch run-make tests from Makefiles to rust](rust-lang#40713) for more context. ## Basic Description of `run-make` V2 `run-make` V2 aims to eliminate the dependency on `make` and `Makefile`s for building `run-make`-style tests. Makefiles are replaced by *recipes* (`rmake.rs`). The current implementation runs `run-make` V2 tests in 3 steps: 1. We build the support library `run_make_support` which the `rmake.rs` recipes depend on as a tool lib. 2. We build the recipe `rmake.rs` and link in the support library. 3. We run the recipe to build and run the tests. `rmake.rs` is basically a replacement for `Makefile`, and allows running arbitrary Rust code. The support library is built using cargo, and so can depend on external crates if desired. The infrastructure implemented by this PR is very barebones, and is the minimally required infrastructure needed to build, run and pass the two example `run-make` tests ported over to the new infrastructure. ### Example `run-make` V2 test ```rs // ignore-tidy-linelength extern crate run_make_support; use std::path::PathBuf; use run_make_support::{aux_build, rustc}; fn main() { aux_build() .arg("--emit=metadata") .arg("stable.rs") .run(); let mut stable_path = PathBuf::from(env!("TMPDIR")); stable_path.push("libstable.rmeta"); let output = rustc() .arg("--emit=metadata") .arg("--extern") .arg(&format!("stable={}", &stable_path.to_string_lossy())) .arg("main.rs") .run(); let stderr = String::from_utf8_lossy(&output.stderr); let version = include_str!(concat!(env!("S"), "/src/version")); let expected_string = format!("stable since {}", version.trim()); assert!(stderr.contains(&expected_string)); } ``` ## Follow Up Work - [ ] Adjust rustc-dev-guide docs
2 parents 6db96de + 48e9f92 commit 17edace

File tree

11 files changed

+583
-32
lines changed

11 files changed

+583
-32
lines changed

Cargo.lock

+4
Original file line numberDiff line numberDiff line change
@@ -3274,6 +3274,10 @@ dependencies = [
32743274
"serde_json",
32753275
]
32763276

3277+
[[package]]
3278+
name = "run_make_support"
3279+
version = "0.0.0"
3280+
32773281
[[package]]
32783282
name = "rust-demangler"
32793283
version = "0.0.1"

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

+80-1
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,52 @@ macro_rules! coverage_test_alias {
13271327
};
13281328
}
13291329

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

13321378
default_test!(RunPassValgrind {
@@ -1361,7 +1407,40 @@ host_test!(RustdocJson { path: "tests/rustdoc-json", mode: "rustdoc-json", suite
13611407

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

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

13661445
host_test!(RunMakeFullDeps {
13671446
path: "tests/run-make-fulldeps",

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)