Skip to content

Commit

Permalink
Rollup merge of rust-lang#106789 - azadnn:save-analysis-for-runpass-t…
Browse files Browse the repository at this point in the history
…ests, 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.
  • Loading branch information
compiler-errors authored Jan 29, 2023
2 parents 6cdc68f + d8b033c commit b2032e4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
35 changes: 16 additions & 19 deletions compiler/rustc_save_analysis/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -897,28 +897,25 @@ impl<'a> DumpHandler<'a> {

fn output_file(&self, ctx: &SaveContext<'_>) -> (BufWriter<File>, 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());

Expand Down
10 changes: 10 additions & 0 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit b2032e4

Please sign in to comment.