Skip to content

Commit d8b033c

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 2b8590e commit d8b033c

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

compiler/rustc_save_analysis/src/lib.rs

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

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

925922
info!("Writing output to {}", file_name.display());
926923

src/tools/compiletest/src/runtest.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1994,6 +1994,16 @@ impl<'test> TestCx<'test> {
19941994

19951995
match output_file {
19961996
TargetLocation::ThisFile(path) => {
1997+
// 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
1998+
env::set_var(
1999+
"RUST_SAVE_ANALYSIS_CONFIG",
2000+
format!(
2001+
"{{\"output_file\": \"{base}\",\"full_docs\": false,\
2002+
\"pub_only\": true,\"reachable_only\": false,\
2003+
\"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}}",
2004+
base = self.config.build_base.display(),
2005+
),
2006+
);
19972007
rustc.arg("-o").arg(path);
19982008
}
19992009
TargetLocation::ThisDirectory(path) => {

0 commit comments

Comments
 (0)