Skip to content

Commit

Permalink
Rollup merge of rust-lang#136581 - jieyouxu:makefile-be-gone, r=Kobzol
Browse files Browse the repository at this point in the history
Retire the legacy `Makefile`-based `run-make` test infra

The final piece of [porting run-make tests to use Rust rust-lang#121876](rust-lang#121876).
Closes rust-lang#121876.
Closes rust-lang#40713.
Closes rust-lang#81791 (no longer using `wc`).
Closes rust-lang#56475 (no longer a problem in current form of that test; we don't ignore the test on `aarch64-unknown-linux-gnu`).

### Summary

This PR removes the legacy `Makefile`-based `run-make` test infra which has served us well over the years. The legacy infra is no longer needed since we ported all of `Makefile`-based `run-make` tests to the new `rmake.rs` infra.

Additionally, this PR:

- Removes `tests/run-make/tools.mk` since no more `Makefile`-based tests remain.
- Updates `tests/run-make/README.md` and rustc-dev-guide docs to remove mention about `Makefile`-based `run-make` tests
- Update test suite requirements in rustc-dev-guide on Windows to no longer need MSYS2 (they should also now run successfully on native Windows MSVC).
- Update `triagebot.toml` to stop backlinking to rust-lang#121876.

**Thanks to everyone who helped in this effort to modernize the `run-make` test infra and test suite!**

r? bootstrap
  • Loading branch information
jieyouxu authored Mar 4, 2025
2 parents fd17dea + 95b030f commit 692c2e8
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 734 deletions.
30 changes: 1 addition & 29 deletions src/doc/rustc-dev-guide/src/tests/compiletest.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,7 @@ The following test suites are available, with links for more information:

### General purpose test suite

[`run-make`](#run-make-tests) are general purpose tests using Rust programs (or
Makefiles (legacy)).
[`run-make`](#run-make-tests) are general purpose tests using Rust programs.

### Rustdoc test suites

Expand Down Expand Up @@ -396,14 +395,6 @@ your test, causing separate files to be generated for 32bit and 64bit systems.

### `run-make` tests

> **Note on phasing out `Makefile`s**
>
> We are planning to migrate all existing Makefile-based `run-make` tests
> to Rust programs. You should not be adding new Makefile-based `run-make`
> tests.
>
> See <https://github.com/rust-lang/rust/issues/121876>.
The tests in [`tests/run-make`] are general-purpose tests using Rust *recipes*,
which are small programs (`rmake.rs`) allowing arbitrary Rust code such as
`rustc` invocations, and is supported by a [`run_make_support`] library. Using
Expand All @@ -424,11 +415,6 @@ Compiletest directives like `//@ only-<target>` or `//@ ignore-<target>` are
supported in `rmake.rs`, like in UI tests. However, revisions or building
auxiliary via directives are not currently supported.

Two `run-make` tests are ported over to Rust recipes as examples:

- <https://github.com/rust-lang/rust/tree/master/tests/run-make/CURRENT_RUSTC_VERSION>
- <https://github.com/rust-lang/rust/tree/master/tests/run-make/a-b-a-linker-guard>

#### Quickly check if `rmake.rs` tests can be compiled

You can quickly check if `rmake.rs` tests can be compiled without having to
Expand Down Expand Up @@ -481,20 +467,6 @@ Then add a corresponding entry to `"rust-analyzer.linkedProjects"`
],
```

#### Using Makefiles (legacy)

<div class="warning">
You should avoid writing new Makefile-based `run-make` tests.
</div>

Each test should be in a separate directory with a `Makefile` indicating the
commands to run.

There is a [`tools.mk`] Makefile which you can include which provides a bunch of
utilities to make it easier to run commands and compare outputs. Take a look at
some of the other tests for some examples on how to get started.

[`tools.mk`]: https://github.com/rust-lang/rust/blob/master/tests/run-make/tools.mk
[`tests/run-make`]: https://github.com/rust-lang/rust/tree/master/tests/run-make
[`run_make_support`]: https://github.com/rust-lang/rust/tree/master/src/tools/run-make-support

Expand Down
7 changes: 1 addition & 6 deletions src/doc/rustc-dev-guide/src/tests/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
FIXME(jieyouxu) completely revise this chapter.
-->

Directives are special comments that tell compiletest how to build and interpret
a test. They must appear before the Rust source in the test. They may also
appear in `rmake.rs` or legacy Makefiles for [run-make
tests](compiletest.md#run-make-tests).
Directives are special comments that tell compiletest how to build and interpret a test. They must appear before the Rust source in the test. They may also appear in `rmake.rs` [run-make tests](compiletest.md#run-make-tests).

They are normally put after the short comment that explains the point of this
test. Compiletest test suites use `//@` to signal that a comment is a directive.
Expand Down Expand Up @@ -221,8 +218,6 @@ The following directives will check LLVM support:
[`aarch64-gnu-debug`]), which only runs a
subset of `run-make` tests. Other tests with this directive will not
run at all, which is usually not what you want.
- Notably, the [`aarch64-gnu-debug`] CI job *currently* only runs `run-make`
tests which additionally contain `clang` in their test name.

See also [Debuginfo tests](compiletest.md#debuginfo-tests) for directives for
ignoring debuggers.
Expand Down
25 changes: 0 additions & 25 deletions src/doc/rustc-dev-guide/src/tests/running.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,30 +238,6 @@ This is much faster, but doesn't always work. For example, some tests include
directives that specify specific compiler flags, or which rely on other crates,
and they may not run the same without those options.

## Running `run-make` tests

### Windows

Running the `run-make` test suite on Windows is a currently bit more involved.
There are numerous prerequisites and environmental requirements:

- Install msys2: <https://www.msys2.org/>
- Specify `MSYS2_PATH_TYPE=inherit` in `msys2.ini` in the msys2 installation directory, run the
following with `MSYS2 MSYS`:
- `pacman -Syuu`
- `pacman -S make`
- `pacman -S diffutils`
- `pacman -S binutils`
- `./x test run-make` (`./x test tests/run-make` doesn't work)

There is [on-going work][port-run-make] to not rely on `Makefile`s in the
run-make test suite. Once this work is completed, you can run the entire
`run-make` test suite on native Windows inside `cmd` or `PowerShell` without
needing to install and use MSYS2. As of <!--date-check --> Oct 2024, it is
already possible to run the vast majority of the `run-make` test suite outside
of MSYS2, but there will be failures for the tests that still use `Makefile`s
due to not finding `make`.

## Running tests on a remote machine

Tests may be run on a remote machine (e.g. to test builds for a different
Expand Down Expand Up @@ -406,4 +382,3 @@ If you encounter bugs or problems, don't hesitate to open issues on the
repository](https://github.com/rust-lang/rustc_codegen_gcc/).

[`tests/ui`]: https://github.com/rust-lang/rust/tree/master/tests/ui
[port-run-make]: https://github.com/rust-lang/rust/issues/121876
16 changes: 7 additions & 9 deletions src/tools/compiletest/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,11 +709,11 @@ impl TestProps {
/// returns a struct containing various parts of the directive.
fn line_directive<'line>(
line_number: usize,
comment: &str,
original_line: &'line str,
) -> Option<DirectiveLine<'line>> {
// Ignore lines that don't start with the comment prefix.
let after_comment = original_line.trim_start().strip_prefix(comment)?.trim_start();
let after_comment =
original_line.trim_start().strip_prefix(COMPILETEST_DIRECTIVE_PREFIX)?.trim_start();

let revision;
let raw_directive;
Expand All @@ -722,7 +722,7 @@ fn line_directive<'line>(
// A comment like `//@[foo]` only applies to revision `foo`.
let Some((line_revision, after_close_bracket)) = after_open_bracket.split_once(']') else {
panic!(
"malformed condition directive: expected `{comment}[foo]`, found `{original_line}`"
"malformed condition directive: expected `{COMPILETEST_DIRECTIVE_PREFIX}[foo]`, found `{original_line}`"
)
};

Expand Down Expand Up @@ -836,6 +836,8 @@ pub(crate) fn check_directive<'a>(
CheckDirectiveResult { is_known_directive: is_known(&directive_name), trailing_directive }
}

const COMPILETEST_DIRECTIVE_PREFIX: &str = "//@";

fn iter_header(
mode: Mode,
_suite: &str,
Expand All @@ -849,8 +851,7 @@ fn iter_header(
}

// Coverage tests in coverage-run mode always have these extra directives, without needing to
// specify them manually in every test file. (Some of the comments below have been copied over
// from the old `tests/run-make/coverage-reports/Makefile`, which no longer exists.)
// specify them manually in every test file.
//
// FIXME(jieyouxu): I feel like there's a better way to do this, leaving for later.
if mode == Mode::CoverageRun {
Expand All @@ -867,9 +868,6 @@ fn iter_header(
}
}

// NOTE(jieyouxu): once we get rid of `Makefile`s we can unconditionally check for `//@`.
let comment = if testfile.extension().is_some_and(|e| e == "rs") { "//@" } else { "#" };

let mut rdr = BufReader::with_capacity(1024, rdr);
let mut ln = String::new();
let mut line_number = 0;
Expand All @@ -882,7 +880,7 @@ fn iter_header(
}
let ln = ln.trim();

let Some(directive_line) = line_directive(line_number, comment, ln) else {
let Some(directive_line) = line_directive(line_number, ln) else {
continue;
};

Expand Down
9 changes: 0 additions & 9 deletions src/tools/compiletest/src/header/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,6 @@ fn check_ignore(config: &Config, contents: &str) -> bool {
d.ignore
}

fn parse_makefile(config: &Config, contents: &str) -> EarlyProps {
let bytes = contents.as_bytes();
EarlyProps::from_reader(config, Path::new("Makefile"), bytes)
}

#[test]
fn should_fail() {
let config: Config = cfg().build();
Expand All @@ -261,10 +256,6 @@ fn revisions() {
let config: Config = cfg().build();

assert_eq!(parse_rs(&config, "//@ revisions: a b c").revisions, vec!["a", "b", "c"],);
assert_eq!(
parse_makefile(&config, "# revisions: hello there").revisions,
vec!["hello", "there"],
);
}

#[test]
Expand Down
43 changes: 11 additions & 32 deletions src/tools/compiletest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub mod util;

use core::panic;
use std::collections::HashSet;
use std::ffi::{OsStr, OsString};
use std::ffi::OsString;
use std::io::{self, ErrorKind};
use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
Expand Down Expand Up @@ -268,12 +268,8 @@ pub fn parse_config(args: Vec<String>) -> Config {
let path = Path::new(f);
let mut iter = path.iter().skip(1);

// We skip the test folder and check if the user passed `rmake.rs` or `Makefile`.
if iter
.next()
.is_some_and(|s| s == OsStr::new("rmake.rs") || s == OsStr::new("Makefile"))
&& iter.next().is_none()
{
// We skip the test folder and check if the user passed `rmake.rs`.
if iter.next().is_some_and(|s| s == "rmake.rs") && iter.next().is_none() {
path.parent().unwrap().to_str().unwrap().to_string()
} else {
f.to_string()
Expand Down Expand Up @@ -776,16 +772,9 @@ fn collect_tests_from_dir(
return Ok(());
}

// For run-make tests, a "test file" is actually a directory that contains
// an `rmake.rs` or `Makefile`"
// For run-make tests, a "test file" is actually a directory that contains an `rmake.rs`.
if cx.config.mode == Mode::RunMake {
if dir.join("Makefile").exists() && dir.join("rmake.rs").exists() {
return Err(io::Error::other(
"run-make tests cannot have both `Makefile` and `rmake.rs`",
));
}

if dir.join("Makefile").exists() || dir.join("rmake.rs").exists() {
if dir.join("rmake.rs").exists() {
let paths = TestPaths {
file: dir.to_path_buf(),
relative_dir: relative_dir_path.parent().unwrap().to_path_buf(),
Expand Down Expand Up @@ -854,24 +843,14 @@ pub fn is_test(file_name: &OsString) -> bool {
!invalid_prefixes.iter().any(|p| file_name.starts_with(p))
}

/// For a single test file, creates one or more test structures (one per revision)
/// that can be handed over to libtest to run, possibly in parallel.
/// For a single test file, creates one or more test structures (one per revision) that can be
/// handed over to libtest to run, possibly in parallel.
fn make_test(cx: &TestCollectorCx, collector: &mut TestCollector, testpaths: &TestPaths) {
// For run-make tests, each "test file" is actually a _directory_ containing
// an `rmake.rs` or `Makefile`. But for the purposes of directive parsing,
// we want to look at that recipe file, not the directory itself.
// For run-make tests, each "test file" is actually a _directory_ containing an `rmake.rs`. But
// for the purposes of directive parsing, we want to look at that recipe file, not the directory
// itself.
let test_path = if cx.config.mode == Mode::RunMake {
if testpaths.file.join("rmake.rs").exists() && testpaths.file.join("Makefile").exists() {
panic!("run-make tests cannot have both `rmake.rs` and `Makefile`");
}

if testpaths.file.join("rmake.rs").exists() {
// Parse directives in rmake.rs.
testpaths.file.join("rmake.rs")
} else {
// Parse directives in the Makefile.
testpaths.file.join("Makefile")
}
testpaths.file.join("rmake.rs")
} else {
PathBuf::from(&testpaths.file)
};
Expand Down
Loading

0 comments on commit 692c2e8

Please sign in to comment.