Skip to content

Commit 72b2716

Browse files
committed
Auto merge of #111472 - djkoloski:compiletest_cfg_current_target, r=compiler-errors
Get current target config from` --print=cfg` Compiletest was switched to querying all targets using `--print=all-target-specs-json` and `--print=target-spec-json` in #108905. This unintentionally prevented codegen flags like `-Cpanic` from being reflected in the current target configuration. This change gets the current compiletest target config using `--print=cfg` like it was previously while still using the faster prints for getting information on all other targets. Fixes #110850. `@jyn514` might be interested in reviewing since they commented on the issue. cc `@tmandry` since this issue is affecting Fuchsia.
2 parents 3ea9ad5 + 9dffb52 commit 72b2716

File tree

1 file changed

+84
-5
lines changed

1 file changed

+84
-5
lines changed

Diff for: src/tools/compiletest/src/common.rs

+84-5
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,6 @@ impl TargetCfgs {
428428
))
429429
.unwrap();
430430

431-
let mut current = None;
432431
let mut all_targets = HashSet::new();
433432
let mut all_archs = HashSet::new();
434433
let mut all_oses = HashSet::new();
@@ -449,14 +448,11 @@ impl TargetCfgs {
449448
}
450449
all_pointer_widths.insert(format!("{}bit", cfg.pointer_width));
451450

452-
if target == config.target {
453-
current = Some(cfg);
454-
}
455451
all_targets.insert(target.into());
456452
}
457453

458454
Self {
459-
current: current.expect("current target not found"),
455+
current: Self::get_current_target_config(config),
460456
all_targets,
461457
all_archs,
462458
all_oses,
@@ -467,6 +463,89 @@ impl TargetCfgs {
467463
all_pointer_widths,
468464
}
469465
}
466+
467+
fn get_current_target_config(config: &Config) -> TargetCfg {
468+
let mut arch = None;
469+
let mut os = None;
470+
let mut env = None;
471+
let mut abi = None;
472+
let mut families = Vec::new();
473+
let mut pointer_width = None;
474+
let mut endian = None;
475+
let mut panic = None;
476+
477+
for config in
478+
rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines()
479+
{
480+
let (name, value) = config
481+
.split_once("=\"")
482+
.map(|(name, value)| {
483+
(
484+
name,
485+
Some(
486+
value
487+
.strip_suffix("\"")
488+
.expect("key-value pair should be properly quoted"),
489+
),
490+
)
491+
})
492+
.unwrap_or_else(|| (config, None));
493+
494+
match name {
495+
"target_arch" => {
496+
arch = Some(value.expect("target_arch should be a key-value pair").to_string());
497+
}
498+
"target_os" => {
499+
os = Some(value.expect("target_os sould be a key-value pair").to_string());
500+
}
501+
"target_env" => {
502+
env = Some(value.expect("target_env should be a key-value pair").to_string());
503+
}
504+
"target_abi" => {
505+
abi = Some(value.expect("target_abi should be a key-value pair").to_string());
506+
}
507+
"target_family" => {
508+
families
509+
.push(value.expect("target_family should be a key-value pair").to_string());
510+
}
511+
"target_pointer_width" => {
512+
pointer_width = Some(
513+
value
514+
.expect("target_pointer_width should be a key-value pair")
515+
.parse::<u32>()
516+
.expect("target_pointer_width should be a valid u32"),
517+
);
518+
}
519+
"target_endian" => {
520+
endian = Some(match value.expect("target_endian should be a key-value pair") {
521+
"big" => Endian::Big,
522+
"little" => Endian::Little,
523+
_ => panic!("target_endian should be either 'big' or 'little'"),
524+
});
525+
}
526+
"panic" => {
527+
panic = Some(match value.expect("panic should be a key-value pair") {
528+
"abort" => PanicStrategy::Abort,
529+
"unwind" => PanicStrategy::Unwind,
530+
_ => panic!("panic should be either 'abort' or 'unwind'"),
531+
});
532+
}
533+
_ => (),
534+
}
535+
}
536+
537+
TargetCfg {
538+
arch: arch.expect("target configuration should specify target_arch"),
539+
os: os.expect("target configuration should specify target_os"),
540+
env: env.expect("target configuration should specify target_env"),
541+
abi: abi.expect("target configuration should specify target_abi"),
542+
families,
543+
pointer_width: pointer_width
544+
.expect("target configuration should specify target_pointer_width"),
545+
endian: endian.expect("target configuration should specify target_endian"),
546+
panic: panic.expect("target configuration should specify panic"),
547+
}
548+
}
470549
}
471550

472551
#[derive(Clone, Debug, serde::Deserialize)]

0 commit comments

Comments
 (0)