Skip to content

Commit b2b676d

Browse files
committed
Auto merge of rust-lang#108905 - ferrocene:pa-compiletest-ignore, r=ehuss
Validate `ignore` and `only` compiletest directive, and add human-readable ignore reasons This PR adds strict validation for the `ignore` and `only` compiletest directives, failing if an unknown value is provided to them. Doing so uncovered 79 tests in `tests/ui` that had invalid directives, so this PR also fixes them. Finally, this PR adds human-readable ignore reasons when tests are ignored due to `ignore` or `only` directives, like *"only executed when the architecture is aarch64"* or *"ignored when the operative system is windows"*. This was the original reason why I started working on this PR and rust-lang#108659, as we need both of them for Ferrocene. The PR is a draft because the code is extremely inefficient: it calls `rustc --print=cfg --target $target` for every rustc target (to gather the list of allowed ignore values), which on my system takes between 4s and 5s, and performs a lot of allocations of constant values. I'll fix both of them in the coming days. r? `@ehuss`
2 parents 4cb92cc + bbcbb6f commit b2b676d

File tree

75 files changed

+720
-506
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

75 files changed

+720
-506
lines changed

compiler/rustc_driver_impl/src/lib.rs

+11
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ use rustc_session::{early_error, early_error_no_abort, early_warn};
4444
use rustc_span::source_map::{FileLoader, FileName};
4545
use rustc_span::symbol::sym;
4646
use rustc_target::json::ToJson;
47+
use rustc_target::spec::{Target, TargetTriple};
4748

4849
use std::cmp::max;
50+
use std::collections::BTreeMap;
4951
use std::env;
5052
use std::ffi::OsString;
5153
use std::fs;
@@ -648,6 +650,15 @@ fn print_crate_info(
648650
TargetSpec => {
649651
println!("{}", serde_json::to_string_pretty(&sess.target.to_json()).unwrap());
650652
}
653+
AllTargetSpecs => {
654+
let mut targets = BTreeMap::new();
655+
for name in rustc_target::spec::TARGETS {
656+
let triple = TargetTriple::from_triple(name);
657+
let target = Target::expect_builtin(&triple);
658+
targets.insert(name, target.to_json());
659+
}
660+
println!("{}", serde_json::to_string_pretty(&targets).unwrap());
661+
}
651662
FileNames | CrateName => {
652663
let Some(attrs) = attrs.as_ref() else {
653664
// no crate attributes, print out an error and exit

compiler/rustc_session/src/config.rs

+16-3
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ pub enum PrintRequest {
582582
CodeModels,
583583
TlsModels,
584584
TargetSpec,
585+
AllTargetSpecs,
585586
NativeStaticLibs,
586587
StackProtectorStrategies,
587588
LinkArgs,
@@ -1441,8 +1442,8 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
14411442
"Compiler information to print on stdout",
14421443
"[crate-name|file-names|sysroot|target-libdir|cfg|calling-conventions|\
14431444
target-list|target-cpus|target-features|relocation-models|code-models|\
1444-
tls-models|target-spec-json|native-static-libs|stack-protector-strategies|\
1445-
link-args]",
1445+
tls-models|target-spec-json|all-target-specs-json|native-static-libs|\
1446+
stack-protector-strategies|link-args]",
14461447
),
14471448
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
14481449
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
@@ -1889,6 +1890,7 @@ fn collect_print_requests(
18891890
("native-static-libs", PrintRequest::NativeStaticLibs),
18901891
("stack-protector-strategies", PrintRequest::StackProtectorStrategies),
18911892
("target-spec-json", PrintRequest::TargetSpec),
1893+
("all-target-specs-json", PrintRequest::AllTargetSpecs),
18921894
("link-args", PrintRequest::LinkArgs),
18931895
("split-debuginfo", PrintRequest::SplitDebuginfo),
18941896
];
@@ -1902,7 +1904,18 @@ fn collect_print_requests(
19021904
early_error(
19031905
error_format,
19041906
"the `-Z unstable-options` flag must also be passed to \
1905-
enable the target-spec-json print option",
1907+
enable the target-spec-json print option",
1908+
);
1909+
}
1910+
}
1911+
Some((_, PrintRequest::AllTargetSpecs)) => {
1912+
if unstable_opts.unstable_options {
1913+
PrintRequest::AllTargetSpecs
1914+
} else {
1915+
early_error(
1916+
error_format,
1917+
"the `-Z unstable-options` flag must also be passed to \
1918+
enable the all-target-specs-json print option",
19061919
);
19071920
}
19081921
}

src/bootstrap/test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ impl Step for CompiletestTest {
694694
/// Runs `cargo test` for compiletest.
695695
fn run(self, builder: &Builder<'_>) {
696696
let host = self.host;
697-
let compiler = builder.compiler(0, host);
697+
let compiler = builder.compiler(1, host);
698698

699699
// We need `ToolStd` for the locally-built sysroot because
700700
// compiletest uses unstable features of the `test` crate.

0 commit comments

Comments
 (0)