Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use struct variant instead of long, commented tuple #1310

Merged
merged 1 commit into from
Feb 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 17 additions & 12 deletions src/cargo/core/resolver/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub struct Resolve {
#[derive(Copy)]
pub enum Method<'a> {
Everything,
Required(/* dev_deps = */ bool,
/* features = */ &'a [String],
/* uses_default_features = */ bool,
/* target_platform = */ Option<&'a str>),
Required{ dev_deps: bool,
features: &'a [String],
uses_default_features: bool,
target_platform: Option<&'a str>},
}

impl Resolve {
Expand Down Expand Up @@ -170,7 +170,7 @@ fn activate(mut cx: Box<Context>,

// Extracting the platform request.
let platform = match method {
Method::Required(_, _, _, platform) => platform,
Method::Required{target_platform: platform, ..} => platform,
Method::Everything => None,
};

Expand Down Expand Up @@ -230,7 +230,7 @@ fn flag_activated(cx: &mut Context,
}
debug!("checking if {} is already activated", summary.package_id());
let features = match *method {
Method::Required(_, features, _, _) => features,
Method::Required{features, ..} => features,
Method::Everything => return false,
};
match cx.resolve.features(id) {
Expand All @@ -247,8 +247,12 @@ fn activate_deps<'a>(cx: Box<Context>,
cur: usize) -> CargoResult<CargoResult<Box<Context>>> {
if cur == deps.len() { return Ok(Ok(cx)) }
let (dep, ref candidates, ref features) = deps[cur];
let method = Method::Required(false, &features,
dep.uses_default_features(), platform);

let method = Method::Required{
dev_deps: false,
features: &features,
uses_default_features: dep.uses_default_features(),
target_platform: platform};

let key = (dep.name().to_string(), dep.source_id().clone());
let prev_active = cx.activations.get(&key)
Expand Down Expand Up @@ -424,7 +428,7 @@ fn resolve_features<'a>(cx: &mut Context, parent: &'a Summary,
(&'a Dependency, Vec<String>)>> {
let dev_deps = match method {
Method::Everything => true,
Method::Required(dev_deps, _, _, _) => dev_deps,
Method::Required{dev_deps, ..} => dev_deps,
};

// First, filter by dev-dependencies
Expand All @@ -434,7 +438,7 @@ fn resolve_features<'a>(cx: &mut Context, parent: &'a Summary,
// Second, ignoring dependencies that should not be compiled for this platform
let deps = deps.filter(|d| {
match method {
Method::Required(_, _, _, Some(ref platform)) => {
Method::Required{target_platform: Some(ref platform), ..} => {
d.is_active_for_platform(platform)
},
_ => true
Expand Down Expand Up @@ -514,14 +518,15 @@ fn build_features(s: &Summary, method: Method)
&mut visited));
}
}
Method::Required(_, requested_features, _, _) => {
Method::Required{features: requested_features, ..} => {
for feat in requested_features.iter() {
try!(add_feature(s, feat, &mut deps, &mut used, &mut visited));
}
}
}
match method {
Method::Everything | Method::Required(_, _, true, _) => {
Method::Everything |
Method::Required{uses_default_features: true, ..} => {
if s.features().get("default").is_some() &&
!visited.contains("default") {
try!(add_feature(s, "default", &mut deps, &mut used,
Expand Down
9 changes: 7 additions & 2 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ pub fn compile_pkg(package: &Package, options: &CompileOptions)
try!(registry.add_overrides(override_ids));

let platform = target.as_ref().map(|e| e.as_slice()).or(Some(rustc_host.as_slice()));
let method = Method::Required(dev_deps, &features,
!no_default_features, platform);

let method = Method::Required{
dev_deps: dev_deps,
features: &features,
uses_default_features: !no_default_features,
target_platform: platform};

let resolved_with_overrides =
try!(ops::resolve_with_previous(&mut registry, package, method,
Some(&resolve), None));
Expand Down