Skip to content

Commit

Permalink
Auto merge of #10668 - weihanglo:issue-10652, r=ehuss
Browse files Browse the repository at this point in the history
Normalize path for `cargo vendor` output
  • Loading branch information
bors committed Jul 16, 2022
2 parents bd5db30 + 88e8892 commit 576356f
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/cargo/ops/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ struct VendorConfig {
#[serde(rename_all = "lowercase", untagged)]
enum VendorSource {
Directory {
directory: PathBuf,
directory: String,
},
Registry {
registry: Option<String>,
Expand Down Expand Up @@ -298,7 +298,10 @@ fn sync(
config.insert(
merged_source_name.to_string(),
VendorSource::Directory {
directory: opts.destination.to_path_buf(),
// Windows-flavour paths are valid here on Windows but Unix.
// This backslash normalization is for making output paths more
// cross-platform compatible.
directory: opts.destination.to_string_lossy().replace("\\", "/"),
},
);
} else if !dest_dir_already_exists {
Expand Down
49 changes: 48 additions & 1 deletion tests/testsuite/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,53 @@ directory = "vendor"
.run();
}

#[cargo_test]
fn vendor_path_specified() {
let p = project()
.file(
"Cargo.toml",
r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
log = "0.3.5"
"#,
)
.file("src/lib.rs", "")
.build();

Package::new("log", "0.3.5").publish();

let path = if cfg!(windows) {
r#"deps\.vendor"#
} else {
"deps/.vendor"
};

let output = p
.cargo("vendor --respect-source-config")
.arg(path)
.exec_with_output()
.unwrap();
// Assert against original output to ensure that
// path is normalized by `ops::vendor` on Windows.
assert_eq!(
&String::from_utf8(output.stdout).unwrap(),
r#"
[source.crates-io]
replace-with = "vendored-sources"
[source.vendored-sources]
directory = "deps/.vendor"
"#
);

let lock = p.read_file("deps/.vendor/log/Cargo.toml");
assert!(lock.contains("version = \"0.3.5\""));
}

fn add_vendor_config(p: &Project) {
p.change_file(
".cargo/config",
Expand Down Expand Up @@ -117,7 +164,7 @@ fn package_exclude() {
.publish();

p.cargo("vendor --respect-source-config").run();
let csum = dbg!(p.read_file("vendor/bar/.cargo-checksum.json"));
let csum = p.read_file("vendor/bar/.cargo-checksum.json");
assert!(csum.contains(".include"));
assert!(!csum.contains(".exclude"));
assert!(!csum.contains(".dotdir/exclude"));
Expand Down

0 comments on commit 576356f

Please sign in to comment.