Skip to content

Commit

Permalink
Rollup merge of rust-lang#61727 - Mark-Simulacrum:crate-deps-in-deps,…
Browse files Browse the repository at this point in the history
… r=alexcrichton

Add binary dependencies to dep-info files

I'm not sure about the lack of incremental-tracking here, but since I'm pretty sure this runs on every compile anyway it might not matter? If there's a better place/way to get at the information I want, I'm happy to refactor the code to match.

r? @alexcrichton
  • Loading branch information
Centril authored Jul 24, 2019
2 parents 03f19f7 + d749b5e commit 40be400
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1468,6 +1468,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
symbol_mangling_version: SymbolManglingVersion = (SymbolManglingVersion::Legacy,
parse_symbol_mangling_version, [TRACKED],
"which mangling version to use for symbol names"),
binary_dep_depinfo: bool = (false, parse_bool, [TRACKED],
"include artifacts (sysroot, crate dependencies) used during compilation in dep-info"),
}

pub fn default_lib_output() -> CrateType {
Expand Down
3 changes: 3 additions & 0 deletions src/librustc/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,9 @@ impl Session {
pub fn print_llvm_passes(&self) -> bool {
self.opts.debugging_opts.print_llvm_passes
}
pub fn binary_dep_depinfo(&self) -> bool {
self.opts.debugging_opts.binary_dep_depinfo
}

/// Gets the features enabled for the current compilation session.
/// DO NOT USE THIS METHOD if there is a TyCtxt available, as it circumvents
Expand Down
25 changes: 22 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,30 @@ 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();

if sess.binary_dep_depinfo() {
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 @@ -750,7 +769,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 40be400

Please sign in to comment.