in src/compiler/rust.rs [2224:2278]
fn handle_outputs(
self: Box<Self>,
path_transformer: &dist::PathTransformer,
output_paths: &[PathBuf],
extra_inputs: &[PathBuf],
) -> Result<()> {
use std::io::Write;
// Outputs in dep files (the files at the beginning of lines) are untransformed at this point -
// remap-path-prefix is documented to only apply to 'inputs'.
trace!("Pondering on rewriting dep file {:?}", self.dep_info);
if let Some(dep_info) = self.dep_info {
let extra_input_str = extra_inputs
.iter()
.fold(String::new(), |s, p| s + " " + &p.to_string_lossy());
for dep_info_local_path in output_paths {
trace!("Comparing with {}", dep_info_local_path.display());
if dep_info == *dep_info_local_path {
info!("Replacing using the transformer {:?}", path_transformer);
// Found the dep info file, read it in
let f = fs::File::open(&dep_info)
.with_context(|| "Failed to open dep info file")?;
let mut deps = String::new();
{ f }.read_to_string(&mut deps)?;
// Replace all the output paths, at the beginning of lines
for (local_path, dist_path) in get_path_mappings(path_transformer) {
let re_str = format!("(?m)^{}", regex::escape(&dist_path));
let local_path_str = local_path.to_str().with_context(|| {
format!(
"could not convert {} to string for RE replacement",
local_path.display()
)
})?;
error!(
"RE replacing {} with {} in {}",
re_str, local_path_str, deps
);
let re = regex::Regex::new(&re_str).expect("Invalid regex");
deps = re.replace_all(&deps, local_path_str).into_owned();
}
if !extra_inputs.is_empty() {
deps = deps.replace(": ", &format!(":{} ", extra_input_str));
}
// Write the depinfo file
let f =
fs::File::create(&dep_info).context("Failed to recreate dep info file")?;
{ f }.write_all(deps.as_bytes())?;
return Ok(());
}
}
// We expected there to be dep info, but none of the outputs matched
bail!("No outputs matched dep info file {}", dep_info.display());
}
Ok(())
}