Skip to content

Commit 4a35a9f

Browse files
Add new needs-backends tests annotations
1 parent 9944139 commit 4a35a9f

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
@@ -206,6 +206,7 @@ settings:
206206
`proc-macro` crate type.
207207
- `needs-target-std` — ignores if target platform does not have std support.
208208
- `ignore-backends` — ignores the listed backends, separated by whitespace characters.
209+
- `needs-backends` — only runs the test if current codegen backend is listed.
209210

210211
The following directives will check LLVM support:
211212

src/tools/compiletest/src/directives.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -908,6 +908,7 @@ const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
908908
"min-llvm-version",
909909
"min-system-llvm-version",
910910
"needs-asm-support",
911+
"needs-backends",
911912
"needs-crate-type",
912913
"needs-deterministic-layouts",
913914
"needs-dlltool",
@@ -1671,6 +1672,7 @@ pub(crate) fn make_test_description<R: Read>(
16711672
decision!(needs::handle_needs(&cache.needs, config, ln));
16721673
decision!(ignore_llvm(config, path, ln));
16731674
decision!(ignore_backends(config, path, ln));
1675+
decision!(needs_backends(config, path, ln));
16741676
decision!(ignore_cdb(config, ln));
16751677
decision!(ignore_gdb(config, ln));
16761678
decision!(ignore_lldb(config, ln));
@@ -1817,6 +1819,29 @@ fn ignore_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecisi
18171819
IgnoreDecision::Continue
18181820
}
18191821

1822+
fn needs_backends(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
1823+
if let Some(needed_backends) = config.parse_name_value_directive(line, "needs-backends") {
1824+
if !needed_backends
1825+
.split_whitespace()
1826+
.map(|backend| match CodegenBackend::try_from(backend) {
1827+
Ok(backend) => backend,
1828+
Err(error) => {
1829+
panic!("Invalid needs-backends value `{backend}` in `{path}`: {error}")
1830+
}
1831+
})
1832+
.any(|backend| config.codegen_backend == backend)
1833+
{
1834+
return IgnoreDecision::Ignore {
1835+
reason: format!(
1836+
"{} backend is not part of required backends",
1837+
config.codegen_backend.as_str()
1838+
),
1839+
};
1840+
}
1841+
}
1842+
IgnoreDecision::Continue
1843+
}
1844+
18201845
fn ignore_llvm(config: &Config, path: &Utf8Path, line: &str) -> IgnoreDecision {
18211846
if let Some(needed_components) =
18221847
config.parse_name_value_directive(line, "needs-llvm-components")

0 commit comments

Comments
 (0)