Skip to content

Commit

Permalink
Fix issues
Browse files Browse the repository at this point in the history
Fix rust-lang#1570 based on commits from PR rust-lang#2056 by @tsurai to master
  • Loading branch information
JanLikar committed Jan 28, 2016
1 parent 08a88b5 commit 2244960
Showing 1 changed file with 25 additions and 23 deletions.
48 changes: 25 additions & 23 deletions src/cargo/ops/cargo_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn compile_pkg<'a>(root_package: &Package,

if spec.len() > 0 && (no_default_features || features.len() > 0) {
bail!("features cannot be modified when the main package \
is not being built");
is not being built");
}

if jobs == Some(0) {
Expand All @@ -168,7 +168,6 @@ pub fn compile_pkg<'a>(root_package: &Package,
try!(resolve_dependencies(root_package, config, source, features,
no_default_features))
};
let all_feature = resolve_with_overrides.features(resolve_with_overrides.root());

let mut invalid_spec = vec![];
let pkgids = if spec.len() > 0 {
Expand Down Expand Up @@ -200,8 +199,9 @@ pub fn compile_pkg<'a>(root_package: &Package,
panic!("`rustc` and `rustdoc` should not accept multiple `-p` flags")
}
(Some(args), _) => {
let all_features = resolve_with_overrides.features(to_builds[0].package_id());
let targets = try!(generate_targets(to_builds[0], profiles,
mode, filter, all_feature, release));
mode, filter, all_features, release));
if targets.len() == 1 {
let (target, profile) = targets[0];
let mut profile = profile.clone();
Expand All @@ -214,8 +214,9 @@ pub fn compile_pkg<'a>(root_package: &Package,
}
}
(None, Some(args)) => {
let all_features = resolve_with_overrides.features(to_builds[0].package_id());
let targets = try!(generate_targets(to_builds[0], profiles,
mode, filter, all_feature, release));
mode, filter, all_features, release));
if targets.len() == 1 {
let (target, profile) = targets[0];
let mut profile = profile.clone();
Expand All @@ -229,8 +230,9 @@ pub fn compile_pkg<'a>(root_package: &Package,
}
(None, None) => {
for &to_build in to_builds.iter() {
let all_features = resolve_with_overrides.features(to_build.package_id());
let targets = try!(generate_targets(to_build, profiles, mode,
filter, all_feature, release));
filter, all_features, release));
package_targets.push((to_build, targets));
}
}
Expand Down Expand Up @@ -318,13 +320,13 @@ fn generate_targets<'a>(pkg: &'a Package,
CompileMode::Build => build,
CompileMode::Doc { .. } => &profiles.doc,
};
let targets = match *filter {
let mut targets = match *filter {
CompileFilter::Everything => {
match mode {
CompileMode::Bench => {
Ok(pkg.targets().iter().filter(|t| t.benched()).map(|t| {
pkg.targets().iter().filter(|t| t.benched()).map(|t| {
(t, profile)
}).collect::<Vec<_>>())
}).collect::<Vec<_>>()
}
CompileMode::Test => {
let mut base = pkg.targets().iter().filter(|t| {
Expand All @@ -340,16 +342,16 @@ fn generate_targets<'a>(pkg: &'a Package,
base.push((t, build));
}
}
Ok(base)
base
}
CompileMode::Build => {
Ok(pkg.targets().iter().filter(|t| {
pkg.targets().iter().filter(|t| {
t.is_bin() || t.is_lib()
}).map(|t| (t, profile)).collect())
}).map(|t| (t, profile)).collect()
}
CompileMode::Doc { .. } => {
Ok(pkg.targets().iter().filter(|t| t.documented())
.map(|t| (t, profile)).collect())
pkg.targets().iter().filter(|t| t.documented())
.map(|t| (t, profile)).collect()
}
}
}
Expand Down Expand Up @@ -384,19 +386,19 @@ fn generate_targets<'a>(pkg: &'a Package,
try!(find(tests, "test", TargetKind::Test, test));
try!(find(benches, "bench", TargetKind::Bench, &profiles.bench));
}
Ok(targets)
targets
}
};

targets.map(|x| x.iter().filter_map(|&(t, p)| {
match (t.is_lib(), t.features()) {
(true, _) | (false, None) => Some((t, p)),
(false, Some(v)) if v.iter().filter(|&f| {
features.map_or(true, |x| !x.contains(f))
}).count() == 0 => Some((t, p)),
_ => None
}
}).collect())
targets.retain(|&(t, _)| {
t.is_lib() ||
t.features().is_none() ||
t.features().unwrap().iter().filter(|&f| {
features.map_or(true, |x| !x.contains(f))
}).count() == 0
});

Ok(targets)
}

/// Read the `paths` configuration variable to discover all path overrides that
Expand Down

0 comments on commit 2244960

Please sign in to comment.