Skip to content

Commit

Permalink
Revert "Removed root related flags"
Browse files Browse the repository at this point in the history
This reverts commit 6f03cce.
  • Loading branch information
raytung committed Oct 3, 2017
1 parent f5fbf73 commit f5961e6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/cargo/core/resolver/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ use super::Resolve;
#[derive(Serialize, Deserialize, Debug)]
pub struct EncodableResolve {
package: Option<Vec<EncodableDependency>>,
/// `root` is optional to allow forward compatibility.
root: Option<EncodableDependency>,
metadata: Option<Metadata>,

#[serde(default, skip_serializing_if = "Patch::is_empty")]
Expand All @@ -31,7 +33,13 @@ impl EncodableResolve {
pub fn into_resolve(self, ws: &Workspace) -> CargoResult<Resolve> {
let path_deps = build_path_deps(ws);

let packages = self.package.unwrap_or_default();
let packages = {
let mut packages = self.package.unwrap_or_default();
if let Some(root) = self.root {
packages.insert(0, root);
}
packages
};

// `PackageId`s in the lock file don't include the `source` part
// for workspace members, so we reconstruct proper ids.
Expand Down Expand Up @@ -303,6 +311,7 @@ impl<'de> de::Deserialize<'de> for EncodablePackageId {
pub struct WorkspaceResolve<'a, 'cfg: 'a> {
pub ws: &'a Workspace<'cfg>,
pub resolve: &'a Resolve,
pub use_root_key: bool,
}

impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> {
Expand All @@ -312,7 +321,15 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> {
let mut ids: Vec<&PackageId> = self.resolve.graph.iter().collect();
ids.sort();

let root = self.ws.members().max_by_key(|member| {
member.name()
}).map(Package::package_id);

let encodable = ids.iter().filter_map(|&id| {
if self.use_root_key && root.unwrap() == id {
return None
}

Some(encodable_resolve_node(id, self.resolve))
}).collect::<Vec<_>>();

Expand All @@ -330,6 +347,11 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> {

let metadata = if metadata.is_empty() { None } else { Some(metadata) };

let root = match root {
Some(root) if self.use_root_key => Some(encodable_resolve_node(root, self.resolve)),
_ => None,
};

let patch = Patch {
unused: self.resolve.unused_patches().iter().map(|id| {
EncodableDependency {
Expand All @@ -343,6 +365,7 @@ impl<'a, 'cfg> ser::Serialize for WorkspaceResolve<'a, 'cfg> {
};
EncodableResolve {
package: Some(encodable),
root: root,
metadata: metadata,
patch: patch,
}.serialize(s)
Expand Down
1 change: 1 addition & 0 deletions src/cargo/ops/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ pub fn write_pkg_lockfile(ws: &Workspace, resolve: &Resolve) -> CargoResult<()>
let toml = toml::Value::try_from(WorkspaceResolve {
ws: ws,
resolve: resolve,
use_root_key: false,
}).unwrap();

let mut out = String::new();
Expand Down

0 comments on commit f5961e6

Please sign in to comment.