Skip to content

Commit

Permalink
Fix remap-path-prefix from failing.
Browse files Browse the repository at this point in the history
  • Loading branch information
ehuss committed Aug 6, 2019
1 parent c604416 commit ec9222a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/cargo/core/compiler/fingerprint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,8 +1581,11 @@ pub fn translate_dep_info(
for file in deps {
// The path may be absolute or relative, canonical or not. Make sure
// it is canonicalized so we are comparing the same kinds of paths.
let canon_file = rustc_cwd.join(file).canonicalize()?;
let abs_file = rustc_cwd.join(file);
// If canonicalization fails, just use the abs path. There is currently
// a bug where --remap-path-prefix is affecting .d files, causing them
// to point to non-existent paths.
let canon_file = abs_file.canonicalize().unwrap_or_else(|_| abs_file.clone());

let (ty, path) = if let Ok(stripped) = canon_file.strip_prefix(&target_root) {
(DepInfoPathType::TargetRootRelative, stripped)
Expand Down
44 changes: 42 additions & 2 deletions tests/testsuite/rustflags.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
use std::fs::{self, File};
use std::io::Write;

use crate::support::rustc_host;
use crate::support::{basic_lib_manifest, basic_manifest, paths, project, project_in_home};
use crate::support::registry::Package;
use crate::support::{
basic_lib_manifest, basic_manifest, paths, project, project_in_home, rustc_host,
};

#[cargo_test]
fn env_rustflags_normal_source() {
Expand Down Expand Up @@ -1393,3 +1395,41 @@ fn remap_path_prefix_ignored() {
.run();
check_metadata_same();
}

#[cargo_test]
fn remap_path_prefix_works() {
// Check that remap-path-prefix works.
Package::new("bar", "0.1.0")
.file("src/lib.rs", "pub fn f() -> &'static str { file!() }")
.publish();

let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
bar = "0.1"
"#,
)
.file(
"src/main.rs",
r#"
fn main() {
println!("{}", bar::f());
}
"#,
)
.build();

p.cargo("run")
.env(
"RUSTFLAGS",
format!("--remap-path-prefix={}=/foo", paths::root().display()),
)
.with_stdout("/foo/home/.cargo/registry/src/[..]/bar-0.1.0/src/lib.rs")
.run();
}

0 comments on commit ec9222a

Please sign in to comment.