Auto merge of #5935 - alexcrichton:vendor-paths, r=ehuss

Only use non-absolute paths for `path` dependencies

Previously Cargo would use a non-absolute path for any dependency contained
within the workspace root but this switches Cargo to only using relative paths
for `path` dependencies. In practice this shouldn't make much difference, but
for vendored crates and moving around `CARGO_HOME` it can produce more
consistent results when target directories are shared.

Closes #5923
This commit is contained in:
bors 2018-08-24 19:37:00 +00:00
commit 676d866fee
2 changed files with 67 additions and 7 deletions

View file

@ -680,9 +680,11 @@ fn path_args(bcx: &BuildContext, unit: &Unit) -> (PathBuf, PathBuf) {
unit.target.src_path().path().to_path_buf()
};
assert!(src.is_absolute());
if unit.pkg.package_id().source_id().is_path() {
if let Ok(path) = src.strip_prefix(ws_root) {
return (path.to_path_buf(), ws_root.to_path_buf());
}
}
(src, unit.pkg.root().to_path_buf())
}

View file

@ -643,3 +643,61 @@ restore the source replacement configuration to continue the build
),
);
}
#[test]
fn workspace_different_locations() {
let p = project()
.no_manifest()
.file(
"foo/Cargo.toml",
r#"
[package]
name = 'foo'
version = '0.1.0'
[dependencies]
baz = "*"
"#,
)
.file("foo/src/lib.rs", "")
.file("foo/vendor/baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
.file("foo/vendor/baz/src/lib.rs", "")
.file("foo/vendor/baz/.cargo-checksum.json", "{\"files\":{}}")
.file(
"bar/Cargo.toml",
r#"
[package]
name = 'bar'
version = '0.1.0'
[dependencies]
baz = "*"
"#,
)
.file("bar/src/lib.rs", "")
.file(
".cargo/config",
r#"
[build]
target-dir = './target'
[source.crates-io]
replace-with = 'my-awesome-local-registry'
[source.my-awesome-local-registry]
directory = 'foo/vendor'
"#,
)
.build();
assert_that(p.cargo("build").cwd(p.root().join("foo")), execs());
assert_that(
p.cargo("build").cwd(p.root().join("bar")),
execs().with_status(0).with_stderr(
"\
[COMPILING] bar [..]
[FINISHED] [..]
",
),
);
}