From 6e57be51602cab15f0e9f0111b749d9eab593a77 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 23 Aug 2018 11:51:05 -0700 Subject: [PATCH] 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 --- src/cargo/core/compiler/mod.rs | 6 ++- tests/testsuite/directory.rs | 68 +++++++++++++++++++++++++++++++--- 2 files changed, 67 insertions(+), 7 deletions(-) diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs index a3106e93144..787889439d2 100644 --- a/src/cargo/core/compiler/mod.rs +++ b/src/cargo/core/compiler/mod.rs @@ -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()) } diff --git a/tests/testsuite/directory.rs b/tests/testsuite/directory.rs index 00934d496ba..f22ea5bc2cf 100644 --- a/tests/testsuite/directory.rs +++ b/tests/testsuite/directory.rs @@ -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' + "# )); } @@ -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] [..] +", + ), + ); +}