Skip to content

Commit 0b9209d

Browse files
committed
Set RUST_SAVE_ANALYSIS_CONFIG env variable for run-pass tests
This fixes rust-lang#96928 by setting the RUST_SAVE_ANALYSIS_CONFIG environment variable for run-pass tests in order to change the location where the result of the analysis is saved.
1 parent f55b002 commit 0b9209d

File tree

2 files changed

+27
-19
lines changed

2 files changed

+27
-19
lines changed

compiler/rustc_save_analysis/src/lib.rs

+16-19
Original file line numberDiff line numberDiff line change
@@ -897,28 +897,25 @@ impl<'a> DumpHandler<'a> {
897897

898898
fn output_file(&self, ctx: &SaveContext<'_>) -> (BufWriter<File>, PathBuf) {
899899
let sess = &ctx.tcx.sess;
900-
let file_name = match ctx.config.output_file {
901-
Some(ref s) => PathBuf::from(s),
900+
let mut root_path = match self.odir {
901+
Some(val) => val.join("save-analysis"),
902902
None => {
903-
let mut root_path = match self.odir {
904-
Some(val) => val.join("save-analysis"),
905-
None => PathBuf::from("save-analysis-temp"),
906-
};
907-
908-
if let Err(e) = std::fs::create_dir_all(&root_path) {
909-
error!("Could not create directory {}: {}", root_path.display(), e);
910-
}
911-
912-
let executable = sess.crate_types().iter().any(|ct| *ct == CrateType::Executable);
913-
let mut out_name = if executable { String::new() } else { "lib".to_owned() };
914-
out_name.push_str(&self.cratename);
915-
out_name.push_str(&sess.opts.cg.extra_filename);
916-
out_name.push_str(".json");
917-
root_path.push(&out_name);
918-
919-
root_path
903+
PathBuf::from(ctx.config.output_file.as_ref().unwrap()).join("save-analysis-temp")
920904
}
921905
};
906+
if let Err(e) = std::fs::create_dir_all(&root_path) {
907+
error!("Could not create directory {}: {}", root_path.display(), e);
908+
}
909+
let file_name = {
910+
let executable = sess.crate_types().iter().any(|ct| *ct == CrateType::Executable);
911+
let mut out_name = if executable { String::new() } else { "lib".to_owned() };
912+
out_name.push_str(&self.cratename);
913+
out_name.push_str(&sess.opts.cg.extra_filename);
914+
out_name.push_str(".json");
915+
root_path.push(&out_name);
916+
917+
root_path
918+
};
922919

923920
info!("Writing output to {}", file_name.display());
924921

src/tools/compiletest/src/runtest.rs

+11
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,17 @@ impl<'test> TestCx<'test> {
20112011

20122012
match output_file {
20132013
TargetLocation::ThisFile(path) => {
2014+
// The idea here is to use the env variable to pass the build_base directory to rustc_save_analysis to be used in cases where there is no output directory
2015+
// Use of double backslash in `base` below is to cater for paths in Windows OS
2016+
env::set_var(
2017+
"RUST_SAVE_ANALYSIS_CONFIG",
2018+
format!(
2019+
"{{\"output_file\": \"{base}\",\"full_docs\": false,\
2020+
\"pub_only\": true,\"reachable_only\": false,\
2021+
\"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}}",
2022+
base = self.config.build_base.display().to_string().replace("\\", "\\\\"),
2023+
),
2024+
);
20142025
rustc.arg("-o").arg(path);
20152026
}
20162027
TargetLocation::ThisDirectory(path) => {

0 commit comments

Comments
 (0)