Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Merge pull request #71 from mykmelez/preserve-crate-in-dst
Browse files Browse the repository at this point in the history
preserve crate whose src dir is in the local_dst dir
  • Loading branch information
alexcrichton authored May 9, 2018
2 parents 3c524ed + 1ec0be4 commit 5683855
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
12 changes: 9 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,14 +176,21 @@ fn sync(workspaces: &[Workspace],
explicit_version: bool,
no_delete: bool,
disallow_duplicates: bool) -> CargoResult<VendorConfig> {
let canonical_local_dst = local_dst.canonicalize().unwrap_or(local_dst.to_path_buf());
let mut ids = BTreeMap::new();
let mut added_crates = Vec::new();
for ws in workspaces {
let (packages, resolve) = cargo::ops::resolve_ws(&ws).chain_err(|| {
"failed to load pkg lockfile"
})?;

for pkg in resolve.iter() {
if pkg.source_id().is_path() {
let path = pkg.source_id().url().to_file_path().expect("path");
let canonical_path = path.canonicalize().unwrap_or(path.to_path_buf());
if canonical_path.starts_with(canonical_local_dst.as_path()) {
added_crates.push(canonical_path);
}
continue
}
ids.insert(pkg.clone(), packages.get(pkg).chain_err(|| {
Expand Down Expand Up @@ -212,14 +219,13 @@ fn sync(workspaces: &[Workspace],
map.insert(id.version(), id.source_id());
}

let existing_crates = local_dst.read_dir().map(|iter| {
let existing_crates = canonical_local_dst.read_dir().map(|iter| {
iter.filter_map(|e| e.ok())
.filter(|e| e.path().join("Cargo.toml").exists())
.map(|e| e.path())
.collect::<Vec<_>>()
}).unwrap_or(Vec::new());

let mut added_crates = Vec::new();
let mut sources = BTreeSet::new();
for (id, pkg) in ids.iter() {
// Next up, copy it to the vendor directory
Expand All @@ -241,7 +247,7 @@ fn sync(workspaces: &[Workspace],
// Eg vendor/futures
id.name().to_string()
};
let dst = local_dst.join(&dst_name);
let dst = canonical_local_dst.join(&dst_name);
added_crates.push(dst.clone());
sources.insert(id.source_id());

Expand Down
37 changes: 35 additions & 2 deletions tests/vendor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ fn read(path: &Path) -> String {
fn run(cmd: &mut Command) -> (String, String) {
println!("running {:?}", cmd);
let output = cmd.output().unwrap();
println!("status: {}", output.status);
println!("stdout: ----------\n{}", String::from_utf8_lossy(&output.stdout));
println!("stderr: ----------\n{}", String::from_utf8_lossy(&output.stderr));
if !output.status.success() {
println!("stdout: ----------\n{}", String::from_utf8_lossy(&output.stdout));
println!("stderr: ----------\n{}", String::from_utf8_lossy(&output.stderr));
panic!("not successful: {}", output.status);
}

Expand Down Expand Up @@ -366,3 +367,35 @@ fn two_versions_disallowed() {
panic!("expected a failure");
}
}

#[test]
fn depend_on_vendor_dir_not_deleted() {
let dir = dir();

file(&dir, "Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
libc = "=0.2.30"
"#);
file(&dir, "src/lib.rs", "");

run(&mut vendor(&dir));

file(&dir, "Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
[dependencies]
libc = "=0.2.30"
[patch.crates-io]
libc = { path = 'vendor/libc' }
"#);

run(&mut vendor(&dir));
assert!(dir.join("vendor/libc").is_dir());
}

0 comments on commit 5683855

Please sign in to comment.