Skip to content

Commit

Permalink
Auto merge of #5935 - alexcrichton:vendor-paths, r=ehuss
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bors committed Aug 24, 2018
2 parents 90fc9f6 + 6e57be5 commit 676d866
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 7 deletions.
6 changes: 4 additions & 2 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,10 @@ fn path_args(bcx: &BuildContext, unit: &Unit) -> (PathBuf, PathBuf) {
unit.target.src_path().path().to_path_buf()
};
assert!(src.is_absolute());
if let Ok(path) = src.strip_prefix(ws_root) {
return (path.to_path_buf(), ws_root.to_path_buf());
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())
}
Expand Down
68 changes: 63 additions & 5 deletions tests/testsuite/directory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ fn setup() {
t!(fs::create_dir(&root.join(".cargo")));
t!(t!(File::create(root.join(".cargo/config"))).write_all(
br#"
[source.crates-io]
replace-with = 'my-awesome-local-registry'
[source.crates-io]
replace-with = 'my-awesome-local-registry'
[source.my-awesome-local-registry]
directory = 'index'
"#
[source.my-awesome-local-registry]
directory = 'index'
"#
));
}

Expand Down Expand Up @@ -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] [..]
",
),
);
}

0 comments on commit 676d866

Please sign in to comment.