Skip to content

Commit b2032e4

Browse files
Rollup merge of rust-lang#106789 - azadnn:save-analysis-for-runpass-tests, r=Mark-Simulacrum
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.
2 parents 6cdc68f + d8b033c commit b2032e4

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
@@ -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

+10
Original file line numberDiff line numberDiff line change
@@ -2011,6 +2011,16 @@ 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+
env::set_var(
2016+
"RUST_SAVE_ANALYSIS_CONFIG",
2017+
format!(
2018+
"{{\"output_file\": \"{base}\",\"full_docs\": false,\
2019+
\"pub_only\": true,\"reachable_only\": false,\
2020+
\"distro_crate\": true,\"signatures\": false,\"borrow_data\": false}}",
2021+
base = self.config.build_base.display(),
2022+
),
2023+
);
20142024
rustc.arg("-o").arg(path);
20152025
}
20162026
TargetLocation::ThisDirectory(path) => {

0 commit comments

Comments
 (0)