Skip to content

Commit 83786e7

Browse files
Add new needs-backends tests annotations
1 parent c479671 commit 83786e7

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/doc/rustc-dev-guide/src/tests/directives.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ settings:
204204
`proc-macro` crate type.
205205
- `needs-target-std` — ignores if target platform does not have std support.
206206
- `ignore-backends` — ignores the listed backends, separated by whitespace characters.
207+
- `needs-backends` — only runs the test if current codegen backend is listed.
207208

208209
The following directives will check LLVM support:
209210

src/tools/compiletest/src/directives.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
902902
"min-llvm-version",
903903
"min-system-llvm-version",
904904
"needs-asm-support",
905+
"needs-backends",
905906
"needs-crate-type",
906907
"needs-deterministic-layouts",
907908
"needs-dlltool",
@@ -1663,6 +1664,7 @@ pub(crate) fn make_test_description<R: Read>(
16631664
decision!(needs::handle_needs(&cache.needs, config, ln));
16641665
decision!(ignore_llvm(config, path, ln));
16651666
decision!(ignore_backends(config, path, ln));
1667+
decision!(needs_backends(config, path, ln));
16661668
decision!(ignore_cdb(config, ln));
16671669
decision!(ignore_gdb(config, ln));
16681670
decision!(ignore_lldb(config, ln));
@@ -1809,6 +1811,29 @@ fn ignore_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecisi
18091811
IgnoreDecision::Continue
18101812
}
18111813

1814+
fn needs_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
1815+
if let Some(needed_backends) = config.parse_name_value_directive(line, "needs-backends") {
1816+
if !needed_backends
1817+
.split_whitespace()
1818+
.map(|backend| match CodegenBackend::try_from(backend) {
1819+
Ok(backend) => backend,
1820+
Err(error) => {
1821+
panic!("Invalid needs-backends value `{backend}` in `{path}`: {error}")
1822+
}
1823+
})
1824+
.any(|backend| config.codegen_backend == backend)
1825+
{
1826+
return IgnoreDecision::Ignore {
1827+
reason: format!(
1828+
"{} backend is not part of required backends",
1829+
config.codegen_backend.as_str()
1830+
),
1831+
};
1832+
}
1833+
}
1834+
IgnoreDecision::Continue
1835+
}
1836+
18121837
fn ignore_llvm(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
18131838
if let Some(needed_components) =
18141839
config.parse_name_value_directive(line, "needs-llvm-components")

0 commit comments

Comments
 (0)