mirror of
https://github.com/rust-lang/cargo
synced 2024-10-02 05:53:53 +00:00
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:
commit
676d866fee
|
@ -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())
|
||||
}
|
||||
|
|
|
@ -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] [..]
|
||||
",
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue