Skip to content

Commit 676d866

Browse files
committed
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
2 parents 90fc9f6 + 6e57be5 commit 676d866

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

src/cargo/core/compiler/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -680,8 +680,10 @@ fn path_args(bcx: &BuildContext, unit: &Unit) -> (PathBuf, PathBuf) {
680680
unit.target.src_path().path().to_path_buf()
681681
};
682682
assert!(src.is_absolute());
683-
if let Ok(path) = src.strip_prefix(ws_root) {
684-
return (path.to_path_buf(), ws_root.to_path_buf());
683+
if unit.pkg.package_id().source_id().is_path() {
684+
if let Ok(path) = src.strip_prefix(ws_root) {
685+
return (path.to_path_buf(), ws_root.to_path_buf());
686+
}
685687
}
686688
(src, unit.pkg.root().to_path_buf())
687689
}

tests/testsuite/directory.rs

Lines changed: 63 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ fn setup() {
1616
t!(fs::create_dir(&root.join(".cargo")));
1717
t!(t!(File::create(root.join(".cargo/config"))).write_all(
1818
br#"
19-
[source.crates-io]
20-
replace-with = 'my-awesome-local-registry'
19+
[source.crates-io]
20+
replace-with = 'my-awesome-local-registry'
2121
22-
[source.my-awesome-local-registry]
23-
directory = 'index'
24-
"#
22+
[source.my-awesome-local-registry]
23+
directory = 'index'
24+
"#
2525
));
2626
}
2727

@@ -643,3 +643,61 @@ restore the source replacement configuration to continue the build
643643
),
644644
);
645645
}
646+
647+
#[test]
648+
fn workspace_different_locations() {
649+
let p = project()
650+
.no_manifest()
651+
.file(
652+
"foo/Cargo.toml",
653+
r#"
654+
[package]
655+
name = 'foo'
656+
version = '0.1.0'
657+
658+
[dependencies]
659+
baz = "*"
660+
"#,
661+
)
662+
.file("foo/src/lib.rs", "")
663+
.file("foo/vendor/baz/Cargo.toml", &basic_manifest("baz", "0.1.0"))
664+
.file("foo/vendor/baz/src/lib.rs", "")
665+
.file("foo/vendor/baz/.cargo-checksum.json", "{\"files\":{}}")
666+
.file(
667+
"bar/Cargo.toml",
668+
r#"
669+
[package]
670+
name = 'bar'
671+
version = '0.1.0'
672+
673+
[dependencies]
674+
baz = "*"
675+
"#,
676+
)
677+
.file("bar/src/lib.rs", "")
678+
.file(
679+
".cargo/config",
680+
r#"
681+
[build]
682+
target-dir = './target'
683+
684+
[source.crates-io]
685+
replace-with = 'my-awesome-local-registry'
686+
687+
[source.my-awesome-local-registry]
688+
directory = 'foo/vendor'
689+
"#,
690+
)
691+
.build();
692+
693+
assert_that(p.cargo("build").cwd(p.root().join("foo")), execs());
694+
assert_that(
695+
p.cargo("build").cwd(p.root().join("bar")),
696+
execs().with_status(0).with_stderr(
697+
"\
698+
[COMPILING] bar [..]
699+
[FINISHED] [..]
700+
",
701+
),
702+
);
703+
}

0 commit comments

Comments
 (0)