[go: up one dir, main page]

Skip to content

Commit

Permalink
Auto merge of rust-lang#4584 - alexcrichton:beta-next, r=matklad
Browse files Browse the repository at this point in the history
[beta] Fix [patch] causing updates with a virtual manifest

This is a backport of rust-lang#4583
  • Loading branch information
bors committed Oct 6, 2017
2 parents 5068cb6 + f0a5263 commit 3423351
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 24 deletions.
68 changes: 44 additions & 24 deletions src/cargo/core/resolver/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::str::FromStr;
use serde::ser;
use serde::de;

use core::{Package, PackageId, SourceId, Workspace};
use core::{Package, PackageId, SourceId, Workspace, Dependency};
use util::{Graph, Config, internal};
use util::errors::{CargoResult, CargoResultExt, CargoError};

Expand Down Expand Up @@ -60,7 +60,12 @@ impl EncodableResolve {
let id = match pkg.source.as_ref().or(path_deps.get(&pkg.name)) {
// We failed to find a local package in the workspace.
// It must have been removed and should be ignored.
None => continue,
None => {
debug!("path dependency now missing {} v{}",
pkg.name,
pkg.version);
continue
}
Some(source) => PackageId::new(&pkg.name, &pkg.version, source)?
};

Expand Down Expand Up @@ -199,34 +204,49 @@ fn build_path_deps(ws: &Workspace) -> HashMap<String, SourceId> {
visited.insert(member.package_id().source_id().clone());
}
for member in members.iter() {
build(member, ws.config(), &mut ret, &mut visited);
build_pkg(member, ws.config(), &mut ret, &mut visited);
}
for (_, deps) in ws.root_patch() {
for dep in deps {
build_dep(dep, ws.config(), &mut ret, &mut visited);
}
}
for &(_, ref dep) in ws.root_replace() {
build_dep(dep, ws.config(), &mut ret, &mut visited);
}

return ret;

fn build(pkg: &Package,
config: &Config,
ret: &mut HashMap<String, SourceId>,
visited: &mut HashSet<SourceId>) {
let replace = pkg.manifest().replace().iter().map(|p| &p.1);
let patch = pkg.manifest().patch().values().flat_map(|v| v);
let deps = pkg.dependencies()
.iter()
.chain(replace)
.chain(patch)
.map(|d| d.source_id())
.filter(|id| !visited.contains(id) && id.is_path())
.filter_map(|id| id.url().to_file_path().ok())
.map(|path| path.join("Cargo.toml"))
.filter_map(|path| Package::for_path(&path, config).ok())
.collect::<Vec<_>>();
for pkg in deps {
ret.insert(pkg.name().to_string(),
pkg.package_id().source_id().clone());
visited.insert(pkg.package_id().source_id().clone());
build(&pkg, config, ret, visited);
fn build_pkg(pkg: &Package,
config: &Config,
ret: &mut HashMap<String, SourceId>,
visited: &mut HashSet<SourceId>) {
for dep in pkg.dependencies() {
build_dep(dep, config, ret, visited);
}
}

fn build_dep(dep: &Dependency,
config: &Config,
ret: &mut HashMap<String, SourceId>,
visited: &mut HashSet<SourceId>) {
let id = dep.source_id();
if visited.contains(id) || !id.is_path() {
return
}
let path = match id.url().to_file_path() {
Ok(p) => p.join("Cargo.toml"),
Err(_) => return,
};
let pkg = match Package::for_path(&path, config) {
Ok(p) => p,
Err(_) => return,
};
ret.insert(pkg.name().to_string(),
pkg.package_id().source_id().clone());
visited.insert(pkg.package_id().source_id().clone());
build_pkg(&pkg, config, ret, visited);
}
}

impl Patch {
Expand Down
38 changes: 38 additions & 0 deletions tests/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -742,3 +742,41 @@ Caused by:
to different sources
"));
}

#[test]
fn patch_in_virtual() {
Package::new("foo", "0.1.0").publish();

let p = project("bar")
.file("Cargo.toml", r#"
[workspace]
members = ["bar"]
[patch.crates-io]
foo = { path = "foo" }
"#)
.file("foo/Cargo.toml", r#"
[package]
name = "foo"
version = "0.1.0"
authors = []
"#)
.file("foo/src/lib.rs", r#""#)
.file("bar/Cargo.toml", r#"
[package]
name = "bar"
version = "0.1.0"
authors = []
[dependencies]
foo = "0.1"
"#)
.file("bar/src/lib.rs", r#""#);

assert_that(p.cargo_process("build"),
execs().with_status(0));
assert_that(p.cargo("build"),
execs().with_status(0).with_stderr("\
[FINISHED] [..]
"));
}

0 comments on commit 3423351

Please sign in to comment.