}
}
-impl Encodable for Resolve {
+pub struct WorkspaceResolve<'a, 'cfg: 'a> {
+ pub ws: &'a Workspace<'cfg>,
+ pub resolve: &'a Resolve,
+}
+
+impl<'a, 'cfg> Encodable for WorkspaceResolve<'a, 'cfg> {
fn encode<S: Encoder>(&self, s: &mut S) -> Result<(), S::Error> {
- let mut ids: Vec<&PackageId> = self.graph.iter().collect();
+ let mut ids: Vec<&PackageId> = self.resolve.graph.iter().collect();
ids.sort();
+ let root = self.ws.members().max_by_key(|member| {
+ member.name()
+ }).unwrap().package_id();
+
let encodable = ids.iter().filter_map(|&id| {
- if self.root == *id { return None; }
+ if root == id {
+ return None
+ }
- Some(encodable_resolve_node(id, self))
+ Some(encodable_resolve_node(id, self.resolve))
}).collect::<Vec<EncodableDependency>>();
EncodableResolve {
package: Some(encodable),
- root: encodable_resolve_node(&self.root, self),
- metadata: self.metadata.clone(),
+ root: encodable_resolve_node(&root, self.resolve),
+ metadata: self.resolve.metadata.clone(),
}.encode(s)
}
}
use util::graph::{Nodes, Edges};
pub use self::encode::{EncodableResolve, EncodableDependency, EncodablePackageId};
-pub use self::encode::Metadata;
+pub use self::encode::{Metadata, WorkspaceResolve};
mod encode;
match s.features().get(feat) {
Some(wanted_features) => {
for entry in wanted_features {
- // If the entry is of the form `foo/bar`, then we just lookup package
+ // If the entry is of the form `foo/bar`, then we just lookup package
// `foo` and enable its feature `bar`. We also add `foo` to the used
// set because `foo` might have been an optional dependency.
//
deps.entry(feat.to_string()).or_insert(Vec::new());
}
}
-
+
visited.remove(&feat.to_string());
Ok(())
use toml::{self, Encoder, Value};
use core::{Resolve, resolver, Workspace};
+use core::resolver::WorkspaceResolve;
use util::{CargoResult, ChainError, human, Filesystem};
use util::toml as cargo_toml;
pub fn write_pkg_lockfile(ws: &Workspace, resolve: &Resolve) -> CargoResult<()> {
let mut e = Encoder::new();
- resolve.encode(&mut e).unwrap();
+ WorkspaceResolve {
+ ws: ws,
+ resolve: resolve,
+ }.encode(&mut e).unwrap();
let mut out = String::new();
+#[macro_use]
extern crate cargotest;
extern crate hamcrest;
+use std::io::Read;
+use std::fs::File;
+
use cargotest::support::{project, execs};
use cargotest::support::registry::Package;
use hamcrest::{assert_that, existing_file, existing_dir, is_not};
root: [..]
"));
}
+
+#[test]
+fn lock_doesnt_change_depending_on_crate() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [project]
+ name = "foo"
+ version = "0.1.0"
+ authors = []
+
+ [workspace]
+ members = ['baz']
+
+ [dependencies]
+ foo = "*"
+ "#)
+ .file("src/lib.rs", "")
+ .file("baz/Cargo.toml", r#"
+ [project]
+ name = "baz"
+ version = "0.1.0"
+ authors = []
+
+ [dependencies]
+ bar = "*"
+ "#)
+ .file("baz/src/lib.rs", "");
+ p.build();
+
+ Package::new("foo", "1.0.0").publish();
+ Package::new("bar", "1.0.0").publish();
+
+ assert_that(p.cargo("build"),
+ execs().with_status(0));
+
+ let mut lockfile = String::new();
+ t!(t!(File::open(p.root().join("Cargo.lock"))).read_to_string(&mut lockfile));
+
+ assert_that(p.cargo("build").cwd(p.root().join("baz")),
+ execs().with_status(0));
+
+ let mut lockfile2 = String::new();
+ t!(t!(File::open(p.root().join("Cargo.lock"))).read_to_string(&mut lockfile2));
+
+ assert_eq!(lockfile, lockfile2);
+}