diff --git a/compiler/rustc_save_analysis/src/lib.rs b/compiler/rustc_save_analysis/src/lib.rs index a9a92cc4f62ed..92fbfe24325d3 100644 --- a/compiler/rustc_save_analysis/src/lib.rs +++ b/compiler/rustc_save_analysis/src/lib.rs @@ -897,28 +897,25 @@ impl<'a> DumpHandler<'a> { fn output_file(&self, ctx: &SaveContext<'_>) -> (BufWriter, PathBuf) { let sess = &ctx.tcx.sess; - let file_name = match ctx.config.output_file { - Some(ref s) => PathBuf::from(s), + let mut root_path = match self.odir { + Some(val) => val.join("save-analysis"), None => { - let mut root_path = match self.odir { - Some(val) => val.join("save-analysis"), - None => PathBuf::from("save-analysis-temp"), - }; - - if let Err(e) = std::fs::create_dir_all(&root_path) { - error!("Could not create directory {}: {}", root_path.display(), e); - } - - let executable = sess.crate_types().iter().any(|ct| *ct == CrateType::Executable); - let mut out_name = if executable { String::new() } else { "lib".to_owned() }; - out_name.push_str(&self.cratename); - out_name.push_str(&sess.opts.cg.extra_filename); - out_name.push_str(".json"); - root_path.push(&out_name); - - root_path + PathBuf::from(ctx.config.output_file.as_ref().unwrap()).join("save-analysis-temp") } }; + if let Err(e) = std::fs::create_dir_all(&root_path) { + error!("Could not create directory {}: {}", root_path.display(), e); + } + let file_name = { + let executable = sess.crate_types().iter().any(|ct| *ct == CrateType::Executable); + let mut out_name = if executable { String::new() } else { "lib".to_owned() }; + out_name.push_str(&self.cratename); + out_name.push_str(&sess.opts.cg.extra_filename); + out_name.push_str(".json"); + root_path.push(&out_name); + + root_path + }; info!("Writing output to {}", file_name.display()); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 51c9a27c83d51..514c818df315b 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2011,6 +2011,16 @@ impl<'test> TestCx<'test> { match output_file { TargetLocation::ThisFile(path) => { + // 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 + env::set_var( + "RUST_SAVE_ANALYSIS_CONFIG", + format!( + "{{\"output_file\": \"{base}\",\"full_docs\": false,\ + \"pub_only\": true,\"reachable_only\": false,\ + \"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}}", + base = self.config.build_base.display(), + ), + ); rustc.arg("-o").arg(path); } TargetLocation::ThisDirectory(path) => {