Skip to content

Commit 576356f

Browse files
committed
Auto merge of #10668 - weihanglo:issue-10652, r=ehuss
Normalize path for `cargo vendor` output
2 parents bd5db30 + 88e8892 commit 576356f

File tree

2 files changed

+53
-3
lines changed

2 files changed

+53
-3
lines changed

src/cargo/ops/vendor.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ struct VendorConfig {
6060
#[serde(rename_all = "lowercase", untagged)]
6161
enum VendorSource {
6262
Directory {
63-
directory: PathBuf,
63+
directory: String,
6464
},
6565
Registry {
6666
registry: Option<String>,
@@ -298,7 +298,10 @@ fn sync(
298298
config.insert(
299299
merged_source_name.to_string(),
300300
VendorSource::Directory {
301-
directory: opts.destination.to_path_buf(),
301+
// Windows-flavour paths are valid here on Windows but Unix.
302+
// This backslash normalization is for making output paths more
303+
// cross-platform compatible.
304+
directory: opts.destination.to_string_lossy().replace("\\", "/"),
302305
},
303306
);
304307
} else if !dest_dir_already_exists {

tests/testsuite/vendor.rs

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,53 @@ directory = "vendor"
6969
.run();
7070
}
7171

72+
#[cargo_test]
73+
fn vendor_path_specified() {
74+
let p = project()
75+
.file(
76+
"Cargo.toml",
77+
r#"
78+
[package]
79+
name = "foo"
80+
version = "0.1.0"
81+
82+
[dependencies]
83+
log = "0.3.5"
84+
"#,
85+
)
86+
.file("src/lib.rs", "")
87+
.build();
88+
89+
Package::new("log", "0.3.5").publish();
90+
91+
let path = if cfg!(windows) {
92+
r#"deps\.vendor"#
93+
} else {
94+
"deps/.vendor"
95+
};
96+
97+
let output = p
98+
.cargo("vendor --respect-source-config")
99+
.arg(path)
100+
.exec_with_output()
101+
.unwrap();
102+
// Assert against original output to ensure that
103+
// path is normalized by `ops::vendor` on Windows.
104+
assert_eq!(
105+
&String::from_utf8(output.stdout).unwrap(),
106+
r#"
107+
[source.crates-io]
108+
replace-with = "vendored-sources"
109+
110+
[source.vendored-sources]
111+
directory = "deps/.vendor"
112+
"#
113+
);
114+
115+
let lock = p.read_file("deps/.vendor/log/Cargo.toml");
116+
assert!(lock.contains("version = \"0.3.5\""));
117+
}
118+
72119
fn add_vendor_config(p: &Project) {
73120
p.change_file(
74121
".cargo/config",
@@ -117,7 +164,7 @@ fn package_exclude() {
117164
.publish();
118165

119166
p.cargo("vendor --respect-source-config").run();
120-
let csum = dbg!(p.read_file("vendor/bar/.cargo-checksum.json"));
167+
let csum = p.read_file("vendor/bar/.cargo-checksum.json");
121168
assert!(csum.contains(".include"));
122169
assert!(!csum.contains(".exclude"));
123170
assert!(!csum.contains(".dotdir/exclude"));

0 commit comments

Comments
 (0)