diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-01-09 05:33:22 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-09 05:33:22 +0100 |
| commit | 985b2ce70dda2aa73a0efd15fd38d2f2eb50b3ff (patch) | |
| tree | 80184b7ab70fea8a5c0b4cb6f622f404230b5a23 /src/tools | |
| parent | b0c492cd6e5237ab64adcdc229293ab127ecc3ab (diff) | |
| parent | b888e2f82b9dbe81875f50d13adbc0271a9401ff (diff) | |
| download | rust-985b2ce70dda2aa73a0efd15fd38d2f2eb50b3ff.tar.gz rust-985b2ce70dda2aa73a0efd15fd38d2f2eb50b3ff.zip | |
Rollup merge of #119619 - onur-ozkan:panic-abort-mir-opt, r=oli-obk
mir-opt and custom target fixes From https://github.com/rust-lang/rust/issues/115642#issuecomment-1879589022 > > Could you please test the last two commits from https://github.com/onur-ozkan/rust/commits/panic-abort-mir-opt when you have the time? The first commit should resolve the error of using the nightly flag with a stable compiler, and the second one should resolve the custom target issue. > I tested with the two commits and the errors of using nightly flag and custom target specs were not seen. Testing was completed for the test suites like ui, run-pass-valgrind, coverage, mir-opt, codegen, assembly, incremental. Fixes #115642
Diffstat (limited to 'src/tools')
| -rw-r--r-- | src/tools/compiletest/src/common.rs | 45 |
1 files changed, 33 insertions, 12 deletions
diff --git a/src/tools/compiletest/src/common.rs b/src/tools/compiletest/src/common.rs index 4cf5a710586..49f1226e2cc 100644 --- a/src/tools/compiletest/src/common.rs +++ b/src/tools/compiletest/src/common.rs @@ -483,6 +483,7 @@ impl TargetCfgs { let mut targets: HashMap<String, TargetCfg> = serde_json::from_str(&rustc_output( config, &["--print=all-target-specs-json", "-Zunstable-options"], + Default::default(), )) .unwrap(); @@ -495,16 +496,33 @@ impl TargetCfgs { let mut all_families = HashSet::new(); let mut all_pointer_widths = HashSet::new(); - // Handle custom target specs, which are not included in `--print=all-target-specs-json`. - if config.target.ends_with(".json") { - targets.insert( - config.target.clone(), - serde_json::from_str(&rustc_output( - config, - &["--print=target-spec-json", "-Zunstable-options", "--target", &config.target], - )) - .unwrap(), - ); + // If current target is not included in the `--print=all-target-specs-json` output, + // we check whether it is a custom target from the user or a synthetic target from bootstrap. + if !targets.contains_key(&config.target) { + let mut envs: HashMap<String, String> = HashMap::new(); + + if let Ok(t) = std::env::var("RUST_TARGET_PATH") { + envs.insert("RUST_TARGET_PATH".into(), t); + } + + // This returns false only when the target is neither a synthetic target + // nor a custom target from the user, indicating it is most likely invalid. + if config.target.ends_with(".json") || !envs.is_empty() { + targets.insert( + config.target.clone(), + serde_json::from_str(&rustc_output( + config, + &[ + "--print=target-spec-json", + "-Zunstable-options", + "--target", + &config.target, + ], + envs, + )) + .unwrap(), + ); + } } for (target, cfg) in targets.iter() { @@ -549,7 +567,9 @@ impl TargetCfgs { // code below extracts them from `--print=cfg`: make sure to only override fields that can // actually be changed with `-C` flags. for config in - rustc_output(config, &["--print=cfg", "--target", &config.target]).trim().lines() + rustc_output(config, &["--print=cfg", "--target", &config.target], Default::default()) + .trim() + .lines() { let (name, value) = config .split_once("=\"") @@ -628,11 +648,12 @@ pub enum Endian { Big, } -fn rustc_output(config: &Config, args: &[&str]) -> String { +fn rustc_output(config: &Config, args: &[&str], envs: HashMap<String, String>) -> String { let mut command = Command::new(&config.rustc_path); add_dylib_path(&mut command, iter::once(&config.compile_lib_path)); command.args(&config.target_rustcflags).args(args); command.env("RUSTC_BOOTSTRAP", "1"); + command.envs(envs); let output = match command.output() { Ok(output) => output, |
