Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remap-path-prefix from failing. #7219

Merged
merged 1 commit into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}