Skip to content

Commit

Permalink
Add binary dependencies to dep-info files
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Simulacrum committed Jun 10, 2019
1 parent 400b409 commit da73a36
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use rustc::hir::lowering::lower_crate;
use rustc::hir::def_id::{CrateNum, LOCAL_CRATE};
use rustc::lint;
use rustc::middle::{self, reachable, resolve_lifetime, stability};
use rustc::middle::cstore::CrateStore;
use rustc::middle::privacy::AccessLevels;
use rustc::ty::{self, AllArenas, Resolutions, TyCtxt, GlobalCtxt};
use rustc::ty::steal::Steal;
Expand Down Expand Up @@ -657,7 +658,8 @@ fn escape_dep_filename(filename: &FileName) -> String {
filename.to_string().replace(" ", "\\ ")
}

fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[PathBuf]) {
fn write_out_deps(compiler: &Compiler, outputs: &OutputFilenames, out_filenames: &[PathBuf]) {
let sess = &compiler.sess;
// Write out dependency rules to the dep-info file if requested
if !sess.opts.output_types.contains_key(&OutputType::DepInfo) {
return;
Expand All @@ -667,13 +669,28 @@ fn write_out_deps(sess: &Session, outputs: &OutputFilenames, out_filenames: &[Pa
let result = (|| -> io::Result<()> {
// Build a list of files used to compile the output and
// write Makefile-compatible dependency rules
let files: Vec<String> = sess.source_map()
let mut files: Vec<String> = sess.source_map()
.files()
.iter()
.filter(|fmap| fmap.is_real_file())
.filter(|fmap| !fmap.is_imported())
.map(|fmap| escape_dep_filename(&fmap.name))
.collect();

for cnum in compiler.cstore.crates_untracked() {
let metadata = compiler.cstore.crate_data_as_rc_any(cnum);
let metadata = metadata.downcast_ref::<cstore::CrateMetadata>().unwrap();
if let Some((path, _)) = &metadata.source.dylib {
files.push(escape_dep_filename(&FileName::Real(path.clone())));
}
if let Some((path, _)) = &metadata.source.rlib {
files.push(escape_dep_filename(&FileName::Real(path.clone())));
}
if let Some((path, _)) = &metadata.source.rmeta {
files.push(escape_dep_filename(&FileName::Real(path.clone())));
}
}

let mut file = fs::File::create(&deps_filename)?;
for path in out_filenames {
writeln!(file, "{}: {}\n", path.display(), files.join(" "))?;
Expand Down Expand Up @@ -742,7 +759,7 @@ pub fn prepare_outputs(
}
}

write_out_deps(sess, &outputs, &output_paths);
write_out_deps(compiler, &outputs, &output_paths);

let only_dep_info = sess.opts.output_types.contains_key(&OutputType::DepInfo)
&& sess.opts.output_types.len() == 1;
Expand Down

0 comments on commit da73a36

Please sign in to comment.